[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools - config.py:1.2
Fred L. Drake, Jr.
fred at zope.com
Thu Mar 11 09:56:21 EST 2004
Update of /cvs-repository/Packages/zpkgtools/zpkgtools
In directory cvs.zope.org:/tmp/cvs-serv27620
Modified Files:
config.py
Log Message:
- use the new ZConfig-lite parser
- tests changed to reflect change in what exceptions get raised
=== Packages/zpkgtools/zpkgtools/config.py 1.1 => 1.2 ===
--- Packages/zpkgtools/zpkgtools/config.py:1.1 Wed Mar 10 16:27:35 2004
+++ Packages/zpkgtools/zpkgtools/config.py Thu Mar 11 09:55:50 2004
@@ -22,9 +22,20 @@
import os
import urllib
+from zpkgtools import cfgparser
from zpkgtools import locationmap
+def non_empty_string(string):
+ if not string:
+ raise ValueError("value cannot be empty")
+ return string
+
+SCHEMA = cfgparser.Schema(
+ ({"repository-map": non_empty_string}, [], None),
+ )
+
+
class Configuration:
"""Configuration settings for zpkg."""
@@ -48,30 +59,17 @@
def loadPath(self, path):
basedir = os.path.dirname(path)
f = open(path, "rU")
- for line in f:
- line = line.strip()
- if line[:1] in ("", "#"):
- continue
- parts = line.split(None, 1)
- key = parts[0]
- if len(parts) == 2:
- # The replace is needed to ensure that we're close to
- # ZConfig syntax; we should check also for single
- # dollar signs and forbid them.
- value = parts[1].replace("$$", "$")
- else:
- value = None
- if key == "repository-map":
- if value is None:
- raise ValueError("'repository-map' requires a location")
- type, rest = urllib.splittype(value)
- if not type:
- # local path references are relative to the file
- # we're loading
- value = os.path.join(basedir, value)
- self.location_maps.append(value)
- else:
- raise ValueError("unknown configuration setting: %r" % key)
+ p = cfgparser.Parser(f, path, SCHEMA)
+ cf = p.load()
+ for value in cf.repository_map:
+ if value is None:
+ raise ValueError("'repository-map' requires a location")
+ type, rest = urllib.splittype(value)
+ if not type:
+ # local path references are relative to the file
+ # we're loading
+ value = os.path.join(basedir, value)
+ self.location_maps.append(value)
def defaultConfigurationPath():
More information about the Zope-CVS
mailing list