[Checkins] SVN: zope.kgs/trunk/src/zope/kgs/ Get basic Web Site generator working.

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Jan 27 02:38:58 EST 2009


Log message for revision 95076:
  Get basic Web Site generator working.
  

Changed:
  U   zope.kgs/trunk/src/zope/kgs/README.txt
  U   zope.kgs/trunk/src/zope/kgs/site.py
  U   zope.kgs/trunk/src/zope/kgs/template.py
  A   zope.kgs/trunk/src/zope/kgs/templates/index.html
  A   zope.kgs/trunk/src/zope/kgs/templates/menu.pt

-=-
Modified: zope.kgs/trunk/src/zope/kgs/README.txt
===================================================================
--- zope.kgs/trunk/src/zope/kgs/README.txt	2009-01-27 07:30:29 UTC (rev 95075)
+++ zope.kgs/trunk/src/zope/kgs/README.txt	2009-01-27 07:38:58 UTC (rev 95076)
@@ -19,6 +19,7 @@
   ... [KGS]
   ... name = zope-dev
   ... version = 1.2.0
+  ... changelog = CHANGES.txt
   ...
   ... [packageA]
   ... versions = 1.0.0

Modified: zope.kgs/trunk/src/zope/kgs/site.py
===================================================================
--- zope.kgs/trunk/src/zope/kgs/site.py	2009-01-27 07:30:29 UTC (rev 95075)
+++ zope.kgs/trunk/src/zope/kgs/site.py	2009-01-27 07:38:58 UTC (rev 95076)
@@ -27,7 +27,7 @@
 import shutil
 import sys
 import time
-from zope.kgs import version, buildout, ppix, link, intro, kgs
+from zope.kgs import version, buildout, ppix, link, intro, kgs, template
 
 TIMESTAMP_FILENAME = 'cf-timestamp'
 
@@ -42,7 +42,8 @@
     # Create some important variables
     kgsPath = os.path.join(siteDir, 'controlled-packages.cfg')
     if not os.path.exists(kgsPath):
-        logger.error("The site directory specified does not have a controlled-packages.cfg file.")
+        logger.error("The site directory specified does not "
+                     "have a controlled-packages.cfg file.")
         return
     set = kgs.KGS(kgsPath)
     ver = set.version
@@ -76,6 +77,8 @@
             logger.info('Recreating directory %s.' %versionDir)
             shutil.rmtree(versionDir)
             os.mkdir(versionDir)
+    else:
+        os.mkdir(versionDir)
 
     # Copy the KGS config file, changelog and announcement file to the version
     # directory
@@ -116,16 +119,10 @@
     ppix.generatePackagePages(kgsPath, midxDir)
     ppix.generateIndexPage(kgsPath, midxDir)
 
-    # copy over the resource files
-    resourcesDir = os.path.join(versionDir, 'resources')
-    logger.info("copying resource files to %s" % resourcesDir)
-    if os.path.exists(resourcesDir):
-        shutil.rmtree(resourcesDir)
-    shutil.copytree(os.path.join(templateDir, 'resources'), resourcesDir)
-
-    # Update the intro page
-    logger.info("updating the intro page")
+    # Generate Web Site
+    logger.info("Generating Web Site")
     #intro.main(['-d',versionDir])
+    template.generateSite(templateDir, siteDir, None)
 
     logger.info("finished generating site.")
 
@@ -145,7 +142,7 @@
     default=os.path.join(os.path.dirname(__file__), 'templates'),
     help="The directory where the site templates are located.")
 parser.add_option(
-    "-f","--force", action="store_true", dest="force",
+    "-f","--force", action="store_true", dest="force", default=False,
     help="For the site to rebuild even if it is already at the latest version.")
 
 def main(args=None):

Modified: zope.kgs/trunk/src/zope/kgs/template.py
===================================================================
--- zope.kgs/trunk/src/zope/kgs/template.py	2009-01-27 07:30:29 UTC (rev 95075)
+++ zope.kgs/trunk/src/zope/kgs/template.py	2009-01-27 07:38:58 UTC (rev 95076)
@@ -13,16 +13,34 @@
 ##############################################################################
 """Helper components for the Web site generation.
 """
+import os
+import shutil
 import zope.pagetemplate.pagetemplatefile
 
+class Template(zope.pagetemplate.pagetemplatefile.PageTemplateFile):
+
+    def __init__(self, path, templates):
+        super(Template, self).__init__(path)
+        self.templates = templates
+
+    def pt_getContext(self, args=(), options=None, **ignore):
+        rval = {'args': args,
+                'nothing': None,
+                'self': self,
+                'templates': self.templates
+                }
+        rval.update(self.pt_getEngine().getBaseNames())
+        return rval
+
+
 class FileContext(object):
 
-    def __init__(path, root):
+    def __init__(self, path, root):
         self.path = path
         self.root = root
 
     def __call__(self):
-        pt = Template(self.path, root)
+        pt = Template(self.path, self.root)
         return pt()
 
 
@@ -39,17 +57,21 @@
         return None
 
 
-class Template(zope.pagetemplate.pagetemplatefile.PageTemplateFile):
-
-    def __init__(self, path, templates):
-        super(Template, self).__init__(path)
-        self.templates = templates
-
-    def pt_getContext(self, args=(), options=None, **ignore):
-        rval = {'args': args,
-                'nothing': None,
-                'self': self,
-                'templates': self.templates
-                }
-        rval.update(self.pt_getEngine().getBaseNames())
-        return rval
+def generateSite(src, dst, data, templates=None):
+    if templates is None:
+        templates = DirectoryContext(src)
+    for filename in os.listdir(src):
+        srcPath = os.path.join(src, filename)
+        dstPath = os.path.join(dst, filename)
+        if filename.startswith('.'):
+            continue
+        elif srcPath.endswith('.pt'):
+            continue
+        elif os.path.isdir(srcPath):
+            os.mkdir(dstPath)
+            generateSite(srcPath, dstPath, data, templates)
+        elif srcPath.endswith('.html'):
+            data = Template(srcPath, templates)()
+            open(dstPath, 'w').write(data)
+        else:
+            shutil.copyfile(srcPath, dstPath)

Added: zope.kgs/trunk/src/zope/kgs/templates/index.html
===================================================================
--- zope.kgs/trunk/src/zope/kgs/templates/index.html	                        (rev 0)
+++ zope.kgs/trunk/src/zope/kgs/templates/index.html	2009-01-27 07:38:58 UTC (rev 95076)
@@ -0,0 +1,9 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+  <head>
+    <title>Introduction to the KGS</title>
+  </head>
+  <body>
+    <div tal:content="structure templates/menu.pt" />
+  </body>
+</html>

Added: zope.kgs/trunk/src/zope/kgs/templates/menu.pt
===================================================================
--- zope.kgs/trunk/src/zope/kgs/templates/menu.pt	                        (rev 0)
+++ zope.kgs/trunk/src/zope/kgs/templates/menu.pt	2009-01-27 07:38:58 UTC (rev 95076)
@@ -0,0 +1 @@
+<div>Menu</div>


Property changes on: zope.kgs/trunk/src/zope/kgs/templates/menu.pt
___________________________________________________________________
Added: svn:eol-style
   + native



More information about the Checkins mailing list