summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpepperpepperpepper <pepper@scannerjammer.com>2015-11-28 18:05:02 -0800
committerpepperpepperpepper <pepper@scannerjammer.com>2015-11-28 18:05:02 -0800
commit31f6e1654e3d6f5269ce3f53a1d068050f3d7887 (patch)
treef0133c786769f6572923b171f5b39b731826c6de
parent4fd71a291f52267e435ecaebe6b0c4f97c918883 (diff)
made a version that works locally, including the gallery
-rw-r--r--photoblaster/.ropeproject/globalnamesbin1808 -> 1808 bytes
-rw-r--r--photoblaster/config.py28
-rw-r--r--photoblaster/modules/base.py2
-rw-r--r--photoblaster/server.py29
-rw-r--r--photoblaster/templates/gallery.html2
5 files changed, 44 insertions, 17 deletions
diff --git a/photoblaster/.ropeproject/globalnames b/photoblaster/.ropeproject/globalnames
index addb8d5..cc1ff5d 100644
--- a/photoblaster/.ropeproject/globalnames
+++ b/photoblaster/.ropeproject/globalnames
Binary files differ
diff --git a/photoblaster/config.py b/photoblaster/config.py
index 0c211c7..698927f 100644
--- a/photoblaster/config.py
+++ b/photoblaster/config.py
@@ -1,8 +1,12 @@
+import os
LOCAL = True
+if os.environ["PB_PRODUCTION"]:
+ LOCAL = False
+
MAX_SIZE = 1024 * 1024 * 1.2 * 1.5
-#PATHS
+# PATHS
BIN_CONVERT = "/usr/bin/convert"
BIN_COMPOSITE = "/usr/bin/composite"
BIN_IDENTIFY = "/usr/bin/identify"
@@ -10,38 +14,40 @@ THREEDROTATE = "./bin/3Drotate"
GRID = "./bin/grid"
BEVELBORDER = "./bin/bevelborder"
-#common parameters
+# common parameters
DEFAULT_FINALFORMAT = "png";
DEFAULT_HEIGHT = 400
DEFAULT_WIDTH = 600
-OUTPUT_IMAGE_TYPES = ["png", "jpg", "gif" ]
+OUTPUT_IMAGE_TYPES = ["png", "jpg", "gif"]
-#mounted on tmpfs
+# mounted on tmpfs
WORKING_DIR = "/var/www/cache"
STATIC_FOLDER = "../share/frontend/"
-#server
-SERVER_HOST='0.0.0.0'
-SERVER_PORT=8999
+# server
+SERVER_HOST = '0.0.0.0'
+SERVER_PORT = 8999
-#s3
+# s3
AWS_ACCESS_KEY_ID = 'AKIAIR53VPBXKJMXZIBA'
AWS_SECRET_ACCESS_KEY = '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'
BUCKET_NAME = 'i.asdf.us'
-SPECIAL_DOWNLOADERS = [ "ryz pepper RICHARD_GIOVANNI dmgk" ]
+SPECIAL_DOWNLOADERS = ["ryz pepper RICHARD_GIOVANNI dmgk"]
SPECIAL_DOWNLOADERS_MAX_SIZE = 100000
-#database
+# database
DB_HOST = "lalalizard.com"
DB_USER = "asdfus"
DB_PASSWORD = "gTYgT&M6q"
DB_NAME = "asdfus"
+if LOCAL:
+ DB_HOST = "localhost"
-#gallery stuff
+# gallery stuff
GALLERY_TAG_TRANS = {
"grid": "PbGrid",
"gradient": "PbGradient",
diff --git a/photoblaster/modules/base.py b/photoblaster/modules/base.py
index 9e76bcb..dcb6a89 100644
--- a/photoblaster/modules/base.py
+++ b/photoblaster/modules/base.py
@@ -4,7 +4,7 @@ contains only the Pb class which is used by the Pb.* modules for inheritance
import re
from photoblaster.config import WORKING_DIR, BIN_CONVERT, BIN_IDENTIFY,\
- DEFAULT_HEIGHT, DEFAULT_WIDTH
+ DEFAULT_HEIGHT, DEFAULT_WIDTH, LOCAL
import time
import sys
import os
diff --git a/photoblaster/server.py b/photoblaster/server.py
index 9896b7a..36524eb 100644
--- a/photoblaster/server.py
+++ b/photoblaster/server.py
@@ -1,6 +1,6 @@
"""All webserver logic lives here, including routes"""
from flask import Flask, Response
-from flask import request, jsonify, render_template
+from flask import request, jsonify, render_template, send_from_directory
import sys
import re
@@ -14,9 +14,9 @@ from photoblaster.modules import PbGenerate, PbGrid, PbBreaker, PbPattern,\
from photoblaster.db.models.imcmd import ImCmd
from photoblaster.param import BadParamError
from photoblaster.config import SERVER_HOST, SERVER_PORT, STATIC_FOLDER, \
- GALLERY_TAG_TRANS
+ GALLERY_TAG_TRANS, WORKING_DIR, LOCAL
-# FIXME add remote_addr and this jsonp thing
+# and this jsonp thing
_CLASSNAME_ALIASES = {
'generate': 'PbGenerate',
@@ -138,6 +138,14 @@ class Server(object):
else:
results = ImCmd.search(**search_params)
images = results.limit(limit).offset(offset).all()
+ if LOCAL:
+ images = ["/im/cache/%s" % image.newfile for image in images]
+ else:
+ images = [
+ "http://i.asdf.us/im/%s/%s" %
+ (image.directory, image.newfile) for
+ image in images
+ ]
older = offset + limit
newer = offset - limit
qs = "&".join(qs)
@@ -150,6 +158,18 @@ class Server(object):
qs=qs
)
+ @self.app.route('/im/cache/<path:path>', methods=['GET'])
+ def local_cache(path):
+ """
+ FOR LOCAL DEVELOPMENT ONLY
+
+ send static file from the WORKING_DIR directory
+ this allows the gallery to work locally without s3
+ send_static_file will guess the correct MIME type
+ FIXME (add WORKING_DIR to function call)
+ """
+ return send_from_directory(WORKING_DIR, path)
+
def _find_class_by_name(self, pb_classname):
pb_classname = self._classname_aliases.get(pb_classname, None) \
or pb_classname
@@ -166,7 +186,8 @@ class Server(object):
try:
pb = pb_class(**request_form)
pb.create()
- pb.file_s3move()
+ if not LOCAL:
+ pb.file_s3move()
pb.db_send(remote_addr=remote_addr)
json_data = jsonify(pb.file_dict())
if pb.params.callback: # accounts for jsonp
diff --git a/photoblaster/templates/gallery.html b/photoblaster/templates/gallery.html
index 11e7395..347abfd 100644
--- a/photoblaster/templates/gallery.html
+++ b/photoblaster/templates/gallery.html
@@ -12,7 +12,7 @@
<script type="text/javascript">
var imagedata = [
{% for image in images %}
-["http://i.asdf.us/im/{{ image.dir }}/{{ image.newfile }}"],
+[ "{{ image }}" ],
{% endfor %}
]