diff options
Diffstat (limited to 'Pb/Generate/__init__.py')
| -rwxr-xr-x | Pb/Generate/__init__.py | 218 |
1 files changed, 105 insertions, 113 deletions
diff --git a/Pb/Generate/__init__.py b/Pb/Generate/__init__.py index 191d600..3aa9c6d 100755 --- a/Pb/Generate/__init__.py +++ b/Pb/Generate/__init__.py @@ -1,72 +1,124 @@ #!/usr/bin/python2.7 import sys import os - from Config import * from Pb import Pb -#FIXME these guys can do stuff wider than 1000 -LIKE_A_BOSS = "ryz pepper seamonkey JAMES".split(" ") -DEFAULT_FINALFORMAT = "gif" -DEFAULT_TAG = "im"; -GRAVITY_PARAMS = ["NorthWest","North","NorthEast","West","Center","East","SouthWest","South","SouthEast"] -GRAVITY_DEFAULT = "Center" -FORMAT_PARAMS = ["jpg", "gif", "png"] -COMPOSE_PARAMS = [ "Over", "ATop", "Dst_Over", "Dst_In", "Dst_Out", "Multiply", +_gravity_params = ["NorthWest","North","NorthEast","West","Center","East","SouthWest","South","SouthEast"] +_gravity_default = "Center" +_compose_params = [ "Over", "ATop", "Dst_Over", "Dst_In", "Dst_Out", "Multiply", "Screen", "Divide", "Plus", "Difference", "Exclusion", "Lighten", "Darken", "Overlay", "Hard_Light", "Soft_Light", "Linear_Dodge", "Linear_Burn", "Color_Dodge", "Color_Burn" ] -DISPOSE_PARAMS = ["None","Previous","Background"] -DISPOSE_DEFAULT = "None" - -def debuglog(s): - sys.stderr.write(str(s) + "\n"); +_dispose_params = ["None","Previous","Background"] +_dispose_default = "None" class Im(Pb): - def __init__(self, **kwargs): - self.params = {} - self._now = self.now() - self.files_created = [] - self.commands = []; - self._required_keys = [ + example_params = { + 'nearest': 'true', + # 'height': None, + 'compose': 'Soft_Light', + 'coalesce': 'true', + 'dispose': 'None', + 'gravity': 'Center', + 'width': '200', + 'black': 'black', + 'tile': 'true', + 'white': 'white', + 'contrast': '100', + 'hue': '90', + 'saturation': '100', + 'merge_early': 'true', + 'format': 'gif', + 'background': 'http://i.asdf.us/im/bc/new_1430440747.gif', + 'subtract': '#EE7AE9', + 'transparent': 'true', + # 'rotate': None, + 'name': 'yo', + # 'brightness': None, + 'url': 'http://asdf.us/im/new.gif', + 'flop': 'true', + 'flip': 'false', + 'callback': 'jsonp1430442384162', + 'fuzz': '5' + } + def __init__(self, + #URLS + url=None, + background=None, + + #BOOLS + coalesce=None, + dispose="None", + nearest=None, + merge_early=None, + flip=None, + flop=None, + tile=None, + transparent=None, + + #COLORS + black=None, + white=None, + subtract=None, + + #INTS + fuzz=None, + width=None, + height=None, + brightness=None, + contrast=None, + saturation=None, + rotate=None, + hue=None, + + #ENUMS + compose=None, + gravity=_gravity_default, + format=DEFAULT_FINALFORMAT, + + #STRINGS + username=None, + callback=None, + ): #{{{ required_keys - #IMAGES - "url", - "background", + #IMAGES + "url", + "background", - #BOOLS - "coalesce", - "dispose", - "nearest", - "merge_early", - "flip", - "flop", - "tile", - "transparent", + #BOOLS + "coalesce", + "dispose", + "nearest", + "merge_early", + "flip", + "flop", + "tile", + "transparent", - #COLORS - "black", - "white", - "subtract", + #COLORS + "black", + "white", + "subtract", - #INTS - "fuzz", - "width", - "height", - "brightness", - "contrast", - "saturation", - "rotate", - "hue", - - #ENUMS - "compose", - "gravity", - "format", + #INTS + "fuzz", + "width", + "height", + "brightness", + "contrast", + "saturation", + "rotate", + "hue", + + #ENUMS + "compose", + "gravity", + "format", - #STRINGS - "username", - "callback", + #STRINGS + "username", + "callback", #}}} ] for k in self._required_keys: @@ -124,33 +176,6 @@ class Im(Pb): self.filename = "{}.{}".format(self.basename, self.params.get('format', DEFAULT_FINALFORMAT)) self.filepath = os.path.join(WORKING_DIR, self.filename) - def _make_tempname(self, s): - return "PBTMP{}{}".format(self._now, s); - - def _test_enum(self, e, arr): - if e in arr: return True - raise Exception ("Bad value: {}".format(e)) - - def _get_filename(self): - return "{}_{}_{}".format( - self.tag, - self._now, - self.params.get('username',"") - ); - - def _call_cmd(self, cmd): - try: - self.call_cmd(cmd) - self.commands.append(" ".join(cmd)); - except Exception: - raise Exception("Unable to call cmd {}".format(str(cmd))) - - def _cleanup(self): - if not len(self.files_created): - pass - cmd = ["rm", "-f"] + self.files_created - self._call_cmd(cmd) - def _composite (self): cmd = [ BIN_CONVERT, self.params['background']['path'], @@ -195,36 +220,3 @@ class Im(Pb): if self.params.get('background'): self._composite() self._cleanup(); - -if __name__ == "__main__": - - TEST_PARAMS = { - 'nearest': 'true', -# 'height': None, - 'compose': 'Soft_Light', - 'coalesce': 'true', - 'dispose': 'None', - 'gravity': 'Center', - 'width': '200', - 'black': 'black', - 'tile': 'true', - 'white': 'white', - 'contrast': '100', - 'hue': '90', - 'saturation': '100', - 'merge_early': 'true', - 'format': 'gif', - 'background': 'http://i.asdf.us/im/bc/new_1430440747.gif', - 'subtract': '#EE7AE9', - 'transparent': 'true', -# 'rotate': None, - 'name': 'yo', -# 'brightness': None, - 'url': 'http://asdf.us/im/new.gif', - 'flop': 'true', - 'flip': 'false', - 'callback': 'jsonp1430442384162', - 'fuzz': '5' - } - g = Generate(**TEST_PARAMS); - g.create() |
