summaryrefslogtreecommitdiff
path: root/pbserver.py
diff options
context:
space:
mode:
Diffstat (limited to 'pbserver.py')
-rwxr-xr-xpbserver.py43
1 files changed, 25 insertions, 18 deletions
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)