summaryrefslogtreecommitdiff
path: root/lib/Pb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Pb')
-rwxr-xr-xlib/Pb/Break/__init__.py4
-rwxr-xr-xlib/Pb/Break/__init__.py~2
-rwxr-xr-xlib/Pb/Generate/__init__.py4
-rwxr-xr-xlib/Pb/Gradient/__init__.py5
-rwxr-xr-xlib/Pb/Grid/__init__.py6
-rwxr-xr-xlib/Pb/Landscape/__init__.py4
-rwxr-xr-xlib/Pb/Pattern/__init__.py5
-rw-r--r--lib/Pb/__init__.py64
8 files changed, 60 insertions, 34 deletions
diff --git a/lib/Pb/Break/__init__.py b/lib/Pb/Break/__init__.py
index d8faa14..45361a5 100755
--- a/lib/Pb/Break/__init__.py
+++ b/lib/Pb/Break/__init__.py
@@ -5,7 +5,7 @@ import random
import re
import urllib
import inspect
-from Config import *
+from config import *
from Pb import Pb
from Params import Params
@@ -168,4 +168,6 @@ class PbBreak(Pb): #FIXME in db gallery
self._add_false_data();
self._final_conversion()
self._cleanup()
+ self._file_dimensions()
+ self._file_size_get()
diff --git a/lib/Pb/Break/__init__.py~ b/lib/Pb/Break/__init__.py~
index c1064e2..64d9cc6 100755
--- a/lib/Pb/Break/__init__.py~
+++ b/lib/Pb/Break/__init__.py~
@@ -5,7 +5,7 @@ import random
import re
import urllib
import inspect
-from Config import *
+from config import *
from Pb import Pb
from Pb.Params import Params
diff --git a/lib/Pb/Generate/__init__.py b/lib/Pb/Generate/__init__.py
index 8e206db..3e47a7b 100755
--- a/lib/Pb/Generate/__init__.py
+++ b/lib/Pb/Generate/__init__.py
@@ -1,7 +1,7 @@
#!/usr/bin/python2.7
import sys
import os
-from Config import *
+from config import *
from Pb import Pb
_default_tag = "im"
@@ -138,3 +138,5 @@ class PbGenerate(Pb):
if self.params.background:
self._composite()
self._cleanup();
+ self._file_dimensions()
+ self._file_size_get()
diff --git a/lib/Pb/Gradient/__init__.py b/lib/Pb/Gradient/__init__.py
index 25e84bb..a05612b 100755
--- a/lib/Pb/Gradient/__init__.py
+++ b/lib/Pb/Gradient/__init__.py
@@ -6,7 +6,7 @@ import simplejson as json
import sys
import os
import sha
-from Config import *
+from config import *
from Pb import Pb
_default_color_1 = "white"
@@ -180,4 +180,5 @@ class PbGradient(Pb):
def create(self):
self._build_cmd()
-
+ self._file_dimensions()
+ self._file_size_get()
diff --git a/lib/Pb/Grid/__init__.py b/lib/Pb/Grid/__init__.py
index b940d5c..854e174 100755
--- a/lib/Pb/Grid/__init__.py
+++ b/lib/Pb/Grid/__init__.py
@@ -3,8 +3,8 @@ import re
import os
import simplejson as json
import random
-from Config import DEFAULT_FINALFORMAT, DEFAULT_HEIGHT, DEFAULT_WIDTH, WORKING_DIR, OUTPUT_IMAGE_TYPES
-from Config import THREEDROTATE, GRID, BIN_CONVERT, BIN_COMPOSITE
+from config import DEFAULT_FINALFORMAT, DEFAULT_HEIGHT, DEFAULT_WIDTH, WORKING_DIR, OUTPUT_IMAGE_TYPES
+from config import THREEDROTATE, GRID, BIN_CONVERT, BIN_COMPOSITE
import tempfile
from Pb import Pb
@@ -159,3 +159,5 @@ class PbGrid(Pb):
if self.params.planebgimage: self._overlay_planebgimage()
if self.params.trim: self._trim_cmd()
self._cleanup()
+ self._file_dimensions()
+ self._file_size_get()
diff --git a/lib/Pb/Landscape/__init__.py b/lib/Pb/Landscape/__init__.py
index cc1bcb0..153f9ce 100755
--- a/lib/Pb/Landscape/__init__.py
+++ b/lib/Pb/Landscape/__init__.py
@@ -1,4 +1,4 @@
-from Config import *
+from config import *
import Pb
import base64
from Pb import Pb
@@ -48,3 +48,5 @@ class PbLandscape(Pb):
def create(self, breakmode=""):
self._saveImgData();
+ self._file_dimensions();
+ self._file_size_get();
diff --git a/lib/Pb/Pattern/__init__.py b/lib/Pb/Pattern/__init__.py
index 930af64..cc3c431 100755
--- a/lib/Pb/Pattern/__init__.py
+++ b/lib/Pb/Pattern/__init__.py
@@ -3,7 +3,7 @@ import sys
import random
import re
import urllib
-from Config import *
+from config import *
from Pb import Pb
import simplejson as json
@@ -83,4 +83,5 @@ class PbPattern(Pb):
self._make_canvas();
self._make_mask()
self._fuse_mask();
-
+ self._file_dimensions()
+ self._file_size_get()
diff --git a/lib/Pb/__init__.py b/lib/Pb/__init__.py
index eab9878..4a5c75d 100644
--- a/lib/Pb/__init__.py
+++ b/lib/Pb/__init__.py
@@ -1,5 +1,5 @@
import re
-from Config import *
+from config import *
import time
import urllib, urllib2
import sys, os
@@ -7,6 +7,10 @@ import random
from subprocess import Popen,PIPE,call
from Params import Params
import sha
+import simplejson as json
+from _S3 import _S3
+from Db import Db
+BASE_URL = "http://i.asdf.us"
Request = urllib2.Request
urlencode = urllib.urlencode
@@ -27,7 +31,7 @@ class Pb(object):
self._working_dir = WORKING_DIR
self._tag = self.__class__.__name__
self._hashdir = None
- self._db_url_param = "NULL"
+ self._db_url_param = None
def _filename_create(self, url=None, namepart="", extension=""):
if url:
@@ -68,11 +72,15 @@ class Pb(object):
raise Exception("Unable to call cmd {}".format(str(cmd)))
def _dimensions(self, filepath):
- ident = (Popen([BIN_IDENTIFY, filepath], stdout=PIPE).communicate()[0]).split(" ")
- return ident[2].split("x")
+ try:
+ ident = (Popen([BIN_IDENTIFY, filepath], stdout=PIPE).communicate()[0]).split(" ")
+ return ident[2].split("x")
+ except Exception as e:
+ self.err_warn("Unable to get file dimensions:\n")
+ self.err_ward(str(e))
- def file_dimensions (self):
- return self._dimensions(self.filename)
+ def _file_dimensions (self):
+ self.file_width, self.file_height = self._dimensions(self.filepath)
def _width_and_height_set(self, filepath=None, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT):
if filepath:
@@ -81,9 +89,9 @@ class Pb(object):
self.width = width
self.height = height
- def file_size(self):
+ def _file_size_get(self):
try:
- return os.stat(self.filepath)[6]
+ self.file_size = os.stat(self.filepath)[6]
except Exception as e:
self.err_warn("Couldn't determine filesize of %s\n" % self.filepath)
self.err_warn(str(e))
@@ -119,7 +127,8 @@ class Pb(object):
if verbose:
sys.stderr.write("generated %s\n" % b.filepath)
sys.stderr.write("files created %s\n" % b._files_created)
- sys.stderr.write("commands %s" % " ".join(b.commands))
+ sys.stderr.write("commands:\n %s\n" % ";\n ".join(b.commands))
+ return b
@staticmethod
def gif_frames(filepath):
@@ -139,36 +148,43 @@ class Pb(object):
frame = random.choice(_gif_frames)
self._call_cmd([BIN_CONVERT, frame, filepath])
- def db_send(self, remote_addr="NULL"):
+ def db_send(self, remote_addr=None, db_connection=None):
try:
- db.insert_cmd(**{
+ db = db_connection or Db();
+ except Exception as e:
+ sys.stderr.write("Could not connect to db:\n{}".format(e))
+ sys.exit(1);
+ try:
+
+ _insert_data = {
'date' : self._now,
'remote_addr' : remote_addr,
- 'username' : self.params.username or "NULL",
+ 'username' : self.params.username,
'url' : self._db_url_param,
'directory' : self._hashdir,
- 'oldfile' : "NULL", #weird
- 'newfile' : im.filename,
+ 'oldfile' : None,
+ 'newfile' : self.filename,
'dataobj' : json.dumps(dict(self._input_kwargs)),
'cmd' : ";".join(self.commands),
'tag' : self._tag,
- })
+ }
+ sys.stderr.write(str(_insert_data))
+ db.insert_cmd(**_insert_data)
except Exception as e:
- self.err_warn("Problem sending to database")
-
+ self.err_warn("Problem sending to database:\n %s" % str(e))
+
def file_s3move(self):
self._hashdir_create()
- s3move(im.filepath, "im/{}/{}".format(self._hashdir, im.filename))
- self._files_created.append(self.filepath)
+ s3conn = _S3()
+ s3conn.s3move(self.filepath, "im/{}/{}".format(self._hashdir, self.filename))
self._file_clean_local();
def file_json(self):
- dimensions = self.file_dimensions();
return json.dumps({
- 'url' : "im/%s/%s".format(BASE_URL, self._hashdir, self.filename),
- 'size' : self.file_size(),
- 'width' : "{}px".format(dimensions[0]),
- 'height' : "{}px".format(dimensions[1]),
+ 'url' : "%s/im/%s/%s" % (BASE_URL, self._hashdir, self.filename),
+ 'size' : self.file_size,
+ 'width' : "%spx" % self.file_width,
+ 'height' : "%spx" % self.file_height,
})
from Pb.Grid import PbGrid