# HG changeset patch # User Sylvain Thenault # Date 1227716458 -3600 # Node ID 343e7a18675d6101347f1d432cf01c21337b564f # Parent 1190261a1f13301e97958144fd022c5212ca9920 static files support diff -r 1190261a1f13 -r 343e7a18675d cwctl.py --- a/cwctl.py Wed Nov 26 15:06:10 2008 +0100 +++ b/cwctl.py Wed Nov 26 17:20:58 2008 +0100 @@ -10,7 +10,7 @@ from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage from cubicweb.cwconfig import CubicWebConfiguration, CONFIGURATIONS from cubicweb.toolsutils import (Command, register_commands, main_run, - rm, create_dir, pop_arg, confirm) + rm, create_dir, pop_arg, confirm) def wait_process_end(pid, maxtry=10, waittime=1): """wait for a process to actually die""" diff -r 1190261a1f13 -r 343e7a18675d etwist/server.py --- a/etwist/server.py Wed Nov 26 15:06:10 2008 +0100 +++ b/etwist/server.py Wed Nov 26 17:20:58 2008 +0100 @@ -123,11 +123,16 @@ if segments[0] == 'https': segments = segments[1:] if len(segments) >= 2: - if segments[0] in (self.versioned_datadir, 'data'): - # Anything in data/ is treated as static files - datadir = self.config.locate_resource(segments[1]) - if datadir is None: - return None, [] + if segments[0] in (self.versioned_datadir, 'data', 'static'): + # Anything in data/, static/ is treated as static files + if segments[0] == 'static': + # instance static directory + datadir = self.config.static_directory + else: + # cube static data file + datadir = self.config.locate_resource(segments[1]) + if datadir is None: + return None, [] self.info('static file %s from %s', segments[-1], datadir) if segments[0] == 'data': return static.File(str(datadir)), segments[1:] diff -r 1190261a1f13 -r 343e7a18675d web/webconfig.py --- a/web/webconfig.py Wed Nov 26 15:06:10 2008 +0100 +++ b/web/webconfig.py Wed Nov 26 17:20:58 2008 +0100 @@ -7,7 +7,7 @@ __docformat__ = "restructuredtext en" import os -from os.path import join, dirname, exists +from os.path import join, dirname, exists, split from urlparse import urljoin from logilab.common.configuration import Method @@ -320,3 +320,31 @@ if isinstance(val, str): files = [w.strip() for w in val.split(',') if w.strip()] self.ext_resources[resource] = files + + + # static files handling ################################################### + + @property + def static_directory(self): + return join(self.appdatahome, 'static') + + def static_file_exists(self, rpath): + return exists(join(self.static_directory, rpath)) + + def static_file_open(self, rpath, mode='wb'): + staticdir = self.static_directory + rdir, filename = split(rpath) + if rdir: + staticdir = join(staticdir, rdir) + os.makedirs(staticdir) + return file(join(staticdir, filename), mode) + + def static_file_add(self, rpath, data): + stream = self.static_file_open(rpath) + stream.write(data) + stream.close() + + def static_file_del(self, rpath): + if static_file_exists(rpath): + os.remove(join(self.static_directory, rpath)) +