[Checkins] SVN: zope.kgs/trunk/src/zope/kgs/ - Add verbose flag to site creation script.

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Jan 27 00:46:41 EST 2009


Log message for revision 95069:
  - Add verbose flag to site creation script.
  
  - Improved logger.
  
  - Fixed tests.
  
  - Added announcement and changelog attributes to KGS object.
  

Changed:
  U   zope.kgs/trunk/src/zope/kgs/README.txt
  U   zope.kgs/trunk/src/zope/kgs/kgs.py
  U   zope.kgs/trunk/src/zope/kgs/site.py

-=-
Modified: zope.kgs/trunk/src/zope/kgs/README.txt
===================================================================
--- zope.kgs/trunk/src/zope/kgs/README.txt	2009-01-27 05:31:02 UTC (rev 95068)
+++ zope.kgs/trunk/src/zope/kgs/README.txt	2009-01-27 05:46:41 UTC (rev 95069)
@@ -565,7 +565,6 @@
         </div>...
 
 
-
 The Site Generator
 ------------------
 
@@ -582,31 +581,20 @@
   >>> shutil.copy(cfgFileReal, cfgFileSite)
 
   >>> from zope.kgs import site
-  >>> site.main(['-s',siteDir])
+  >>> site.main(['-s', siteDir])
 
 Let's have a look at the generated files:
 
   >>> from pprint import pprint
   >>> pprint(sorted(os.listdir(siteDir)))
-    ['PIL',
-     'buildout-3.4.0b2.cfg',
-     'buildout.cfg',
-     'cf-timestamp',
-     'controlled-packages-3.4.0b2.cfg',
-     'controlled-packages.cfg',
-     'intro.html',
-     'links-3.4.0b2.html',
-     'links.html',
-     'minimal',
-     'minimal-3.4.0b2',
-     'resources',
-     'versions-3.4.0b2.cfg',
-     'versions.cfg',
-     'z3c.formdemo',
-     'zope.component',
-     'zope.interface']
+  ['3.4.0b2', 'cf-timestamp']
 
-  >>> sorted(os.listdir(os.path.join(siteDir, 'minimal')))
+  >>> sorted(os.listdir(os.path.join(siteDir, '3.4.0b2')))
+  ['PIL', 'buildout.cfg', 'controlled-packages.cfg', 'links.html',
+   'minimal', 'resources', 'versions.cfg', 'z3c.formdemo',
+   'zope.component', 'zope.interface']
+
+  >>> sorted(os.listdir(os.path.join(siteDir, '3.4.0b2', 'minimal')))
   ['PIL', 'index.html', 'z3c.formdemo', 'zope.component', 'zope.interface']
 
 If you try to generate the site again without changing the controlled packages
@@ -616,7 +604,8 @@
   >>> tsPath = os.path.join(siteDir, 'cf-timestamp')
 
   >>> beforeTimestamp = open(tsPath).read()
-  >>> site.main(['-s',siteDir])
+  >>> shutil.copy(cfgFileReal, cfgFileSite)
+  >>> site.main(['-s', siteDir])
   >>> afterTimestamp = open(tsPath).read()
 
   >>> beforeTimestamp == afterTimestamp

Modified: zope.kgs/trunk/src/zope/kgs/kgs.py
===================================================================
--- zope.kgs/trunk/src/zope/kgs/kgs.py	2009-01-27 05:31:02 UTC (rev 95068)
+++ zope.kgs/trunk/src/zope/kgs/kgs.py	2009-01-27 05:46:41 UTC (rev 95069)
@@ -70,7 +70,16 @@
     seen.pop()
     return result
 
+def _getAbsolutePath(section, basePath, name, default):
+    path = section.get(name, default)
+    if path:
+        if not os.path.isabs(path):
+            path = os.path.join(basePath, path)
+        if path and not os.path.exists(path):
+            path = None
+    return path
 
+
 class Package(object):
 
     def __init__(self, name, versions, tested):
@@ -98,20 +107,13 @@
         basePath = os.path.dirname(self.path)
         result = _open(basePath, self.path, [])
         if MAIN_SECTION in result:
-            self.name = result[MAIN_SECTION].get('name', self.name)
-            self.version = result[MAIN_SECTION].get('version', self.version)
-            self.changelog = result[MAIN_SECTION].get(
-                'changelog', self.changelog)
-            if not os.path.isabs(self.changelog):
-                self.changelog = os.path.join(basePath, self.changelog)
-            if not os.path.exists(self.changelog):
-                self.changelog = None
-            self.announcement = result[MAIN_SECTION].get(
-                'announcement', self.announcement)
-            if not os.path.isabs(self.announcement):
-                self.announcement = os.path.join(basePath, self.announcement)
-            if not os.path.exists(self.announcement):
-                self.announcement = None
+            section = result[MAIN_SECTION]
+            self.name = section.get('name', self.name)
+            self.version = section.get('version', self.version)
+            self.changelog = _getAbsolutePath(
+                section, basePath, 'changelog', self.changelog)
+            self.announcement = _getAbsolutePath(
+                section, basePath, 'announcement', self.announcement)
             del result[MAIN_SECTION]
         self.packages = []
         sections = result.keys()

Modified: zope.kgs/trunk/src/zope/kgs/site.py
===================================================================
--- zope.kgs/trunk/src/zope/kgs/site.py	2009-01-27 05:31:02 UTC (rev 95068)
+++ zope.kgs/trunk/src/zope/kgs/site.py	2009-01-27 05:46:41 UTC (rev 95069)
@@ -32,12 +32,19 @@
 TIMESTAMP_FILENAME = 'cf-timestamp'
 RESOURCES_PATH = os.path.join(os.path.dirname(__file__), 'templates','resources')
 
+formatter = logging.Formatter('%(levelname)s - %(message)s')
+handler = logging.StreamHandler(sys.stdout)
+handler.setFormatter(formatter)
+logger = logging.getLogger('info')
+logger.addHandler(handler)
+logger.setLevel(logging.ERROR)
+
 def generateSite(siteDir):
     # Create some important variables
     kgsPath = os.path.join(siteDir, 'controlled-packages.cfg')
     set = kgs.KGS(kgsPath)
     ver = set.version
-    logging.info(
+    logger.info(
         "Building site for version %s using config: %s" % (ver, kgsPath))
 
     timestampPath = os.path.join(siteDir, TIMESTAMP_FILENAME)
@@ -48,7 +55,7 @@
         last_update = float(open(timestampPath, 'r').read())
         last_modified = os.stat(kgsPath)[-2]
         if last_update > last_modified:
-            logging.info("Site is up to date.")
+            logger.info("Site is up to date.")
             return
 
     # Save the last generation date-time.
@@ -74,12 +81,12 @@
 
     # Create the buildout config file
     buildoutPath = os.path.join(versionDir, 'buildout.cfg')
-    logging.info("Generating buildout config: %s" % buildoutPath)
+    logger.info("Generating buildout config: %s" % buildoutPath)
     buildout.generateBuildout(kgsPath, buildoutPath)
 
     # Create a versions config file and version it
     versionsPath = os.path.join(versionDir, 'versions.cfg')
-    logging.info("Generating version config file: %s" % versionsPath)
+    logger.info("Generating version config file: %s" % versionsPath)
     version.generateVersions(kgsPath, versionsPath)
 
     # Create a links config file and version it
@@ -87,11 +94,11 @@
     link.generateLinks(kgsPath, linksPath)
 
     # Update the full index (which is assumed to live in the site directory)
-    logging.info("updating the index")
+    logger.info("updating the index")
     ppix.generatePackagePages(kgsPath, versionDir)
 
     # Update the minimal index
-    logging.info("updating the minimal index")
+    logger.info("updating the minimal index")
     midxDir = os.path.join(versionDir, 'minimal')
     if not os.path.exists(midxDir):
         os.mkdir(midxDir)
@@ -100,37 +107,39 @@
 
     # copy over the resource files
     resourcesDir = os.path.join(versionDir, 'resources')
-    logging.info("copying resource files to %s" % resourcesDir)
+    logger.info("copying resource files to %s" % resourcesDir)
     if os.path.exists(resourcesDir):
         shutil.rmtree(resourcesDir)
     shutil.copytree(RESOURCES_PATH, resourcesDir)
 
     # Update the intro page
-    #logging.info("updating the intro page")
+    logger.info("updating the intro page")
     #intro.main(['-d',versionDir])
 
-    logging.info("finished generating site.")
+    logger.info("finished generating site.")
 
 
 parser = optparse.OptionParser()
-parser.add_option("-v","--verbose", action="bool",
-                  type="string", dest="siteDir", metavar="DIR",
-                  help="The directory where the site should be generated")
+parser.add_option("-v","--verbose", action="store_true",
+                  dest="verbose", default=False,
+                  help="When specified, debug information is created.")
 parser.add_option("-s","--site-dir", action="store",
                   type="string", dest="siteDir", metavar="DIR",
                   help="The directory where the site should be generated")
 
 def main(args=None):
-    logging.basicConfig(level=logging.INFO)
-
     if args is None:
         args = sys.argv[1:]
     if not args:
         args = ['-h']
 
     options, args = parser.parse_args(args)
+
+    if options.verbose:
+        logger.setLevel(logging.INFO)
+
     if not options.siteDir:
-        logging.error("You must specify the site directory with the -s option.")
+        logger.error("You must specify the site directory with the -s option.")
         sys.exit(1)
 
     siteDir = os.path.abspath(options.siteDir)



More information about the Checkins mailing list