summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPepper <pepper@scannerjammer.com>2015-09-27 03:02:22 -0400
committerPepper <pepper@scannerjammer.com>2015-09-27 03:02:22 -0400
commit480896bd416d0dfef7716508c6a10144d0fa068e (patch)
tree2a2297334e990e94f241a7882c5a61cf0f25a702
parent30126dfc2877a82b8af02d68ca3b155068d551dd (diff)
ready for merge and ready for publish
-rw-r--r--lib/param/__init__.py2
-rw-r--r--lib/param/img_url.py19
-rw-r--r--lib/param/param.py10
-rw-r--r--lib/params.py51
-rw-r--r--lib/pb/__init__.py2
-rwxr-xr-xlib/pb/generate.py3
-rw-r--r--lib/server.py14
-rw-r--r--run_module_examples.py11
8 files changed, 51 insertions, 61 deletions
diff --git a/lib/param/__init__.py b/lib/param/__init__.py
index 4f3daba..c7ea845 100644
--- a/lib/param/__init__.py
+++ b/lib/param/__init__.py
@@ -1,5 +1,5 @@
"""imports for the param package"""
-from .param import Param
+from .param import Param, BadParamError
from .int_ import Int
from .raw import Raw
from .bool_ import Bool
diff --git a/lib/param/img_url.py b/lib/param/img_url.py
index 69e3d66..84d6123 100644
--- a/lib/param/img_url.py
+++ b/lib/param/img_url.py
@@ -25,16 +25,12 @@ class Img_url(Param):
"""
super(Img_url, self).__init__(classname=classname)
if value:
- try:
- self.filename = self._filename_temporary(key)
+ self.filename = self._filename_temporary(key)
- self.path = os.path.join(self._working_dir, self.filename)
- self._image_download(value, self.path)
- self.mimetype = self._image_mimetype(self.path)
- self.url = value
- except Exception as e:
- self.err_warn("Unable to download image: %s" % str(value))
- self.err_warn(str(e))
+ self.path = os.path.join(self._working_dir, self.filename)
+ self._image_download(value, self.path)
+ self.mimetype = self._image_mimetype(self.path)
+ self.url = value
def _filename_temporary(self, s):
return "_tmp-{}-{}_{}".format(self._classname, self._now, s)
@@ -78,7 +74,7 @@ class Img_url(Param):
response = urllib2.urlopen(req)
except IOError as e:
if hasattr(e, 'code'):
- sys.stderr.write('browser request error: %s - ERROR %s' % (url, e.code))
+ self.err_warn('browser request error: %s - ERROR %s' % (url, e.code))
raise IOError
return response
@@ -107,5 +103,4 @@ class Img_url(Param):
).communicate()[0].split(" ")[1].lower()
return mimetype
except Exception as e:
- sys.stderr.write("couldn't determine mimetype\n")
- raise e
+ self.err_warn("Couldn't determine mimetype")
diff --git a/lib/param/param.py b/lib/param/param.py
index d1e1446..3268274 100644
--- a/lib/param/param.py
+++ b/lib/param/param.py
@@ -36,9 +36,9 @@ class Param(object):
except Exception as e:
self.err_warn("Unable to set value {}".format(value))
- def err_warn(self, s, error=None):
- self._error_log(s, error=error)
- raise BadParamError("%s - %s" % (self._classname, s))
+ def err_warn(self, s):
+ self._error_log(s)
+ raise BadParamError("%s - %s\n" % (self._classname, s))
def __getattr__(self, key):
try:
@@ -50,10 +50,8 @@ class Param(object):
self._log(s, error, fatal=True)
sys.exit(1)
- def _error_log(self, s, error=None, fatal=False):
+ def _error_log(self, s, fatal=False):
message = "ERROR - BAD PARAM"
if fatal: message += "- [FATAL] -"
sys.stderr.write("{}:{} - {}\n".format(message, self._classname, s))
- if error:
- sys.stderr.write("PARAM ERROR: {}\n".format(str(error)))
diff --git a/lib/params.py b/lib/params.py
index 2f3bf31..04677c0 100644
--- a/lib/params.py
+++ b/lib/params.py
@@ -44,31 +44,28 @@ class Params(object):
to attribute values of the params class"""
value = None
for key in def_dict.keys():
- try:
- value = None
- if key in classkwargs:
- value = classkwargs.get(key, None) or def_dict[key].get('default', None)
- elif 'default' in def_dict[key]:
- value = def_dict[key]['default']
- if def_dict[key]['type'] == "bool":
- instance = Bool(value, classname=classname)
- elif def_dict[key]['type'] == "color":
- instance = Color(value, classname=classname)
- elif def_dict[key]['type'] == "enum":
- instance = Enum(value, enum_values=def_dict[key]['enum_values'], classname=classname)
- elif def_dict[key]['type'] == "float":
- instance = Float(value, classname=classname)
- elif def_dict[key]['type'] == "img_url":
- instance = Img_url(value, key=key, classname=classname)
- elif def_dict[key]['type'] == "int":
- instance = Int(value, classname=classname)
- elif def_dict[key]['type'] == "json":
- instance = Json(value, classname=classname)
- elif def_dict[key]['type'] == "raw":
- instance = Raw(value, classname=classname)
- elif def_dict[key]['type'] == "string":
- instance = String(value, classname=classname)
- self.__setattr__(key, instance)
- except Exception as e:
- self.err_warn("key: %s value: %s" % (key, str(def_dict[key])), error=str(e))
+ value = None
+ if key in classkwargs:
+ value = classkwargs.get(key, None) or def_dict[key].get('default', None)
+ elif 'default' in def_dict[key]:
+ value = def_dict[key]['default']
+ if def_dict[key]['type'] == "bool":
+ instance = Bool(value, classname=classname)
+ elif def_dict[key]['type'] == "color":
+ instance = Color(value, classname=classname)
+ elif def_dict[key]['type'] == "enum":
+ instance = Enum(value, enum_values=def_dict[key]['enum_values'], classname=classname)
+ elif def_dict[key]['type'] == "float":
+ instance = Float(value, classname=classname)
+ elif def_dict[key]['type'] == "img_url":
+ instance = Img_url(value, key=key, classname=classname)
+ elif def_dict[key]['type'] == "int":
+ instance = Int(value, classname=classname)
+ elif def_dict[key]['type'] == "json":
+ instance = Json(value, classname=classname)
+ elif def_dict[key]['type'] == "raw":
+ instance = Raw(value, classname=classname)
+ elif def_dict[key]['type'] == "string":
+ instance = String(value, classname=classname)
+ self.__setattr__(key, instance)
diff --git a/lib/pb/__init__.py b/lib/pb/__init__.py
index d87fb7e..10f4ae6 100644
--- a/lib/pb/__init__.py
+++ b/lib/pb/__init__.py
@@ -1,5 +1,5 @@
"""Convenience for relative imports"""
-from .pb import Pb
+from .pb import Pb, PbProcessError
from .grid import PbGrid
from .breaker import PbBreaker
from .pattern import PbPattern
diff --git a/lib/pb/generate.py b/lib/pb/generate.py
index 5fc1402..6bf99c3 100755
--- a/lib/pb/generate.py
+++ b/lib/pb/generate.py
@@ -34,7 +34,8 @@ class PbGenerate(Pb):
'saturation': '100',
'merge_early': 'true',
'format': 'gif',
- 'background': 'http://i.asdf.us/im/bc/new_1430440747.gif',
+ 'background': 'bob',
+ #'background': 'http://i.asdf.us/im/bc/new_1430440747.gif',
'subtract': '#EE7AE9',
'transparent': 'true',
'name': 'yo',
diff --git a/lib/server.py b/lib/server.py
index 3a91632..e41062b 100644
--- a/lib/server.py
+++ b/lib/server.py
@@ -8,6 +8,7 @@ from paste.translogger import TransLogger
sys.path.append("./lib")
from pb import *
+from param import BadParamError
from config import SERVER_HOST, SERVER_PORT
class InvalidUsage(Exception):
@@ -70,15 +71,12 @@ class Server(object):
pb.db_send()
return jsonify(pb.file_dict())
- #FIXME handle BadParamsError and PbError separately
- except Exception as e:
- sys.stderr.write("%s failure" % pb_class.__name__)
- sys.stderr.write("params:\n")
- sys.stderr.write(str(e))
+ except BadParamError:
for i in request_form.keys():
- sys.stderr.write("{}:{}\n".format(i, request_form[i]))
- raise
- return jsonify({'error' : 'Request could not be processed'})
+ sys.stderr.write('\'%s\':\'%s\'\n' % (i, request_form[i] or None))
+ return jsonify({'error' : 'Bad Params'})
+ except PbProcessError:
+ return jsonify({'error' : 'Problem with server-side processing' })
def run(self, host=SERVER_HOST, port=SERVER_PORT):
self.app.run(host=host, port=port)
diff --git a/run_module_examples.py b/run_module_examples.py
index 7803fc0..637fd81 100644
--- a/run_module_examples.py
+++ b/run_module_examples.py
@@ -4,8 +4,9 @@ import sys
sys.path.append('./lib')
from pb import *
for cls in Pb.__subclasses__():
- print cls.__name__
- instance = cls.example_run()
- instance.file_s3move()
- print instance.file_dict()
- instance.db_send();
+ if cls.__name__ == "PbGenerate":
+ print cls.__name__
+ instance = cls.example_run()
+ instance.file_s3move()
+ print instance.file_dict()
+ instance.db_send();