[Checkins] SVN: zope.kgs/trunk/src/zope/kgs/ - Allow site to be generated, even if no controlled-packages.cfg file is

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Jan 29 02:32:29 EST 2009


Log message for revision 95374:
  - Allow site to be generated, even if no controlled-packages.cfg file is 
    found. This way the command can safely run in a cron job.
  
  - Add -q/--quiet option that will suppress all messages, except fatal 
    ones.
  
  - Added -w/--website-only option that will only re-generate the Website 
    pages. Very useful when testing and manipulating templates.
  

Changed:
  U   zope.kgs/trunk/src/zope/kgs/README.txt
  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-29 07:17:59 UTC (rev 95373)
+++ zope.kgs/trunk/src/zope/kgs/README.txt	2009-01-29 07:32:29 UTC (rev 95374)
@@ -530,31 +530,22 @@
 
   >>> from pprint import pprint
   >>> pprint(sorted(os.listdir(siteDir)))
-  ['3.4.0b2', 'cf-timestamp', 'index.html', 'intro.html', 'resources']
+  ['3.4.0b2', 'index.html', 'intro.html', 'resources']
 
   >>> sorted(os.listdir(os.path.join(siteDir, '3.4.0b2')))
   ['ANNOUNCEMENT.html', 'CHANGES.html',
-   'buildout.cfg', 'controlled-packages.cfg', 'index',
+   'buildout.cfg', 'controlled-packages.cfg', 'index', 'index.html',
    'links.html', 'minimal', 'versions.cfg']
 
   >>> 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
-config file, it will simply return, because it checks the timestamp from the
-previous generation:
+If you try to generate the site again without adding the controlled packages
+config file to the site directory again, it will simply return:
 
-  >>> tsPath = os.path.join(siteDir, 'cf-timestamp')
-
-  >>> beforeTimestamp = open(tsPath).read()
-  >>> shutil.copy(cfgFileReal, cfgFileSite)
   >>> site.main(['-s', siteDir])
-  >>> afterTimestamp = open(tsPath).read()
 
-  >>> beforeTimestamp == afterTimestamp
-  True
 
-
 Basic Parser API
 ----------------
 

Modified: zope.kgs/trunk/src/zope/kgs/site.py
===================================================================
--- zope.kgs/trunk/src/zope/kgs/site.py	2009-01-29 07:17:59 UTC (rev 95373)
+++ zope.kgs/trunk/src/zope/kgs/site.py	2009-01-29 07:32:29 UTC (rev 95374)
@@ -112,36 +112,18 @@
 def generateSite(siteDir, templateDir, force=False, offline=False):
     # Create some important variables
     kgsPath = os.path.join(siteDir, 'controlled-packages.cfg')
+
+    # If the `controlled-packages.cfg` file is not found,
     if not os.path.exists(kgsPath):
-        logger.error("The site directory specified does not "
-                     "have a controlled-packages.cfg file.")
+        logger.info("The site is up-to-date. No new file "
+                    "`controlled-packages.cfg` was found.")
         return
+
     set = kgs.KGS(kgsPath)
     ver = set.version
     logger.info(
         "Building site for version %s using config: %s" % (ver, kgsPath))
 
-    timestampPath = os.path.join(siteDir, TIMESTAMP_FILENAME)
-
-    # If there have been no changes in the file since the last generation,
-    # simple do not do anything.
-    if os.path.exists(timestampPath):
-        last_update = float(open(timestampPath, 'r').read())
-        last_modified = os.stat(kgsPath)[-2]
-        if last_update > last_modified:
-            if not force:
-                logger.info("Site is up to date.  Use --force "
-                            "on the command line to force a rebuild.")
-                return
-            else:
-                logger.info("Site is up to date, but a rebuild has been "
-                            "forced.")
-
-    # Save the last generation date-time.
-    # Note: We want to do this operation first, since it might take longer to
-    # generate the site than the scheduler's wait time.
-    open(timestampPath, 'w').write(str(time.time()))
-
     # Create a directory for the new version
     versionDir = os.path.join(siteDir, ver)
     if os.path.exists(versionDir):
@@ -215,6 +197,10 @@
 
 parser = optparse.OptionParser()
 parser.add_option(
+    "-q","--quiet", action="store_true",
+    dest="quiet", default=False,
+    help="When specified, no messages are displayed.")
+parser.add_option(
     "-v","--verbose", action="store_true",
     dest="verbose", default=False,
     help="When specified, debug information is created.")
@@ -228,11 +214,17 @@
     default=os.path.join(os.path.dirname(__file__), 'templates'),
     help="The directory where the site templates are located.")
 parser.add_option(
+    "-w","--website-only", action="store_true",
+    dest="websiteOnly", default=False,
+    help="When specified, only the Web site is (re-)generated.")
+parser.add_option(
     "-f","--force", action="store_true", dest="force", default=False,
-    help="Force the site to rebuild even if it is already at the latest version.")
+    help=("Force the site to rebuild even if it is already at the "
+          "latest version."))
 parser.add_option(
     "-o","--offline", action="store_true", dest="offlineMode", default=False,
-    help="Run in offline mode.  Doesn't really do much, good for developing templates.")
+    help=("Run in offline mode.  Doesn't really do much, good for "
+          "developing templates."))
 
 def main(args=None):
     if args is None:
@@ -244,6 +236,8 @@
 
     if options.verbose:
         logger.setLevel(logging.INFO)
+    if options.quiet:
+        logger.setLevel(logging.FATAL)
 
     if not options.siteDir:
         logger.error("You must specify the site directory with the -s option.")
@@ -251,4 +245,12 @@
 
     siteDir = os.path.abspath(options.siteDir)
     templateDir = os.path.abspath(options.templateDir)
-    generateSite(siteDir, templateDir, force=options.force, offline=options.offlineMode)
+
+    if options.websiteOnly:
+        # Generate Web Site
+        logger.info("Generating Web Site")
+        template.generateSite(templateDir, siteDir, generateData(siteDir))
+        logger.info("finished generating site.")
+    else:
+        generateSite(siteDir, templateDir, force=options.force,
+                     offline=options.offlineMode)



More information about the Checkins mailing list