diff options
| -rwxr-xr-x | photoblaster/modules/pbpattern/__init__.py | 7 | ||||
| -rw-r--r-- | photoblaster/param/img_url.py | 21 | ||||
| -rw-r--r-- | photoblaster/server.py | 9 | ||||
| -rw-r--r-- | run_module_examples.py | 2 | ||||
| -rw-r--r-- | share/frontend/im/js/main.js | 51 | ||||
| -rw-r--r-- | share/frontend/impattern/js/inputs.js | 2 |
6 files changed, 46 insertions, 46 deletions
diff --git a/photoblaster/modules/pbpattern/__init__.py b/photoblaster/modules/pbpattern/__init__.py index c4ea379..2d73f89 100755 --- a/photoblaster/modules/pbpattern/__init__.py +++ b/photoblaster/modules/pbpattern/__init__.py @@ -2,6 +2,7 @@ from photoblaster.config import BIN_CONVERT, BIN_COMPOSITE from photoblaster.modules import ModuleBase from PIL import Image from photoblaster._file import File +import json _FUSE_MODE = "Pin_Light" @@ -19,7 +20,7 @@ class PbPattern(ModuleBase): _definitions = { 'image_url': {'type': 'img_url'}, 'pattern_url': {'type': 'img_url'}, - 'pattern_data': {'type': 'json'}, + 'pattern_data': {'type': 'json'}, 'username': {'type': 'string'}, } self.params.definitions_import( @@ -67,9 +68,9 @@ class PbPattern(ModuleBase): #first step def _make_canvas(self): - _width, _height = self.params.image_url.get_file().get_dimensions() + width, height = self.params.image_url.get_file().get_dimensions() cmd = [ - BIN_CONVERT, "-size", _width + "x" + _height, + BIN_CONVERT, "-size", str(width) + "x" + str(height), "canvas:transparent", self.get_output_file().get_filepath()] self._call_cmd(cmd) diff --git a/photoblaster/param/img_url.py b/photoblaster/param/img_url.py index b3ca08c..73a349e 100644 --- a/photoblaster/param/img_url.py +++ b/photoblaster/param/img_url.py @@ -73,14 +73,8 @@ class Img_url(Param): 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)', 'Accept': '*/*', } - try: - req = urllib2.Request(url, data, headers) - response = urllib2.urlopen(req) - except IOError as e: - if hasattr(e, 'code'): - self.err_warn( - 'browser request error: %s - ERROR %s' % (url, e.code)) - raise IOError + req = urllib2.Request(url, data, headers) + response = urllib2.urlopen(req) return response def _download(self, url, destination, max_size=MAX_SIZE): @@ -106,13 +100,10 @@ class Img_url(Param): """ retrieves the image mimetype from the file header using imagemagick """ - try: - mimetype = Popen( - [BIN_IDENTIFY, f], stdout=PIPE - ).communicate()[0].split(" ")[1].lower() - return mimetype - except Exception: - self.err_warn("Couldn't determine mimetype") + mimetype = Popen( + [BIN_IDENTIFY, f], stdout=PIPE + ).communicate()[0].split(" ")[1].lower() + return mimetype def get_file(self): return self._file diff --git a/photoblaster/server.py b/photoblaster/server.py index 4a5ac2c..92e51f3 100644 --- a/photoblaster/server.py +++ b/photoblaster/server.py @@ -184,7 +184,8 @@ class Server(object): offset = int(request.args.get('start', 0)) if request.args.get('random'): results = ImCmd.search_random(**search_params) - qs.append("random=" + request.args['random']) + if 'start' not in request.args: + qs.append("random=" + request.args['random']) else: results = ImCmd.search(**search_params) images = results.limit(limit).offset(offset).all() @@ -257,6 +258,12 @@ class Server(object): except PbProcessError: sys.stderr.write(dict(request_form)) raise InvalidUsage('Problem with server-side processing') + except Exception as e: + + sys.stderr.write("Unknown Error\n") + sys.stderr.write("%s\n" % e) + sys.stderr.write(str(request_form)) + raise e def run(self, host=SERVER_HOST, port=SERVER_PORT): self.app.run(host=host, port=port, debug=True) diff --git a/run_module_examples.py b/run_module_examples.py index 27fd13c..a682ab7 100644 --- a/run_module_examples.py +++ b/run_module_examples.py @@ -4,7 +4,7 @@ from photoblaster.modules import Modules modules = Modules() for module_name in modules.list_modules(): - if module_name == "pbconcat": + if module_name == "pbpattern": print "\n\n\n" print "running example for %s" % module_name cls = modules.get_module(module_name) diff --git a/share/frontend/im/js/main.js b/share/frontend/im/js/main.js index ac62ec6..27dbc96 100644 --- a/share/frontend/im/js/main.js +++ b/share/frontend/im/js/main.js @@ -43,31 +43,32 @@ var Main = dispose: $('#dispose').val(), username: $("#img-name").val(), } - if (form.rotate.match(/-/)){ form.rotate=360-parseInt(data.rotate.replace("-","")); }; - $("#img-rotate").val(""); - if (form.username.length > 0) - document.cookie = "imname="+data.username+";path=/;domain=.asdf.us;max-age=1086400" - $.ajax({ - url: '/im/api/generate', - type: 'post', - dataType: 'json', - data: form, - success: function(data){ Main.callback(data) }, - error: function(data){ - switch(data.status){ - case 500: - alert("Problem with server") - console.log(data) - break; - case 410: - alert(JSON.parse(data.responseText).message) - break; - default: - console.log(data) - } - Main.generating = false - } - }); + if (form.rotate.match(/-/)){ form.rotate=360-parseInt(data.rotate.replace("-","")); }; + $("#img-rotate").val(""); + if (form.username.length > 0){ + document.cookie = "imname="+form.username+";path=/;domain=.asdf.us;max-age=1086400" + } + $.ajax({ + url: '/im/api/generate', + type: 'post', + dataType: 'json', + data: form, + success: function(data){ Main.callback(data) }, + error: function(data){ + switch(data.status){ + case 500: + alert("Problem with server") + console.log(data) + break; + case 410: + alert(JSON.parse(data.responseText).message) + break; + default: + console.log(data) + } + Main.generating = false + } + }); }, error: function (s) { diff --git a/share/frontend/impattern/js/inputs.js b/share/frontend/impattern/js/inputs.js index 69cd2d3..283bd52 100644 --- a/share/frontend/impattern/js/inputs.js +++ b/share/frontend/impattern/js/inputs.js @@ -12,7 +12,7 @@ $('.patterns').click(function(){ 'box-shadow': '0px 0px 9px 3px firebrick' }) - selected_pattern = /url\((.+)\)$/.exec($(this).css("background-image"))[1]; + selected_pattern = /url\(["']?(.+)["']\)$/.exec($(this).css("background-image"))[1]; preview_controller.from_image(selected_pattern) $('.patterns').attr("current_pattern", selected_pattern); }); |
