[Checkins] SVN: ZConfig/branches/haufe-legacy-integration/ - Launchpad #373583: ZODBMountPoint - fixed broken mount support and
Andreas Jung
andreas at andreas-jung.com
Sun May 10 12:09:52 EDT 2009
Log message for revision 99827:
- Launchpad #373583: ZODBMountPoint - fixed broken mount support and
extended the test suite.
Changed:
U ZConfig/branches/haufe-legacy-integration/NEWS.txt
U ZConfig/branches/haufe-legacy-integration/ZConfig/cfgparser.py
U ZConfig/branches/haufe-legacy-integration/ZConfig/tests/test_config.py
-=-
Modified: ZConfig/branches/haufe-legacy-integration/NEWS.txt
===================================================================
--- ZConfig/branches/haufe-legacy-integration/NEWS.txt 2009-05-10 16:05:33 UTC (rev 99826)
+++ ZConfig/branches/haufe-legacy-integration/NEWS.txt 2009-05-10 16:09:52 UTC (rev 99827)
@@ -2,6 +2,11 @@
Change History for ZConfig
==========================
+ZConfig 2.7.0 (unreleased)
+--------------------------
+
+- Launchpad #373614: new ``includeGlobPattern`` directive
+
ZConfig 2.6.1 (2008/12/05)
--------------------------
Modified: ZConfig/branches/haufe-legacy-integration/ZConfig/cfgparser.py
===================================================================
--- ZConfig/branches/haufe-legacy-integration/ZConfig/cfgparser.py 2009-05-10 16:05:33 UTC (rev 99826)
+++ ZConfig/branches/haufe-legacy-integration/ZConfig/cfgparser.py 2009-05-10 16:09:52 UTC (rev 99827)
@@ -131,7 +131,9 @@
if not m:
self.error("missing or unrecognized directive")
name, arg = m.group('key', 'value')
- if name not in ("define", "import", "include"):
+ if name not in ("define", "import", "include",
+ "redefine", "includeGlobPattern"
+ ):
self.error("unknown directive: " + `name`)
if not arg:
self.error("missing argument to %%%s directive" % name)
@@ -141,6 +143,10 @@
self.handle_define(section, arg)
elif name == "import":
self.handle_import(section, arg)
+ elif name == "redefine":
+ self.handle_define(section, arg, False)
+ elif name == "includeGlobPattern":
+ self.handle_includeGlobPattern(section, arg)
else:
assert 0, "unexpected directive for " + `"%" + rest`
@@ -153,18 +159,51 @@
newurl = ZConfig.url.urljoin(self.url, rest)
self.context.includeConfiguration(section, newurl, self.defines)
- def handle_define(self, section, rest):
+ def handle_define(self, section, rest, prevent_override=True):
parts = rest.split(None, 1)
defname = self._normalize_case(parts[0])
defvalue = ''
if len(parts) == 2:
defvalue = parts[1]
- if self.defines.has_key(defname):
+ if prevent_override and self.defines.has_key(defname):
self.error("cannot redefine " + `defname`)
if not isname(defname):
self.error("not a substitution legal name: " + `defname`)
self.defines[defname] = self.replace(defvalue)
+ def handle_includeGlobPattern(self, section, rest):
+ '''import any file identified by the glob pattern *rest* (the directive argument).
+
+ If *rest* is not absolute, then it is resolved relative to
+ the current baseurl. Note, that this url must be a file Url in
+ this case.
+ '''
+ from os.path import isabs, join, sep, islink, exists
+ from urllib import url2pathname
+ from glob import glob
+ rest = self.replace (rest.strip()); url = self.url
+ if isabs(rest) or url is None: pattern = rest
+ elif not url.startswith('file:///'):
+ self.error('relative glob pattern requires a file url as base')
+ else:
+ path = sep.join(url2pathname(url[5:]).split(sep)[:-1])
+ pattern = join(path, rest)
+ for name in glob(pattern):
+ # Note: this "try: ... except: ..." is highly "iDesk" specific:
+ # "iDesk" makes extensive use of symbolic links pointing
+ # into the production environment. During the production
+ # the link destination can be missing.
+ # The "try: ... except: ..." prevents such broken links
+ # from interference with the startup.
+ try:
+ self.context.includeConfiguration(section, name, self.defines)
+ except ZConfig.ConfigurationError:
+ # If we can't open the file it may be an invalid symbolic link
+ # In this case we just print a warning and continue
+ if not islink (name) or exists (name):
+ raise
+ self.warn ("Invalid symbolic link: %s" % name)
+
def replace(self, text):
try:
return substitute(text, self.defines)
Modified: ZConfig/branches/haufe-legacy-integration/ZConfig/tests/test_config.py
===================================================================
--- ZConfig/branches/haufe-legacy-integration/ZConfig/tests/test_config.py 2009-05-10 16:05:33 UTC (rev 99826)
+++ ZConfig/branches/haufe-legacy-integration/ZConfig/tests/test_config.py 2009-05-10 16:09:52 UTC (rev 99827)
@@ -108,6 +108,11 @@
self.assertEqual(conf.var3, "value3")
self.assertEqual(conf.var4, "value")
+ def test_includeGlobPattern(self):
+ conf = self.load("glob_pattern.conf")
+ self.assertEqual(conf.var1, "a")
+ self.assertEqual(conf.var2, "b")
+
def test_includes_with_defines(self):
self.schema = ZConfig.loadSchemaFile(StringIO.StringIO("""\
<schema>
@@ -135,6 +140,19 @@
self.assertRaises(ZConfig.ConfigurationSyntaxError,
self.loadtext, "%define a value\n%define a value\n")
+ def test_redefine(self):
+ # a "redefine" is allowed to define
+ conf = self.loadtext("%redefine option v\n"
+ "getname $option\n"
+ )
+ self.assertEqual(conf.getname, "v")
+ # a "redefine" is allowed to override a previous definition
+ conf = self.loadtext("%define reoption v\n%redefine reoption w\n"
+ "getname $reoption\n"
+ )
+ self.assertEqual(conf.getname, "w")
+
+
def test_fragment_ident_disallowed(self):
self.assertRaises(ZConfig.ConfigurationError,
self.load, "simplesections.conf#another")
More information about the Checkins
mailing list