[Zope-CVS] CVS: Packages/zpkgtools/zpkgtools - package.py:1.15
Fred L. Drake, Jr.
fred at zope.com
Tue May 11 16:10:15 EDT 2004
Update of /cvs-repository/Packages/zpkgtools/zpkgtools
In directory cvs.zope.org:/tmp/cvs-serv18307/zpkgtools
Modified Files:
package.py
Log Message:
add a <data-files> section type for SETUP.cfg files; this allows installation
arbitrary files using the "normal" distutils notion of data files
(not completely hooked up yet)
=== Packages/zpkgtools/zpkgtools/package.py 1.14 => 1.15 ===
--- Packages/zpkgtools/zpkgtools/package.py:1.14 Wed May 5 16:55:34 2004
+++ Packages/zpkgtools/zpkgtools/package.py Tue May 11 16:09:44 2004
@@ -51,7 +51,6 @@
:Variables:
- `PACKAGE_CONF`: Name of the package information file.
- - `SCHEMA`: Schema for the package information file.
:Groups:
- `Public interface`: loadCollectionInfo loadPackageInfo
@@ -74,9 +73,6 @@
PACKAGE_CONF = "SETUP.cfg"
-# SCHEMA is defined at the end of the module to allow referenced
-# functions to be defined first.
-
def loadPackageInfo(pkgname, directory, reldir):
"""Load package information for a Python package.
@@ -143,7 +139,7 @@
url = "<no file>"
f = StringIO("")
try:
- p = cfgparser.Parser(f, url, SCHEMA)
+ p = cfgparser.Parser(f, url, PackageSchema(directory, reldir))
pkginfo = p.load()
finally:
f.close()
@@ -379,12 +375,80 @@
return p
-SCHEMA = cfgparser.Schema(
- ({"script": path_ref, "documentation": path_ref, "header": path_ref},
- ["extension"], None),
- {"extension": ({"source": path_ref, "depends-on": path_ref,
- "define" : cpp_definition, "undefine": cpp_names,
- "language": str,
- },
- (), extension),
- })
+class PackageSchema(cfgparser.Schema):
+ """Schema implementation with a <data-files> section type.
+
+ The <data-files> sections have keys that are glob-expanded (based
+ on information passed to the constructor) and combined into a
+ single .data_files member on the resulting package information
+ object. The value of the .data_files attribute is suitable for
+ passing to the distutils.core.setup() function.
+
+ """
+
+ def __init__(self, directory, reldir):
+ cfgparser.Schema.__init__(
+ self,
+ ({"script": path_ref,
+ "documentation": path_ref,
+ "header": path_ref},
+ ["extension"], None),
+ {"extension": ({"source": path_ref, "depends-on": path_ref,
+ "define" : cpp_definition, "undefine": cpp_names,
+ "language": str,
+ },
+ (), extension),
+ }
+ )
+ self.__cf = None
+ self.__datafiles = None
+ self.__directory = directory
+ self.__reldir = reldir
+
+ def getConfiguration(self):
+ assert self.__cf is None
+ self.__cf = cfgparser.Schema.getConfiguration(self)
+ self.__cf.data_files = []
+ return self.__cf
+
+ def startSection(self, parent, typename, name):
+ if self.__datafiles is not None:
+ raise cfgparser.ConfigurationError(
+ "can't nest another section inside <data-files> section")
+ if typename == "data-files":
+ if not name:
+ raise cfgparser.ConfigurationError(
+ "<data-files> section must have a name")
+ normname = posixpath.normpath(name)
+ for target, files in self.__cf.data_files:
+ if target == normname:
+ raise cfgparser.ConfigurationError(
+ "can't have two sections of the same name:"
+ " <data-files %s>" % name)
+ self.__datafiles = []
+ self.__cf.data_files.append((normname, self.__datafiles))
+ # The return value is passed around, but that's it
+ return ()
+ else:
+ return cfgparser.Schema.startSection(self, parent, typename, name)
+
+ def endSection(self, parent, typename, name, child):
+ if self.__datafiles is None:
+ cfgparser.Schema.endSection(self, parent, typename, name, child)
+ else:
+ # mutate self.__datafiles since the reference from
+ # self.__cf.data_files is what's actually used
+ self.__datafiles[:] = expand_globs(self.__directory,
+ self.__reldir,
+ self.__datafiles)
+ self.__datafiles = None
+
+ def addValue(self, section, key, value):
+ if self.__datafiles is not None:
+ if value:
+ raise cfgparser.ConfigurationError(
+ "each entry in a <data-files> section must be"
+ " a single glob pattern")
+ self.__datafiles.append(key)
+ else:
+ cfgparser.Schema.addValue(self, section, key, value)
More information about the Zope-CVS
mailing list