diff options
| author | pepperpepperpepper <pepper@scannerjammer.com> | 2015-12-07 17:36:03 -0800 |
|---|---|---|
| committer | pepperpepperpepper <pepper@scannerjammer.com> | 2015-12-07 17:36:03 -0800 |
| commit | cd48eb7a6fd7c1e4a94846c3346d7b4cef6a6c50 (patch) | |
| tree | 4d9055f54848c08f651b6580e28be356b5f09570 | |
| parent | e679707290eff0fc30bee0a45b7d409a87c97e8a (diff) | |
finished offline mode for ricky
| -rwxr-xr-x | example.py | 1 | ||||
| m--------- | photoblaster | 0 | ||||
| -rw-r--r-- | ricky/config.py | 12 | ||||
| -rw-r--r-- | ricky/pb.py | 20 | ||||
| -rw-r--r-- | ricky/pbbreaker/__init__.py | 2 | ||||
| -rw-r--r-- | unused/probabilities.py | 21 | ||||
| -rw-r--r-- | unused/probability.py | 9 |
7 files changed, 26 insertions, 39 deletions
@@ -10,6 +10,7 @@ params = api.params_init() print params params.randomize(probabilities_local=True) print params +print params.execute() #print params['color1'] #params['color1'].from_normalized(0.28187431585) #print params['color1'] diff --git a/photoblaster b/photoblaster -Subproject 2f4bd6a0cf0c9a38b527bde3e6e903a2770ff5d +Subproject 0545fd1d7f25c09dd8a6c92ada4b12f1b992de6 diff --git a/ricky/config.py b/ricky/config.py index 9d0ddfa..04da7e1 100644 --- a/ricky/config.py +++ b/ricky/config.py @@ -4,10 +4,10 @@ TEST_URL = ( "http://i.asdf.us/im/" "65/imBreak5qI6DN2_14254-PbPattern_1444004782_pepper.png" ) -PATTERN_URL_BASE = "http://localhost:8999/impattern/patterns" -IMPATTERN_URL = "http://localhost:8999/im/api/impattern" -IMGRID_URL = "http://localhost:8999/im/api/imgrid" -IMGRADIENT_URL = "http://localhost:8999/im/api/imgradient" -IMBREAK_URL = "http://localhost:8999/im/api/imbreak" -OFFLINE = False +PATTERN_URL_BASE = "http://asdf.us/impattern/patterns" +IMPATTERN_URL = "http://asdf.us/im/api/impattern" +IMGRID_URL = "http://asdf.us/im/api/imgrid" +IMGRADIENT_URL = "http://asdf.us/im/api/imgradient" +IMBREAK_URL = "http://asdf.us/im/api/imbreak" +OFFLINE = True PROBABILITIES_DIR = "share/probabilities" diff --git a/ricky/pb.py b/ricky/pb.py index 6e70ea6..d600708 100644 --- a/ricky/pb.py +++ b/ricky/pb.py @@ -26,14 +26,28 @@ class Pb(object): req = urllib2.Request(url, params, headers) response = urllib2.urlopen(req) return response.read() - except urllib.error.HTTPError: - sys.stderr.write("Post Request failed!") + except ValueError: + sys.stderr.write( + "Bad Post params or Url sent to photoblaster" + "api.\n" + ) + except urllib2.URLError: + sys.stderr.write( + "Could not complete post request to the given url:\n" + + ("URL: %s\n" % url) + + ("PARAMS: %s\n" % params) + ) def call(self, params): if self._offline: sys.path.append("./photoblaster") from photoblaster.modules import Pb - pass + for pbcls in Pb.__subclasses__(): + if pbcls.__name__ == self.__class__.__name__: + params_dict = params.as_dict() + instance = pbcls(**params_dict) + instance.create() + return instance.file_dict() return json.loads( self.post_request(self.url, params.as_dict()) ) diff --git a/ricky/pbbreaker/__init__.py b/ricky/pbbreaker/__init__.py index 3a25a2b..2a1c105 100644 --- a/ricky/pbbreaker/__init__.py +++ b/ricky/pbbreaker/__init__.py @@ -5,7 +5,9 @@ from ricky.config import IMBREAK_URL class PbBreaker(Pb): def __init__(self): + super(PbBreaker, self).__init__() self.url = IMBREAK_URL + def params_init(self): new_params = Params() # new_params = self.get_from_server() diff --git a/unused/probabilities.py b/unused/probabilities.py deleted file mode 100644 index d109b18..0000000 --- a/unused/probabilities.py +++ /dev/null @@ -1,21 +0,0 @@ -from ricky.param.probability import Probability -import sys -class Probabilities: - def __init__(self, *args): - self._values = args - def __iter__(self): - return iter(self._values) - def __len__(self): - return len(self._values) - def __str__(self): - return str(self._values) - def __getitem__(self, i): - return self._values[i] - def search(self, s): - for i in self: - if str(s) in i.value: - return i - @classmethod - def from_dict(cls, *args): - probabilities = map(lambda x: Probability(**x), args); - return cls(*probabilities); diff --git a/unused/probability.py b/unused/probability.py deleted file mode 100644 index 0d27b70..0000000 --- a/unused/probability.py +++ /dev/null @@ -1,9 +0,0 @@ -class Probability(dict): - def __init__(self, **kwargs): - super(Probability, self).__init__(**kwargs) - self.value = kwargs["value"] - self.weight = kwargs["weight"] - def __getattr__(self, attr): - return self.get(attr) - __setattr__= dict.__setitem__ - __delattr__= dict.__delitem__ |
