--- 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"""
--- 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:]
--- 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))
+