summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpepperpepperpepper <pepper@scannerjammer.com>2015-12-08 15:51:26 -0800
committerpepperpepperpepper <pepper@scannerjammer.com>2015-12-08 15:51:26 -0800
commit6c3c36e2e3670a3fc3b84f051558eb77ba6ff373 (patch)
treefb9640ad01068aed1831b73cc5855429733c8311
parentd3bd099bc89bb06e0d2e569e6cbab9a932ef2237 (diff)
removed api class, simplified source tree
-rwxr-xr-xexample.py23
-rw-r--r--ricky/params.py107
-rw-r--r--ricky/pbbreaker/__init__.py12
-rw-r--r--ricky/pbbreaker/params.py59
-rw-r--r--ricky/pbgradient/__init__.py13
-rw-r--r--ricky/pbgradient/params.py167
-rw-r--r--ricky/pbgrid/__init__.py12
-rw-r--r--ricky/pbgrid/params.py132
-rwxr-xr-xricky/pbpattern/__init__.py12
-rw-r--r--ricky/pbpattern/params.py25
10 files changed, 12 insertions, 550 deletions
diff --git a/example.py b/example.py
index 0bafc8b..4b98c13 100755
--- a/example.py
+++ b/example.py
@@ -1,21 +1,22 @@
#!/usr/bin/python2.7
-from ricky.pbgradient import PbGradient
-from ricky.pbbreaker import PbBreaker
-from ricky.pbgrid import PbGrid
-from ricky.pbpattern import PbPattern
+from ricky.params.pbgradient import PbGradient
+from ricky.params.pbbreaker import PbBreaker
+from ricky.params.pbgrid import PbGrid
+from ricky.params.pbpattern import PbPattern
import ricky.utils as utils
-api = PbGradient()
-params = api.params_init()
+params = PbGradient()
params.randomize()
+params.execute()
print params
#print params
+#print params
#print params.execute()
-data = utils.data_from_url(
- "http://i.asdf.us/im/8f/PbGradientblue4-DarkGreen_1448917630.png"
-)
-params.from_dict(data['params'])
-print params
+#data = utils.data_from_url(
+# "http://i.asdf.us/im/8f/PbGradientblue4-DarkGreen_1448917630.png"
+#)
+#params.from_dict(data['params'])
+#print params
#print params['color1']
#params['color1'].from_normalized(0.28187431585)
#print params['color1']
diff --git a/ricky/params.py b/ricky/params.py
deleted file mode 100644
index 5ba90c0..0000000
--- a/ricky/params.py
+++ /dev/null
@@ -1,107 +0,0 @@
-"""base class for all params"""
-import pprint
-import simplejson as json
-import sys
-import os
-from ricky.config import PROBABILITIES_DIR, OFFLINE
-import ricky.utils as utils
-
-
-class Params(object):
- def __init__(self, *args):
- self._api = None
- self._url = None
- self._params = tuple(args)
-
- def __getitem__(self, name):
- """getter for the param by name"""
- for param in self._params:
- if param.name == name:
- return param
- raise ValueError("No param with name %s\n" % name)
-
- def __str__(self):
- """string representation"""
- return pprint.pformat(self.as_dict())
-
- def _load_probabilities_json(self, probabilities_file=None):
- if probabilities_file:
- filepath = probabilities_file
- else:
- filepath = os.path.join(
- PROBABILITIES_DIR,
- "%s.json" % (self.api.__class__.__name__)
- )
- try:
- f = open(filepath, 'r')
- data = f.read()
- f.close()
- return json.loads(data)
- except json.scanner.JSONDecodeError as e:
- sys.stderr.write("Invalid Json - Problem decoding %s\n" % filepath)
- sys.stderr.write("%s\n" % e)
- sys.exit(1)
- except IOError:
- sys.stderr.write(
- "Could not find probabilities file %s\n" % filepath)
- sys.exit(1)
-
- def randomize(
- self,
- probabilities=None,
- probabilities_local=False
- ):
- """assign random values to all params
- if using a probabilities.json file, weight is taken
- into account"""
- if probabilities:
- probabilities_dict = self._load_probabilities_json(probabilities)
- elif probabilities_local:
- probabilities_dict = self._load_probabilities_json()
- else:
- probabilities_dict = {}
- for param in self._params:
- param.randomize(probabilities=probabilities_dict.get(param.name))
-
- @property
- def api(self):
- """property setter for im api"""
- return self._api
-
- @api.setter
- def api(self, cls):
- """property getter for im api"""
- self._api = cls
-
- def execute(self):
- """calls the associated api"""
- if OFFLINE:
- sys.path.append("./photoblaster")
- from photoblaster.modules import Pb as _Pb
- from photoblaster.config import LOCAL as PBLOCAL
- for pbcls in _Pb.__subclasses__():
- if pbcls.__name__ == self.__class__.__name__:
- params_dict = self.as_dict()
- instance = pbcls(**params_dict)
- instance.create()
- if not PBLOCAL:
- instance.file_s3move()
- return instance.file_dict()
- return json.loads(
- utils.http_request(self._url, params=self.as_dict())
- )
-
- def as_dict(self):
- """displays the params names and values in dictionary form
- used by the api call
- """
- result = {}
- for param in self._params:
- result[param.name] = param.value
- return result
-
- def from_dict(self, params_dict):
- """set param values manually from a dictionary"""
- for param in self._params:
- if param.name in params_dict.keys():
- param.value = params_dict[param.name]
diff --git a/ricky/pbbreaker/__init__.py b/ricky/pbbreaker/__init__.py
deleted file mode 100644
index cb76b15..0000000
--- a/ricky/pbbreaker/__init__.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from ricky.pb import Pb
-from ricky.pbbreaker.params import Params
-
-
-class PbBreaker(Pb):
- def __init__(self):
- super(PbBreaker, self).__init__()
-
- def params_init(self):
- new_params = Params()
- new_params.api = self
- return new_params
diff --git a/ricky/pbbreaker/params.py b/ricky/pbbreaker/params.py
deleted file mode 100644
index e8438b1..0000000
--- a/ricky/pbbreaker/params.py
+++ /dev/null
@@ -1,59 +0,0 @@
-from ricky.params import Params as _Params
-from ricky.param.username import Username
-from ricky.param.imageurl import PbageUrl
-from ricky.param.enum import Enum
-from ricky.param.constrainednumber import ConstrainedNumber
-from ricky.param.bool import Bool
-from ricky.config import PBBREAKER_URL
-
-_BREAKTYPE_OPTIONS = [
- "CLASSIC",
- "REDUX",
- "BLURRY_BREAK",
- "BLURRY_BREAK_2",
- "SWIPE",
- "RGB_WASH",
- "RGB_WASH_2",
- "NOISY_BREAK",
- "BROKEN_VIGNETTE",
- "FAX_MACHINE",
- "STRIPES",
- "PHOTOCOPY"
-]
-_BREAKMODE_OPTIONS = [
- "extreme",
- "subtle",
-]
-_FINALFORMAT_OPTIONS = [
- "png",
- "jpg",
- "gif",
-]
-
-
-class Params(_Params):
- def __init__(self):
- super(Params, self).__init__(
- Username(name="username", required=False),
- PbageUrl(name="url", required=True),
- Enum(
- name="finalformat",
- required=False,
- options=_FINALFORMAT_OPTIONS),
- Enum(
- name="breaktype",
- required=True,
- options=_BREAKTYPE_OPTIONS),
- ConstrainedNumber(
- name="breakangle",
- required=False,
- enforce_int=True,
- min=-180,
- max=180),
- Enum(
- name="breakmode",
- required=True,
- options=_BREAKMODE_OPTIONS),
- Bool(name="expanded", required=False)
- )
- self._url = PBBREAKER_URL
diff --git a/ricky/pbgradient/__init__.py b/ricky/pbgradient/__init__.py
deleted file mode 100644
index 3de11f4..0000000
--- a/ricky/pbgradient/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-"""class for the imgradient api handler"""
-from ricky.pb import Pb
-from ricky.pbgradient.params import Params
-
-
-class PbGradient(Pb):
- def __init__(self):
- super(PbGradient, self).__init__()
-
- def params_init(self):
- new_params = Params()
- new_params.api = self
- return new_params
diff --git a/ricky/pbgradient/params.py b/ricky/pbgradient/params.py
deleted file mode 100644
index 54686ef..0000000
--- a/ricky/pbgradient/params.py
+++ /dev/null
@@ -1,167 +0,0 @@
-from ricky.params import Params as _Params
-from ricky.param.username import Username
-from ricky.param.enum import Enum
-from ricky.param.constrainednumber import ConstrainedNumber
-from ricky.param.bool import Bool
-from ricky.param.color import Color
-from ricky.config import PBGRADIENT_URL
-
-_HALFTONE_OPTIONS = [
- "",
- "checkeredfade",
- "etchedtransition",
- "bendaydots",
- "smallerdots1",
- "smallerdots2",
- "flatstripes",
-]
-
-_BEVEL_OPTIONS = [
- "",
- "flatout",
- "flatinner",
- "evenlyframed",
- "biginner",
- "bigouter",
- "dramaticflatout",
- "dramaticflatinner",
-]
-
-_FILETYPE_OPTIONS = [
- "png",
- "jpg",
- "gif",
-]
-
-_GRADIENTTYPE_OPTIONS = [
- "canvas",
- "gradient",
- "radial",
- "colorspace",
- "plasmawash",
- "gradientwash",
- "mirrored",
- "noise",
-]
-
-
-class Params(_Params):
- def __init__(self):
- super(Params, self).__init__(
- Username(name="username", required=False),
- ConstrainedNumber(
- name="width",
- required=True,
- enforce_int=True,
- min=10,
- max=800
- ),
- ConstrainedNumber(
- name="height",
- required=True,
- enforce_int=True,
- min=10,
- max=800
- ),
- Color(name="color1", required=True),
- Color(name="color2", required=True),
- Enum(
- name="filetype",
- required=False,
- options=_FILETYPE_OPTIONS
- ),
- Enum(
- name="gradienttype",
- required=True,
- options=_GRADIENTTYPE_OPTIONS
- ),
- Enum(
- name="halftone",
- required=False,
- options=_HALFTONE_OPTIONS
- ),
- Enum(
- name="bevel",
- required=False,
- options=_BEVEL_OPTIONS
- ),
- ConstrainedNumber(
- name="stripenumber",
- required=False,
- enforce_int=True,
- min=0,
- max=400
- ),
- ConstrainedNumber(
- name="stripeintensity",
- required=False,
- enforce_int=True,
- min=0,
- max=5000
- ),
- ConstrainedNumber(
- name="blurriness",
- required=False,
- enforce_int=True,
- min=0,
- max=200
- ),
- ConstrainedNumber(
- name="contrast",
- required=False,
- enforce_int=True,
- min=0,
- max=200
- ),
- ConstrainedNumber(
- name="brightness",
- required=False,
- enforce_int=True,
- min=0,
- max=200
- ),
- ConstrainedNumber(
- name="saturation",
- required=False,
- enforce_int=True,
- min=0,
- max=200
- ),
- ConstrainedNumber(
- name="hue",
- required=False,
- enforce_int=True,
- min=0,
- max=200
- ),
- ConstrainedNumber(
- name="percentbeveled",
- required=False,
- enforce_int=True,
- min=0,
- max=100
- ),
- ConstrainedNumber(
- name="rotate",
- required=False,
- enforce_int=True,
- min=0,
- max=360
- ),
- ConstrainedNumber(
- name="tilt",
- required=False,
- enforce_int=True,
- min=0,
- max=360
- ),
- Bool(
- name="flop",
- required=False,
- ),
- Bool(
- name="flip",
- required=False
- )
- )
- self._url = PBGRADIENT_URL
diff --git a/ricky/pbgrid/__init__.py b/ricky/pbgrid/__init__.py
deleted file mode 100644
index ed195d0..0000000
--- a/ricky/pbgrid/__init__.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from ricky.pb import Pb
-from ricky.pbgrid.params import Params
-
-
-class PbGrid(Pb):
- def __init__(self):
- pass
-
- def params_init(self):
- new_params = Params()
- new_params.api = self
- return new_params
diff --git a/ricky/pbgrid/params.py b/ricky/pbgrid/params.py
deleted file mode 100644
index abf0b3b..0000000
--- a/ricky/pbgrid/params.py
+++ /dev/null
@@ -1,132 +0,0 @@
-from ricky.params import Params as _Params
-from ricky.param.username import Username
-from ricky.param.imageurl import PbageUrl
-from ricky.param.enum import Enum
-from ricky.param.constrainednumber import ConstrainedNumber
-from ricky.param.color import Color
-from ricky.param.bool import Bool
-from ricky.config import PBGRID_URL
-
-_TRANSITION_OPTIONS = [
- "background",
- "dither",
- "random",
- "tile",
- "edge"
-]
-
-_FILETYPE_OPTIONS = [
- "png",
- "jpg",
- "gif",
-]
-
-
-class Params(_Params):
- def __init__(self):
- super(Params, self).__init__(
- Username(name="username", required=False),
- PbageUrl(name="bgimage", required=False),
- PbageUrl(name="imageinstead", required=False),
- PbageUrl(name="planebgimage", required=False),
- Enum(
- name="format",
- required=False,
- options=_FILETYPE_OPTIONS
- ),
- Enum(
- name="transition",
- required=True,
- options=_TRANSITION_OPTIONS
- ),
- Color(name="skycolor", required=False),
- Color(name="planebgcolor", required=False),
- Color(name="bgcolor", required=False),
- Color(name="linecolor", required=False),
- ConstrainedNumber(
- name="swing",
- required=False,
- enforce_int=True,
- min=-170,
- max=170),
- ConstrainedNumber(
- name="tilt",
- required=False,
- enforce_int=True,
- min=-170,
- max=170),
- ConstrainedNumber(
- name="roll",
- required=False,
- enforce_int=True,
- min=-170,
- max=170),
- ConstrainedNumber(
- name="width",
- required=False,
- enforce_int=True,
- min=100,
- max=800),
- ConstrainedNumber(
- name="height",
- required=False,
- enforce_int=True,
- min=100,
- max=800),
- ConstrainedNumber(
- name="linethickness",
- required=False,
- enforce_int=True,
- min=1,
- max=30
- ),
- ConstrainedNumber(
- name="opacity", required=False, min=0, max=1, prec=2),
- ConstrainedNumber(
- name="spacing",
- enforce_int=True,
- required=False,
- min=2,
- max=100),
- Bool(name="vlines", required=False),
- Bool(name="hlines", required=False),
- Bool(name="trim", required=False),
- Bool(name="shadow", required=False),
- ConstrainedNumber(
- name="zoom",
- required=False,
- min=-12,
- max=12,
- forbidden_range_min=-1.1,
- forbidden_range_max=1.1,
- prec=1
- )
- )
- self._url = PBGRID_URL
-
- def _test_values(self):
- return not any([
- (self.__getitem__('spacing').value >
- self.__getitem__('width').value),
- (self.__getitem__('spacing').value >
- self.__getitem__('height').value),
- (self.__getitem__('linethickness').value >
- self.__getitem__('width').value),
- (self.__getitem__('linethickness').value >
- self.__getitem__('height').value),
- ])
-
- def randomize(self):
- p = self._params
- for el in p:
- if el in ['spacing', 'linethickness']:
- continue
- el.randomize()
- for name in ['spacing', 'linethickness']:
- max_tries = 10000
- while(max_tries):
- self.__getitem__(name).randomize()
- if self._test_values():
- return
- max_tries -= 1
- raise ValueError
diff --git a/ricky/pbpattern/__init__.py b/ricky/pbpattern/__init__.py
deleted file mode 100755
index 78af181..0000000
--- a/ricky/pbpattern/__init__.py
+++ /dev/null
@@ -1,12 +0,0 @@
-from ricky.pb import Pb
-from ricky.pbpattern.params import Params
-
-
-class PbPattern(Pb):
- def __init__(self):
- pass
-
- def params_init(self):
- new_params = Params()
- new_params.api = self
- return new_params
diff --git a/ricky/pbpattern/params.py b/ricky/pbpattern/params.py
deleted file mode 100644
index 8c3a885..0000000
--- a/ricky/pbpattern/params.py
+++ /dev/null
@@ -1,25 +0,0 @@
-from ricky.params import Params as _Params
-from ricky.param.username import Username
-from ricky.param.imageurl import PbageUrl
-from ricky.param.enum import Enum
-from ricky.config import PATTERN_URL_BASE, PBPATTERN_URL
-
-
-class Params(_Params):
- def __init__(self):
- super(Params, self).__init__(
- Username(name="username", required=False),
- PbageUrl(name="image_url", required=True),
- Enum(
- name="pattern_url",
- required=True,
- options=self._get_pattern_urls()
- )
- )
- self._url = PBPATTERN_URL
-
- def _get_pattern_urls(self):
- return set(
- ["%s/img/%s.png" % (PATTERN_URL_BASE, i) for i in xrange(0, 97)] +
- ["%s/img/a%s.png" % (PATTERN_URL_BASE, i) for i in xrange(1, 42)]
- )