[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools - config.py:1.6
Fred L. Drake, Jr.
fred at zope.com
Tue Mar 30 18:50:25 EST 2004
Update of /cvs-repository/Packages/zpkgtools/zpkgtools
In directory cvs.zope.org:/tmp/cvs-serv29956/zpkgtools
Modified Files:
config.py
Log Message:
- added Configuration.loadStream() to support loading from a stream,
to make it easier to embed test data in the unit tests
- moved some of the test data to strings
- added configuration option to control whether support code should be
included in the resulting package, and enough command-line support
to suppress the configuration
=== Packages/zpkgtools/zpkgtools/config.py 1.5 => 1.6 ===
--- Packages/zpkgtools/zpkgtools/config.py:1.5 Tue Mar 16 12:00:01 2004
+++ Packages/zpkgtools/zpkgtools/config.py Tue Mar 30 18:49:54 2004
@@ -26,13 +26,26 @@
from zpkgtools import locationmap
+TRUE_STRINGS =("yes", "true", "on")
+FALSE_STRINGS = ("no", "false", "off")
+
+def boolean(string):
+ s = string.lower()
+ if s in FALSE_STRINGS:
+ return False
+ if s in TRUE_STRINGS:
+ return True
+ raise ValueError("unknown boolean value: %r" % string)
+
def non_empty_string(string):
if not string:
raise ValueError("value cannot be empty")
return string
SCHEMA = cfgparser.Schema(
- ({"resource-map": non_empty_string}, [], None),
+ ({"resource-map": non_empty_string,
+ "include-support-code": boolean,
+ }, [], None),
)
@@ -41,27 +54,37 @@
def __init__(self):
self.location_maps = []
- self.locations = None
+ self.locations = locationmap.LocationMap()
+ self.include_support_code = True
def finalize(self):
for loc in self.location_maps:
self.locations = locationmap.fromPathOrUrl(loc,
mapping=self.locations)
- if self.locations is None:
- self.locations = locationmap.LocationMap()
def loadPath(self, path):
basedir = os.path.dirname(path)
f = open(path, "rU")
+ try:
+ self.loadStream(f, path, basedir)
+ finally:
+ f.close()
+
+ def loadStream(self, f, path, basedir):
p = cfgparser.Parser(f, path, SCHEMA)
cf = p.load()
for value in cf.resource_map:
type, rest = urllib.splittype(value)
- if not type:
+ if basedir and not type:
# local path references are relative to the file
# we're loading
value = os.path.join(basedir, value)
self.location_maps.append(value)
+ if len(cf.include_support_code) > 1:
+ raise cfgparser.ConfigurationError(
+ "include-support-code can be specified at most once")
+ if cf.include_support_code:
+ self.include_support_code = cf.include_support_code[0]
def defaultConfigurationPath():
More information about the Zope-CVS
mailing list