[Zope3-checkins] CVS: Zope/lib/python/ZConfig/scripts - zconfig:1.3.2.1
Fred L. Drake, Jr.
fred@zope.com
Thu, 23 Jan 2003 17:01:59 -0500
Update of /cvs-repository/Zope/lib/python/ZConfig/scripts
In directory cvs.zope.org:/tmp/cvs-serv32578/scripts
Added Files:
Tag: chrism-install-branch
zconfig
Log Message:
Merge from the ZConfig trunk.
=== Added File Zope/lib/python/ZConfig/scripts/zconfig ===
#! /usr/local/bin/python
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""zconfig: Script to check well-formedness of a configuration file.
Usage:
zconfig [options] [file...]
Options:
-h
--help Print this help text.
-s file
--schema file Use the schema in 'file' to validate the configuration.
Each file named on the command line is checked for syntactical errors
and schema conformance (when the schema is specified).
"""
import getopt
import sys
import ZConfig
import ZConfig.Context
import ZConfig.loader
def main():
loader = ClassicLoader()
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
for opt, arg in opts:
if opt in ("-h", "--help"):
usage(sys.stdout)
return 0
if opt in ("-s", "--schema"):
schema = ZConfig.loadSchema(arg)
loader = ZConfig.loader.ConfigLoader(schema)
if not args:
if sys.stdin.isatty():
print >>sys.stderr, "No configuration files specified."
usage(sys.stderr)
return 2
else:
# stdin is a pipe
args = ["-"]
errors = 0
for fn in args:
try:
if fn == "-":
loader.loadFile(sys.stdin)
else:
loader.loadURL(fn)
except ZConfig.ConfigurationError, e:
print >>sys.stderr, str(e)
errors += 1
if errors:
return 1
else:
return 0
def usage(fp):
print >>fp, __doc__
class ClassicLoader(ZConfig.Context.Context):
def loadResource(self, resource):
# create a temporary context since it's not reusable
context = ZConfig.Context.Context()
return context.loadResource(resource)
if __name__ == "__main__":
sys.exit(main())