Permalink
Browse files

Bug 48 - tmp and pub directories for each artist now created on the s…

…erver as needed. export.py now uses the tmp directory to store the layer images and the pub directory for the finished product.
  • Loading branch information...
jonoxia committed Aug 29, 2011
1 parent c8ce8a9 commit 79b5a9a964df9eb2edd71e3438c83c4c012df95f
Showing with 31 additions and 12 deletions.
  1. +16 −11 export.py
  2. +3 −0 pencilbox_config.py.template
  3. +12 −1 webserver_utils.py
View
@@ -27,24 +27,27 @@
import cgitb
import time
from PIL import Image
+from webserver_utils import get_dir_for_artist, verify_id
+from pencilbox_config import FILE_PUB_URL
-BASE_PATH = "/var/www/multicanvas/tmpimages"
-
-def compositeFiles(fileNameList, outFileName):
- baseImage = Image.open( os.path.join(BASE_PATH, fileNameList[0]) )
+def compositeFiles(artist, fileNameList, outFileName):
+ tmp_dir = get_dir_for_artist(artist, "tmp")
+ pub_dir = get_dir_for_artist(artist, "pub")
+ baseImage = Image.open( os.path.join(tmp_dir, fileNameList[0]) )
for fileName in fileNameList[1:]:
- layerImage = Image.open( os.path.join(BASE_PATH, fileName) )
+ layerImage = Image.open( os.path.join(tmp_dir, fileName) )
baseImage.paste(layerImage, (0, 0), layerImage)
- baseImage.save( os.path.join(BASE_PATH, outFileName ))
+ baseImage.save( os.path.join(pub_dir, outFileName ))
-def writeTempFiles(dataBlob, outFileName):
+def writeTempFiles(artist, dataBlob, outFileName):
+ tmp_dir = get_dir_for_artist(artist, "tmp")
layerBlobs = dataBlob.split(",")
filenames = []
for i in xrange(len(layerBlobs)):
data = layerBlobs[i]
filename = "layer%d-%s" % (i, outFileName)
filenames.append(filename)
- file = open( os.path.join(BASE_PATH, filename), "wb")
+ file = open( os.path.join(tmp_dir, filename), "wb")
# Get an "incorrect padding" error on trying to decode.
# Correct b64 padding:
while len(data) % 4 != 0:
@@ -61,15 +64,17 @@ def writeTempFiles(dataBlob, outFileName):
filename = q.getfirst("filename", "untitled")
filename = "%s-%d.png" % (filename, time.time())
-tempFileNames = writeTempFiles(data, filename)
+artist = verify_id()
+tempFileNames = writeTempFiles(artist, data, filename)
-compositeFiles(tempFileNames, filename)
+compositeFiles(artist, tempFileNames, filename)
+url = FILE_PUB_URL % (str(artist.id), filename)
# TODO delete temp files
print "Content-type: text/html"
print
-print "Saved as <a href=\"%s\">%s</a>" % ("/multicanvas/tmpimages/" + filename, filename)
+print "Saved as <a href=\"%s\">%s</a>" % (url, filename)
#except Exception as e:
# print "Content-type: text/html"
# print
@@ -1,3 +1,6 @@
URL_STRING = "Replace this with your SQL database connection string"
DOMAIN = "Replace this with the name of the domain where you're hosting pencilbox"
TEMPLATE_DIR = "Replace this with absolute path to the dir where pencilbox is installed"
+ARTIST_FILE_BASE_DIR = "Replace this with absolute path to where artist files can be stored."
+FILE_PUB_URL = ""
+TMP_FILE_URL = ""
View
@@ -4,7 +4,7 @@
import os
import sys
import string
-from pencilbox_config import TEMPLATE_DIR
+from pencilbox_config import TEMPLATE_DIR, ARTIST_FILE_BASE_DIR
from database_tables import Artist
def render_template_file( filename, substitutionDict ):
@@ -44,3 +44,14 @@ def verify_id():
print_redirect("index.html")
sys.exit(1)
+def get_dir_for_artist(artist, subdir):
+ # subdir should be "tmp" for temp files and "pub" for published files
+ # creates it if it doesn't already exist.
+ dir = os.path.join(ARTIST_FILE_BASE_DIR, "%d" % artist.id)
+ if not (os.path.isdir(dir)):
+ os.mkdir(dir)
+ dir = os.path.join(dir, subdir)
+ if not (os.path.isdir(dir)):
+ os.mkdir(dir)
+ return dir
+

0 comments on commit 79b5a9a

Please sign in to comment.