Writing to a file system on an App Engine development server

I'm just trying to use scala and the template scaling system in an appengine application. By default, scalate attempts to write the compiled template to the file system. Now, obviously, this will not work on appengine, and there is a way to precompile the templates. But I was wondering if this restriction can be disabled only during development. This slows down the compilation / testing cycle a bit.

+4
source share
3 answers

I am currently using webpy , which has the same limitation, its template system cannot access the parser module (blocked) and cannot write to the file system in Google App Engine, so you need to precompile the templates.

I solved this unpleasant problem with the help of a Python script, which, every time a file with a given directory is changed, starts a preliminary compilation of this file.

I am on OSX and I use FSEvents , but I believe that you can find other solutions / libraries on any other platform ( incron on 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) 
+1
source

On a Python dev server, you can use it to enter a file when using a 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 or unicode, you may need to add 'wb' or 'wU' to this list. Perhaps there is something in the Java dev server.

+1
source

I would strongly recommend using AppEngine ...

If you are just looking for free JVM / webapp hosting, then Stax.net offers the best alternative. Among other functions, it allows you to write to the file system and create threads.

They also use Scala internally, so they are very suitable for other Scala developers :)

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

(Note: I am in no way attached to Stax)

-3
source

Source: https://habr.com/ru/post/1332329/


All Articles