From 296edc5ad772d0e31384246b566648f3b5b545e7 Mon Sep 17 00:00:00 2001 From: Pepper Date: Thu, 26 Feb 2015 18:47:25 -0500 Subject: ok done! --- breaker.py | 5 +- db.py | 2 +- gradient.py | 3 +- imbreak_main.js | 113 ----------- imgradient_index.html | 532 -------------------------------------------------- imgrid.py | 12 +- imgrid_main.js | 121 ------------ pbserver.py | 43 ++-- 8 files changed, 40 insertions(+), 791 deletions(-) delete mode 100644 imbreak_main.js delete mode 100644 imgradient_index.html delete mode 100644 imgrid_main.js diff --git a/breaker.py b/breaker.py index 33dcba9..4bb5bf9 100755 --- a/breaker.py +++ b/breaker.py @@ -11,7 +11,8 @@ urlencode = urllib.urlencode urlopen = urllib2.urlopen Request = urllib2.Request -WORKING_DIR = "/tmp" +#WORKING_DIR = "/tmp" +WORKING_DIR = "/var/www/cache" BIN_CONVERT = "/usr/bin/convert" BIN_IDENTIFY = "/usr/bin/identify" DEFAULT_FINALFORMAT = "png"; @@ -19,7 +20,7 @@ DEFAULT_FINALFORMAT = "png"; SUBTLE_BREAK_MARK = 'pron' EXTREME_BREAK_MARK = 'sugar' -HEADER_OFFSET = 5000 +HEADER_OFFSET = 2000 MAX_SIZE = 1024 * 1024 * 1.2 * 1.5 diff --git a/db.py b/db.py index 23ebbe4..2570b4f 100755 --- a/db.py +++ b/db.py @@ -1,6 +1,6 @@ import MySQLdb USER = "asdfus" -PASSWORD = "urJJwLjdO9GPuOxk" +PASSWORD = "gTYgT&M6q" DATABASE = "asdfus" class db: diff --git a/gradient.py b/gradient.py index baefc6b..1fa8e9f 100755 --- a/gradient.py +++ b/gradient.py @@ -42,7 +42,8 @@ DEFAULT_COLORS = { "color2" : "black", }; -WORKING_DIR = '/tmp' +#WORKING_DIR = '/tmp' +WORKING_DIR = '/var/www/cache' DEFAULT_WIDTH = "200" DEFAULT_HEIGHT = "200" diff --git a/imbreak_main.js b/imbreak_main.js deleted file mode 100644 index 78ae753..0000000 --- a/imbreak_main.js +++ /dev/null @@ -1,113 +0,0 @@ -var Main = - { - firsttime: true, - generating: false, - thelast: "", - enter: function (e) - { - if (Main.generating) - return - if (e.keyCode === 13) - Main.go() - }, - go: function () - { - if (Main.generating) - return - Main.generating = true - var theloader = '' - $("#output-cmd").html(theloader).show() - $('.result').show() - $('.results').show() - $("#output-img").show() - $("#output-url").show() - $("#result").show() - var data = - { - breakmode:$('input:radio[name=modeswitch]:checked').val(), - breaktype: $('#breaktype :selected').val(), - breakangle: $("#breakangle").val(), - url: $('#url').val(), - username: $('#username').val(), - firsttime: Main.firsttime.toString() - } - if (data["breakmode"] == "gradual") - { - data["breakmode"] = "subtle" - if (Main.lines && Main.thelast == $('#url').val()) - { - Main.firsttime = false - data["url"] = Main.lines[1] - } - } - else - { - Main.firsttime = true - } - Main.thelast = $('#url').val(); - thestring = JSON.stringify(data); - $('#error').append(thestring); - if (data.username.length > 0) - document.cookie = "imname="+data.username+";path=/;domain=.asdf.us;max-age=1086400" - $.post("/cgi-bin/im/break/breaker", data, Main.callback) - }, - error: function (s) - { - $("#output-cmd").html("ERROR: " + s + "").show() - $("#output-url").hide() - $("#output-img").hide() - }, - filesize: function (size) - { - if (size < 1024) - return size.toString() + " bytes" - if (size < 1024 * 1024) - return Math.floor (size/1024).toString() + " KB" - else - return Math.floor (size/(1024*1024)).toString() + " MB" - }, - callback: function (data) - { - data = JSON.parse(data) - $('#error').append('called'); - $("#output-cmd").html('') - $('#output-url').val(data.url) - $("#output-img").html("click image to enlarge
"+"
"+"
" -); - $("#output-info").html('-ACTUAL SIZE-
'+Main.filesize(data.size)+'
'+data.width+'
'+data.height+'

'+'see more at →photoblaster gallery'+'
') - Main.generating = false - }, - cookie: function () - { - if (document.cookie) - { - var cookies = document.cookie.split(";") - for (i in cookies) - { - var cookie = cookies[i].split("=") - if (cookie[0].indexOf("imname") !== -1) - { - if (cookie[1] !== 'false' && cookie[1] !== 'undefined' && cookie[1].length) - { - return cookie[1] - } - } - } - } - return "" - }, - init: function () - { - var name = Main.cookie () - $("#username").val(name) - $("#breakbutton").bind("click", Main.go) - $(document).bind("keydown", Main.enter) - } - } -//$('#theform').each(function(){ -// this.reset(); -// }); - - - -Main.init () diff --git a/imgradient_index.html b/imgradient_index.html deleted file mode 100644 index 70a39dc..0000000 --- a/imgradient_index.html +++ /dev/null @@ -1,532 +0,0 @@ - - - - - - -GRADIENT PHOTOBLASTER - - - - - - - - - - - - -
-
-
-

- GRADIENT GENERATOR FOR PHOTOBLASTER - - - - - - - - -

- - - - - - - - - - - px -
- - - - - px -
- - - - - list of color names - - - - - -
- - - - - -
- - - - - - - if yes...0-4000-2000 - - - - - - - -
- -
- - - -
- -
- - - -
- -
- - - -
- -
- - - - - - - - - - - - - - - % - - - - - - -
- - - -
- - ° -
- - - - ° -
- - - - - - - - - - - - -
- - - - - - - -
- VIEW AND ARRANGE THE PHOTOBLASTS → Image Gallery
- - OPEN THE PHOTOBLASTER EDITOR → PHOTOBLASTER - - TOP PHOTOBLASTS GO TO THE TUMBLR → Photoblaster Tumblr -

- -
- -
- →
-
- - -
- - - -
-
-
- - - - - - - - diff --git a/imgrid.py b/imgrid.py index 5a893f7..86597bb 100755 --- a/imgrid.py +++ b/imgrid.py @@ -15,7 +15,8 @@ urlopen = urllib2.urlopen Request = urllib2.Request MAX_SIZE = 1024 * 1024 * 1.2 * 1.5 -WORKING_DIR = "/tmp" +WORKING_DIR = "/var/www/cache" +#WORKING_DIR = "/tmp" BIN_CONVERT = "/usr/bin/convert" BIN_COMPOSITE = "/usr/bin/composite" @@ -170,6 +171,10 @@ class Imgrid(): raise; elif k in [ 'bgcolor', 'planebgcolor' ]: self.params[k] = params[k] + elif k == 'opacity': + self.params[k] = str(float(params[k])) + elif k == 'zoom': + self.params[k] = int(float(params[k])) else: self.params[k] = bool_correct(sanitize(params[k])) else: @@ -250,7 +255,8 @@ class Imgrid(): if self.params.swing: cmd += ["pan={}".format(self.params.swing)] if self.params.tilt: cmd += ["tilt={}".format(self.params.tilt)] if self.params.roll: cmd += ["roll={}".format(self.params.roll)] - if self.params.zoom: cmd += ["zoom={}".format(self.params.zoom)] + if self.params.zoom: + cmd += ["zoom={}".format(self.params.zoom)] if cmd == [THREEDROTATE]: #if nothing has been added return if self.params.planebgcolor and not self.params.planebgimage: @@ -258,7 +264,7 @@ class Imgrid(): else: cmd += ["bgcolor=none"] cmd += ["skycolor={}".format(self.params.skycolor or 'none')] - if self.params.transition: cmd += ["vp={}",self.params.transition] + if self.params.transition: cmd += ["vp={}".format(self.params.transition)] cmd += [ self.filepath, self.filepath ] self._call_cmd(cmd) diff --git a/imgrid_main.js b/imgrid_main.js deleted file mode 100644 index 29114f2..0000000 --- a/imgrid_main.js +++ /dev/null @@ -1,121 +0,0 @@ -var Main = - { - API_HEADER: "#@imgrid", - generating: false, - enter: function (e) - { - if (Main.generating) - return - if (e.keyCode === 13) - Main.go() - }, - go: function () - { - if (Main.generating) - return - Main.generating = true - var theloader = '' - $("#output-cmd").html(theloader).show() - if($('#transition :selected').val() === 'tile'||$('#transition :selected').val()=== 'random') - { - $('#output-cmd').append("
WARNING: THIS REQUEST MIGHT TAKE A WHILE") - } - $('.results').show() - $("#output-img").show() - $("#output-url").show() - $("#result").show() - var data = - { - width: $("#img-width").val(), - height: $("#img-height").val(), - linethickness: $("#line-thickness").val(), - opacity: $("#line-opacity").val(), - linecolor: $("#line-color").val(), - spacing: $("#line-spacing").val(), - vlines: $('#v-lines:checked').val() !== undefined ? "true" : "false", - hlines: $('#h-lines:checked').val() !== undefined ? "true" : "false", - shadow: $('#shadow:checked').val() !== undefined ? "true" : "false", - bgimage: $("#bg-image").val(), - bgcolor: $("#bg-color").val(), - imageinstead: $("#imageinstead").val(), - planebgcolor: $("#planebgcolor").val(), - skycolor: $("#skycolor").val(), - planebgimage: $("#planebgimage").val(), - transition: $('#transition :selected').val(), - swing: $("#swing").val(), - tilt: $("#tilt").val(), - roll: $("#roll").val(), - zoom: $("#zoom").val(), - trim: $("#trim:checked").val() !== undefined ? "true" : "false", - format: $('#format :selected').val(), - username: $('#username').val() - } - if (data.transition == 'infinite'){ - $('#genbutton').append("WARNING:This might take a while")} - if (data.username.length > 0) - document.cookie = "imname="+data.username+";path=/;domain=.asdf.us;max-age=1086400" - $.post("localhost:8999/imgrid", data, Main.callback) - }, - error: function (s) - { - $("#output-cmd").html("ERROR: " + s + "").show() - $("#output-url").hide() - $("#output-img").hide() - }, - filesize: function (size) - { - if (size < 1024) - return size.toString() + " bytes" - if (size < 1024 * 1024) - return Math.floor (size/1024).toString() + " KB" - else - return Math.floor (size/(1024*1024)).toString() + " MB" - }, - callback: function (data) - { - data = JSON.parse(data) - $("#output-cmd").html('') - $("#output-img").html(""+"
"+"
"); - $("#output-url").val(data.url) - $("#output-info").html('-ACTUAL SIZE-
'+Main.filesize(data.size)+'
'+data.width+'
'+data.height+'

'+'see more at →photoblaster gallery'+'
') - Main.generating = false - }, - cookie: function () - { - if (document.cookie) - { - var cookies = document.cookie.split(";") - for (i in cookies) - { - var cookie = cookies[i].split("=") - if (cookie[0].indexOf("imname") !== -1) - { - if (cookie[1] !== 'false' && cookie[1] !== 'undefined' && cookie[1].length) - { - return cookie[1] - } - } - } - } - return "" - }, - init: function () - { - var name = Main.cookie () - $("#username").val(name) - if (name) - { -// $("#userlink").show() - // $("#userlink a").attr("href", "/im/gallery/?name="+name).html(name+"'s photoblasts") - } - $("#generate").bind("click", Main.go) - $(document).bind("keydown", Main.enter) - } - } -$('#theform').each(function(){ - this.reset(); - }); - - - -Main.init () diff --git a/pbserver.py b/pbserver.py index cea6314..6712b76 100755 --- a/pbserver.py +++ b/pbserver.py @@ -28,7 +28,7 @@ def hashdir(filename): def file_size (filepath): try: - return os.stat(file)[6] + return os.stat(filepath)[6] except Exception as e: sys.stderr.write(str(e)) raise; @@ -37,7 +37,7 @@ def bin_identify (filepath): ident = Popen([BIN_IDENTIFY, filepath], stdout=PIPE).communicate()[0] partz = ident.split(" ") width,height = partz[2].split("x") - return width, height + return [ width, height ] def cleanup(filepath): @@ -47,10 +47,10 @@ def cleanup(filepath): sys.stderr.write(str(e)) raise -def moveToS3(filename,objectname): +def s3move(filepath,objectname): conn = s3.AWSAuthConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) - filedata = open(filename, 'rb').read() - content_type = mimetypes.guess_type(filename)[0] + filedata = open(filepath, 'rb').read() + content_type = mimetypes.guess_type(filepath)[0] try: conn.put(BUCKET_NAME, objectname, s3.S3Object(filedata), { @@ -69,7 +69,7 @@ def insert_cmd (date, remote_addr, username, url, directory, oldfile, newfile, c sql += "(date, remote_addr, name, url, dir, oldfile, newfile, cmd, dataobj, tag) " sql += "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" #or "NULL" - args = (now(), remote_addr, username, url, directory, oldfile, newfile, cmd, dataobj, tag) + args = (date, remote_addr, username, url, directory, oldfile, newfile, cmd, dataobj, tag) #args = (now(), os.environ['REMOTE_ADDR'], name, url, dir, oldfile, newfile, " ".join(cmd),dataobj) DB.execute(sql, args) except Exception as e: @@ -79,10 +79,12 @@ def insert_cmd (date, remote_addr, username, url, directory, oldfile, newfile, c def return_image(im, insert_url="NULL"): directory = hashdir(im.filename) dimensions = bin_identify(im.filepath) - objectname = "{}/{}".format(directory, im.filename) + size = file_size(im.filepath) + objectname = "im/{}/{}".format(directory, im.filename) try: s3move(im.filepath, objectname) - # return "{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}".format( + cleanup(im.filepath) +# # return "{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}".format( insert_cmd( im.now, request.environ.get('REMOTE_ADDR'), @@ -95,9 +97,9 @@ def return_image(im, insert_url="NULL"): json.dumps(im.params), im.tag, ) - return json.loads({ - 'url' : "{}/{}".format(BASE_URL, objectname) - 'size' : file_size(im.filepath), + return json.dumps({ + 'url' : "{}/{}".format(BASE_URL, objectname), + 'size' : size, 'width' : "{}px".format(dimensions[0]), 'height' : "{}px".format(dimensions[1]), }) @@ -106,7 +108,7 @@ def return_image(im, insert_url="NULL"): raise; -@post('/gradient') +@post('/im/api/imgradient') def gradient(): try: im = Gradient(request.forms) @@ -116,17 +118,22 @@ def gradient(): sys.stderr.write(str(e)) raise; -@post('/imgrid') +@post('/im/api/imgrid') def imgrid(): try: im = Imgrid(request.forms) im.create(); - return return_image(im, im.params.imageinstead or im.params.bgimage or im.params.planebgimage or "NULL") + url= "NULL" + for elem in [ im.params.imageinstead , im.params.bgimage, im.params.planebgimage ]: + if elem: + url = elem['url'] + break + return return_image(im, url) except Exception as e: sys.stderr.write(str(e)) - return json.load({ 'error' : 'Request could not be processed' }) + return json.dumps({ 'error' : 'Request could not be processed' }) -@post('/breaker') +@post('/im/api/imbreak') def breaker(): try: im = Breaker(request.forms) @@ -134,6 +141,6 @@ def breaker(): return return_image(im, im.params['url']) except Exception as e: sys.stderr.write(str(e)) - return json.load({ 'error' : 'Request could not be processed' }) + return json.dumps({ 'error' : 'Request could not be processed' }) -run(host='0.0.0.0', port=8999, debug=True) +run(host='0.0.0.0', server='flup', port=8999, debug=True) -- cgit v1.2.3-70-g09d2