From 3311bc27f52dc00b9226deb7e683754fa4c8316b Mon Sep 17 00:00:00 2001 From: yo mama Date: Tue, 22 Sep 2015 16:46:02 -0700 Subject: ok finishing server --- lib/Pb/Break/__init__.py | 4 +--- lib/Pb/Generate/__init__.py | 4 +--- lib/Pb/Gradient/__init__.py | 3 +-- lib/Pb/Grid/__init__.py | 4 +--- lib/Pb/Landscape/__init__.py | 3 +-- lib/Pb/Pattern/__init__.py | 3 +-- lib/Pb/__init__.py | 16 ++++++++++++---- lib/Pb/inspect_objects_example.py | 15 --------------- lib/S3Cli/__init__.py | 24 ++++++++++++++++++++++++ lib/_S3/__init__.py | 24 ------------------------ 10 files changed, 42 insertions(+), 58 deletions(-) delete mode 100644 lib/Pb/inspect_objects_example.py create mode 100644 lib/S3Cli/__init__.py delete mode 100644 lib/_S3/__init__.py (limited to 'lib') diff --git a/lib/Pb/Break/__init__.py b/lib/Pb/Break/__init__.py index 45361a5..b7edfb1 100755 --- a/lib/Pb/Break/__init__.py +++ b/lib/Pb/Break/__init__.py @@ -167,7 +167,5 @@ class PbBreak(Pb): #FIXME in db gallery self._prepare_filedata(); self._add_false_data(); self._final_conversion() - self._cleanup() - self._file_dimensions() - self._file_size_get() + super(PbBreak, self).create() diff --git a/lib/Pb/Generate/__init__.py b/lib/Pb/Generate/__init__.py index 3e47a7b..e631002 100755 --- a/lib/Pb/Generate/__init__.py +++ b/lib/Pb/Generate/__init__.py @@ -137,6 +137,4 @@ class PbGenerate(Pb): self._convert() if self.params.background: self._composite() - self._cleanup(); - self._file_dimensions() - self._file_size_get() + super(PbGenerate, self).create() diff --git a/lib/Pb/Gradient/__init__.py b/lib/Pb/Gradient/__init__.py index a05612b..340ce62 100755 --- a/lib/Pb/Gradient/__init__.py +++ b/lib/Pb/Gradient/__init__.py @@ -180,5 +180,4 @@ class PbGradient(Pb): def create(self): self._build_cmd() - self._file_dimensions() - self._file_size_get() + super(PbGradient, self).create() diff --git a/lib/Pb/Grid/__init__.py b/lib/Pb/Grid/__init__.py index 854e174..b0d731f 100755 --- a/lib/Pb/Grid/__init__.py +++ b/lib/Pb/Grid/__init__.py @@ -158,6 +158,4 @@ class PbGrid(Pb): self._threed_rotate_cmd() if self.params.planebgimage: self._overlay_planebgimage() if self.params.trim: self._trim_cmd() - self._cleanup() - self._file_dimensions() - self._file_size_get() + super(PbGrid, self).create() diff --git a/lib/Pb/Landscape/__init__.py b/lib/Pb/Landscape/__init__.py index 153f9ce..5dd8329 100755 --- a/lib/Pb/Landscape/__init__.py +++ b/lib/Pb/Landscape/__init__.py @@ -48,5 +48,4 @@ class PbLandscape(Pb): def create(self, breakmode=""): self._saveImgData(); - self._file_dimensions(); - self._file_size_get(); + super(PbLandscape, self).create() diff --git a/lib/Pb/Pattern/__init__.py b/lib/Pb/Pattern/__init__.py index cc3c431..6ae6eb7 100755 --- a/lib/Pb/Pattern/__init__.py +++ b/lib/Pb/Pattern/__init__.py @@ -83,5 +83,4 @@ class PbPattern(Pb): self._make_canvas(); self._make_mask() self._fuse_mask(); - self._file_dimensions() - self._file_size_get() + super(PbPattern, self).create() diff --git a/lib/Pb/__init__.py b/lib/Pb/__init__.py index 4a5c75d..1b3c79e 100644 --- a/lib/Pb/__init__.py +++ b/lib/Pb/__init__.py @@ -8,7 +8,7 @@ from subprocess import Popen,PIPE,call from Params import Params import sha import simplejson as json -from _S3 import _S3 +from S3Cli import S3Cli from Db import Db BASE_URL = "http://i.asdf.us" @@ -159,7 +159,7 @@ class Pb(object): _insert_data = { 'date' : self._now, 'remote_addr' : remote_addr, - 'username' : self.params.username, + 'username' : str(self.params.username), 'url' : self._db_url_param, 'directory' : self._hashdir, 'oldfile' : None, @@ -175,8 +175,8 @@ class Pb(object): def file_s3move(self): self._hashdir_create() - s3conn = _S3() - s3conn.s3move(self.filepath, "im/{}/{}".format(self._hashdir, self.filename)) + s3cli = S3Cli() + s3cli.s3move(self.filepath, "im/{}/{}".format(self._hashdir, self.filename)) self._file_clean_local(); def file_json(self): @@ -187,6 +187,14 @@ class Pb(object): 'height' : "%spx" % self.file_height, }) + def create(self): + #base methods + if self.__class__.__name__ == 'Pb': + return + self._file_dimensions() + self._file_size_get() + self._cleanup(); + from Pb.Grid import PbGrid from Pb.Break import PbBreak from Pb.Pattern import PbPattern diff --git a/lib/Pb/inspect_objects_example.py b/lib/Pb/inspect_objects_example.py deleted file mode 100644 index 92e28b7..0000000 --- a/lib/Pb/inspect_objects_example.py +++ /dev/null @@ -1,15 +0,0 @@ -class Test(object): - def __init__(self, one="la", two="di"): - self._test_args(inspect.getargvalues(inspect.currentframe())); - - def _test_args(self, _args_vals): - for arg in _args_vals.args: - if arg == "self": - continue - try: - sys.stdout.write("%s\n" % arg) - sys.stdout.write("\t%s\n" % _args_vals.locals.get(arg)) - except Exception as e: - sys.stderr.write("%s\n" % e ); - -t = Test(); diff --git a/lib/S3Cli/__init__.py b/lib/S3Cli/__init__.py new file mode 100644 index 0000000..70ba24c --- /dev/null +++ b/lib/S3Cli/__init__.py @@ -0,0 +1,24 @@ +from config import * +import sys +from boto.s3.connection import S3Connection +from boto.s3.key import Key +class S3Cli(object): + def __init__(self): + try: + self.conn = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, is_secure=False) + self.bucket = self.conn.get_bucket(BUCKET_NAME) + except Exception as e: + sys.stderr.write("Could not connect to s3\n"); + sys.stderr.write(str(e)) + sys.exit(1) + + def s3move(self, filename,objectname): + try: + k = Key(self.bucket) + k.key = objectname + k.set_contents_from_filename(filename) + k.set_acl('public-read') + k.storage_class = 'REDUCED_REDUNDANCY' + except Exception as e: + sys.stderr.write(str(e)); + sys.exit(1) diff --git a/lib/_S3/__init__.py b/lib/_S3/__init__.py deleted file mode 100644 index dbe50c5..0000000 --- a/lib/_S3/__init__.py +++ /dev/null @@ -1,24 +0,0 @@ -from config import * -import sys -from boto.s3.connection import S3Connection -from boto.s3.key import Key -class _S3(object): - def __init__(self): - try: - self.conn = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, is_secure=False) - self.bucket = self.conn.get_bucket(BUCKET_NAME) - except Exception as e: - sys.stderr.write("Could not connect to s3\n"); - sys.stderr.write(str(e)) - sys.exit(1) - - def s3move(self, filename,objectname): - try: - k = Key(self.bucket) - k.key = objectname - k.set_contents_from_filename(filename) - k.set_acl('public-read') - k.storage_class = 'REDUCED_REDUNDANCY' - except Exception as e: - sys.stderr.write(str(e)); - sys.exit(1) -- cgit v1.2.3-70-g09d2