[Zodb-checkins] CVS: StandaloneZConfig/ZConfig/scripts - zconfig:1.8
Fred L. Drake, Jr.
fred at zope.com
Tue Jan 27 16:47:58 EST 2004
Update of /cvs-repository/StandaloneZConfig/ZConfig/scripts
In directory cvs.zope.org:/tmp/cvs-serv19315
Modified Files:
zconfig
Log Message:
convert from getopt to optparse; this is substantially simpler!
=== StandaloneZConfig/ZConfig/scripts/zconfig 1.7 => 1.8 ===
--- StandaloneZConfig/ZConfig/scripts/zconfig:1.7 Tue Jan 27 13:26:41 2004
+++ StandaloneZConfig/ZConfig/scripts/zconfig Tue Jan 27 16:47:55 2004
@@ -36,47 +36,31 @@
"""
-import getopt
+import optparse
import sys
import ZConfig
-import ZConfig.loader
def main():
- loader = None
- schema = None
- try:
- opts, args = getopt.getopt(sys.argv[1:], "hs:", ["help", "schema="])
- except getopt.GetoptError, e:
- print >>sys.stderr, e
- usage(sys.stderr)
- return 2
+ optparser = optparse.OptionParser(
+ usage="usage: %prog [-s FILE] [file ...]")
+ optparser.add_option(
+ "-s", "--schema", dest="schema",
+ help="use the schema in FILE (can be a URL)",
+ metavar="FILE")
+ options, args = optparser.parse_args()
- for opt, arg in opts:
- if opt in ("-h", "--help"):
- usage(sys.stdout)
- return 0
- if opt in ("-s", "--schema"):
- try:
- schema = ZConfig.loadSchema(arg)
- except ZConfig.SchemaError, e:
- print >>sys.stderr, e
- return 1
- loader = ZConfig.loader.ConfigLoader(schema)
-
- if loader is None:
+ if not options.schema:
print >>sys.stderr, "No schema specified, but is required."
usage(sys.stderr)
return 2
+ schema = ZConfig.loadSchema(options.schema)
if not args:
if sys.stdin.isatty():
- if schema:
- return 0
- print >>sys.stderr, "No configuration files specified."
- usage(sys.stderr)
- return 2
+ # just checking the schema
+ return 0
else:
# stdin is a pipe
args = ["-"]
@@ -85,9 +69,9 @@
for fn in args:
try:
if fn == "-":
- loader.loadFile(sys.stdin)
+ ZConfig.loadConfigFile(schema, sys.stdin)
else:
- loader.loadURL(fn)
+ ZConfig.loadConfig(schema, fn)
except ZConfig.ConfigurationError, e:
print >>sys.stderr, str(e)
errors += 1
More information about the Zodb-checkins
mailing list