[z3-checkins] r40785 - in z3/deliverance/trunk: . deliverance deliverance/new_layout_template deliverance/new_layout_template/bin deliverance/new_layout_template/etc deliverance/new_layout_template/log deliverance/new_layout_template/static deliverance/new_layout_template/static/rules deliverance/new_layout_template/var
ianb at codespeak.net
ianb at codespeak.net
Mon Mar 19 18:12:08 CET 2007
Author: ianb
Date: Mon Mar 19 18:12:05 2007
New Revision: 40785
Added:
z3/deliverance/trunk/deliverance/new_layout_template/
z3/deliverance/trunk/deliverance/new_layout_template/bin/
z3/deliverance/trunk/deliverance/new_layout_template/etc/
z3/deliverance/trunk/deliverance/new_layout_template/etc/deliverance-proxy.ini
z3/deliverance/trunk/deliverance/new_layout_template/log/
z3/deliverance/trunk/deliverance/new_layout_template/static/
z3/deliverance/trunk/deliverance/new_layout_template/static/rules/
z3/deliverance/trunk/deliverance/new_layout_template/static/rules/rules.xml
z3/deliverance/trunk/deliverance/new_layout_template/static/rules/standardrules.xml (contents, props changed)
z3/deliverance/trunk/deliverance/new_layout_template/static/theme.html
z3/deliverance/trunk/deliverance/new_layout_template/var/
z3/deliverance/trunk/deliverance/proxyconfig.py
z3/deliverance/trunk/deliverance/staticcommand.py
Modified:
z3/deliverance/trunk/ (props changed)
z3/deliverance/trunk/deliverance/proxycommand.py
z3/deliverance/trunk/setup.py
Log:
the start (not yet complete) of a static rendering command and a command to setup a new environment with all the necessary configuration to run the proxy
Added: z3/deliverance/trunk/deliverance/new_layout_template/etc/deliverance-proxy.ini
==============================================================================
--- (empty file)
+++ z3/deliverance/trunk/deliverance/new_layout_template/etc/deliverance-proxy.ini Mon Mar 19 18:12:05 2007
@@ -0,0 +1,36 @@
+[DEFAULT]
+## Uncomment this to show exceptions in the browser
+## (ideally there should be no exceptions)
+#debug = true
+## Set this to have any errors emailed to you, including problems
+## with the server
+#error_email = johndoe at example.com, janedoe at example.org
+
+[server:main]
+use = egg:Paste#http
+## This is the interface to bind to (0.0.0.0 means all interfaces):
+host = 0.0.0.0
+## And the port to serve on:
+port = 8000
+
+[app:main]
+use = egg:Deliverance#proxy
+## This is the site that is being wrapped:
+wrap_href = http://plone.org
+## These refer to the files in static/, and you probably don't need to
+## change these:
+theme_uri = /.deliverance/static/theme.html
+rule_uri = /.deliverance/static/rules/rules.xml
+mount /.deliverance/static = %(here)s/../static
+
+[exe]
+## These options control the daemon process
+command = serve
+## Note that %(here)s means the directory containing this config file
+pid_file = %(here)s/../var/deliverance-proxy.pid
+log_file = %(here)s/../log/deliverance-proxy.log
+daemon = true
+## The user and group options can be used if you start this as root
+## (the server will then change to this user/group):
+#user = username
+#group = groupname
Added: z3/deliverance/trunk/deliverance/new_layout_template/static/rules/rules.xml
==============================================================================
--- (empty file)
+++ z3/deliverance/trunk/deliverance/new_layout_template/static/rules/rules.xml Mon Mar 19 18:12:05 2007
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rules xmlns:xi="http://www.w3.org/2001/XInclude" xmlns="http://www.plone.org/deliverance" >
+ <xi:include href="standardrules.xml" />
+
+ <copy theme="//div[@id='content']" content="//*[@id='portal-columns']" />
+</rules>
Added: z3/deliverance/trunk/deliverance/new_layout_template/static/rules/standardrules.xml
==============================================================================
--- (empty file)
+++ z3/deliverance/trunk/deliverance/new_layout_template/static/rules/standardrules.xml Mon Mar 19 18:12:05 2007
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rules xmlns:xi="http://www.w3.org/2001/XInclude" xmlns="http://www.plone.org/deliverance">
+ <prepend theme="//head" content="//head/link" nocontent="ignore" />
+ <prepend theme="//head" content="//head/style" nocontent="ignore" />
+ <append theme="//head" content="//head/script" nocontent="ignore" />
+ <append theme="//head" content="//head/meta" nocontent="ignore" />
+ <append-or-replace theme="//head" content="//head/title"
+ nocontent="ignore" />
+</rules>
Added: z3/deliverance/trunk/deliverance/new_layout_template/static/theme.html
==============================================================================
--- (empty file)
+++ z3/deliverance/trunk/deliverance/new_layout_template/static/theme.html Mon Mar 19 18:12:05 2007
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
+<title>The Theme</title>
+</head>
+
+<body>
+<h1>A theme</h1>
+
+<div id="content">
+</div>
+
+
+<hr>
+<address></address>
+<!-- hhmts start -->Last modified: Fri Mar 16 09:33:37 CDT 2007 <!-- hhmts end -->
+</body> </html>
Modified: z3/deliverance/trunk/deliverance/proxycommand.py
==============================================================================
--- z3/deliverance/trunk/deliverance/proxycommand.py (original)
+++ z3/deliverance/trunk/deliverance/proxycommand.py Mon Mar 19 18:12:05 2007
@@ -1,3 +1,4 @@
+import os
import optparse
import pkg_resources
import sys
@@ -15,6 +16,10 @@
parser = optparse.OptionParser(
version=str(my_package),
usage="%%prog [OPTIONS]\n\n%s" % help)
+parser.add_option('--new-layout',
+ dest="new_layout",
+ metavar="DEST_DIR",
+ help="Create a self-contained layout for running the proxy server, with a pre-built theme, rules, and configuration file")
parser.add_option('-s', '--serve',
help="The interface to serve on (default 0.0.0.0:80)",
dest="serve",
@@ -63,6 +68,9 @@
if args is None:
args = sys.argv[1:]
options, args = parser.parse_args(args)
+ if options.new_layout:
+ make_new_layout(options.new_layout)
+ return
serve = strip('http://', options.serve)
if ':' not in serve:
serve += ':80'
@@ -103,3 +111,10 @@
print 'Exiting.'
sys.exit()
+def make_new_layout(dest_dir):
+ source = os.path.join(os.path.dirname(__file__), 'new_layout_template')
+ from paste.script import copydir
+ copydir.copy_dir(
+ source, dest_dir, {}, 1, simulate=False, interactive=True,
+ svn_add=False)
+
Added: z3/deliverance/trunk/deliverance/proxyconfig.py
==============================================================================
--- (empty file)
+++ z3/deliverance/trunk/deliverance/proxyconfig.py Mon Mar 19 18:12:05 2007
@@ -0,0 +1,34 @@
+"""
+This module contains the commands used in deliverance file layouts,
+where you have a deliverance-proxy-run and deliverance-proxy-ctl
+commands bound a specific configuration.
+"""
+
+import os
+import sys
+from paste.script import serve
+from paste.script import exe
+
+def proxy_run(script_filename):
+ """
+ Using script_filename, this determines the configuration and executes
+ ``paster serve``
+ """
+ config_filename = find_config(script_filename)
+ cmd = serve.ServeCommand('serve')
+ cmd.run([config_filename] + sys.argv[1:])
+
+def proxy_ctl(script_filename):
+ """
+ Using script_filename, this determines the configuration and executes
+ ``paster serve --daemon`` plus the given commands
+ """
+ config_filename = find_config(script_filename)
+ os.environ['_'] = config_filename
+ cmd = exe.ExeCommand('exe')
+ cmd.run([config_filename] + sys.argv[1:])
+
+def find_config(script_filename):
+ return os.path.join(
+ os.path.dirname(os.path.dirname(script_filename)),
+ 'etc', 'deliverance-proxy.ini')
Added: z3/deliverance/trunk/deliverance/staticcommand.py
==============================================================================
--- (empty file)
+++ z3/deliverance/trunk/deliverance/staticcommand.py Mon Mar 19 18:12:05 2007
@@ -0,0 +1,136 @@
+"""
+Command for rendering a set of static files to another set of static
+files. Not yet complete.
+"""
+
+import optparse
+import sys
+import os
+import re
+import urllib
+import cgi
+import pkg_resources
+
+my_package = pkg_resources.get_distribution('Deliverance')
+
+scheme_re = re.compile(r'^[a-z][a-z]+:', re.I)
+drive_re = re.compile(r'^[a-z]:', re.I)
+
+help = """\
+Render the FILES (or directories) given the THEME and RULES
+(or a default set of rules generated by the rule-* options)"""
+
+parser = optparse.OptionParser(
+ version=str(my_package),
+ usage="%%prog [OPTIONS] INPUT_DIR OUTPUT_DIR\n\n%s" % help)
+parser.add_option('-v', '--verbose',
+ help="Be more verbose",
+ dest="verbose",
+ action="count")
+parser.add_option('-q', '--quiet',
+ help="Be more quiet",
+ dest="quiet",
+ action="count")
+parser.add_option('-t', '--theme',
+ help="The URI of the theme to use",
+ metavar="URI/FILE",
+ dest="theme")
+parser.add_option('-r', '--rule',
+ help="The URI of the ruleset to use",
+ metavar="URI/FILE",
+ dest="rule")
+parser.add_option('--rule-theme-body',
+ metavar="XPATH",
+ help="If no rules provided, use this XPath expression to locate the body",
+ dest="theme_body_xpath")
+parser.add_option('--rule-content-body',
+ metavar="XPATH",
+ help="If no rules provided, use this XPath expression to locate the content body")
+parser.add_option('--renderer',
+ dest="renderer",
+ metavar="NAME",
+ help="Select which renderer to use: 'py' or 'xslt'",
+ default='py')
+
+class BadCommand(Exception):
+ pass
+
+def run_command(options, args):
+ if len(args) < 2:
+ raise BadCommand(
+ "You must give a INPUT_DIR and OUTPUT_DIR argument")
+ elif len(args) > 2:
+ raise BadCommand(
+ "You can only give two arguments, INPUT_DIR and OUTPUT_DIR")
+ input_dir, output_dir = args
+ if not options.rule:
+ options.rule = make_rule(options)
+ else:
+ options.rule = make_uri(options.rule)
+ options.verbose += 1
+ options.verbose -= options.quiet
+ del options.quiet
+ if not options.theme:
+ raise BadCommand(
+ "You must give an argument for --theme")
+ options.theme = make_uri(options.theme)
+ loader = make_loader(input_dir, options.rule)
+ norm_input_dir = os.path.abspath(input_dir)
+ renderer = None
+ for fn in all_files(input_dir):
+ full_fn = os.path.abspath(fn)
+ assert full_fn.startswith(input_dir)
+ plain_fn = full_fn[len(input_dir):].lstrip(os.path.sep)
+ dest_fn = os.path.join(output_dir, plain_fn)
+ ext = os.path.splitext(fn)[1].lower()
+ if ext not in ('.html', '.xhtml'):
+ if options.verbose > 2:
+ print 'Copying %s' % fn
+ shutil.copy(fn, dest_fn)
+ continue
+ if options.verbose > 2:
+ print 'Rendering %s'
+ contents = transform_file(renderer, loader, fn)
+ f = open(dest_fn, 'wb')
+ f.write(contents)
+ f.close()
+
+
+def all_files(dir):
+ for dirpath, dirnames, filenames in os.walk(dir):
+ for filename in filenames:
+ yield os.path.join(dirpath, filename)
+
+def make_uri(maybe_uri):
+ """
+ Returns the argument as a URI. The argument may be a relative or
+ absolute file path, in which case it is turned into an absolute
+ file: URI.
+ """
+ if scheme_re.search(maybe_uri):
+ return maybe_uri
+ maybe_uri = os.path.abspath(maybe_uri)
+ if os.path.sep != '/':
+ maybe_uri = maybe_uri.replace(os.path.sep, '/')
+ maybe_uri = urllib.quote(maybe_uri)
+ if sys.platform == 'win32':
+ match = drive_re.search(maybe_uri)
+ if match:
+ maybe_uri = '/' + maybe_uri[:match.end()-1] + '|' + maybe_uri[match.end():]
+ return 'file://' + maybe_uri
+
+def main(args=None):
+ if args is None:
+ args = sys.argv[1:]
+ options, args = parser.parse_args(args)
+ try:
+ run_command(options, args)
+ except BadCommand, e:
+ print e
+ parser.print_help()
+ sys.exit(2)
+
+
+if __name__ == '__main__':
+ main()
+
Modified: z3/deliverance/trunk/setup.py
==============================================================================
--- z3/deliverance/trunk/setup.py (original)
+++ z3/deliverance/trunk/setup.py Mon Mar 19 18:12:05 2007
@@ -31,11 +31,15 @@
[paste.filter_app_factory]
main = deliverance.wsgimiddleware:make_filter
+ [paste.app_factory]
+ proxy = deliverance.proxyapp:make_proxy
+
[console_scripts]
deliverance-proxy = deliverance.proxycommand:main
deliverance-tests = deliverance.testrunner:main
deliverance-speed = deliverance.test_speed:main
deliverance-handtransform = deliverance.handtransform:main
+ deliverance-static = deliverance.staticcommand:main
""",
)
More information about the z3-checkins
mailing list