4

I'm just trying out using scala and the scalate templating system on an appengine application. By default, scalate tries to write the compiled template to the filesystem. Now, obviously this won't work on appengine, and there is a way to precompile the templates. But I was wondering if it is possible to switch off this restriction, just during development. It slows down the compile/test cycle quite a bit.

systempuntoout
  • 71,966
  • 47
  • 171
  • 241
nickclare
  • 41
  • 2

3 Answers3

1

I'm currently using webpy that has the same limitation, its templating system can't access parser module (blocked) and can't write to filesystem on Google App Engine, so you need to precompile the templates upfront.

I have resolved this annoying issue with a Python script that, everytime a file of a given directory is changed, triggers the precompilation of that file.

I'm on OSX and I'm using FSEvents but I believe you can find other solutions/libraries on any other platform (incron in Linux, FileSystemWatcher on Windows):

from fsevents import Observer
from fsevents import Stream
from datetime import datetime
import subprocess
import os
import time

PROJECT_PATH = '/Users/.../Project/GoogleAppEngine/stackprinter/'
TEMPLATE_COMPILE_PATH = os.path.join(PROJECT_PATH,'web','template.py')
VIEWS_PATH = os.path.join(PROJECT_PATH,'app','views')

def callback(event):
    if event.name.endswith('.html'):
        subprocess.Popen('python2.5 %s %s %s' % ( TEMPLATE_COMPILE_PATH ,'--compile', VIEWS_PATH) , shell=True)
        print '%s - %s compiled!' % (datetime.now(), event.name.split('/')[-1])

observer = Observer()
observer.start()
stream = Stream(callback, VIEWS_PATH, file_events=True)
observer.schedule(stream)

while not observer.isAlive():
    time.sleep(0.1) 
Community
  • 1
  • 1
systempuntoout
  • 71,966
  • 47
  • 171
  • 241
  • Actually you can modify the dev server to write to the file system, see my answer. – Einar Egilsson Dec 16 '10 at 14:13
  • 1
    I do have my build process set up to compile the templates, which will be necessary for the production build anyway. It's not a total disaster if I can't get this working, just hoping to avoid the wait every time I change a template. Thanks for the post though, didn't know about FSEvents (I'm on OSX, too), it might come in handy for other things! – nickclare Dec 16 '10 at 14:49
  • @nick you are welcome, it's really handy and blazing fast; you just forget that it's compiling actually. – systempuntoout Dec 16 '10 at 15:08
1

In the Python dev server you can, I use it to log to a file when using the dev server:

if os.environ.get('SERVER_SOFTWARE','').startswith('Dev'):
    from google.appengine.tools.dev_appserver import FakeFile
    FakeFile.ALLOWED_MODES = frozenset(['a','r', 'w', 'rb', 'U', 'rU'])

If you want to write binary files or unicode you might need to add 'wb' or 'wU' to that list. Maybe there is something equivalent in the Java dev server.

Einar Egilsson
  • 3,438
  • 9
  • 36
  • 47
-3

I'd strongly advise against using AppEngine...

If you're just looking for free JVM/webapp hosting, then Stax.net offers a better alternative . Amongst other features, it allows you to write to the filesystem and to spawn threads.

They also use Scala internally, so they're very accommodating towards other Scala developers :)

Stax.net: http://www.stax.net/

(Note: I'm in no way affilliated to Stax)

Kevin Wright
  • 49,540
  • 9
  • 105
  • 155
  • I'm still evaluating my options, but at least as it stands now, stax.net doesn't have everything I'm looking for. The new AppEngine channel API, as well as the easy to use memcache service, image service, etc, make AppEngine an interesting platform. If AppEngine doesn't work out, which is possible, I'd rather go to EC2 directly. From the website it looks like Stax might get some of these things, in which case I'll have to reevaluate – nickclare Dec 16 '10 at 14:37