[Checkins] SVN: keas.build/trunk/ Check dependent configs, upload all to the server.

Adam Groszer agroszer at gmail.com
Wed Dec 9 03:39:57 EST 2009


Log message for revision 106314:
  Check dependent configs, upload all to the server.

Changed:
  U   keas.build/trunk/CHANGES.txt
  U   keas.build/trunk/src/keas/build/build.py
  U   keas.build/trunk/src/keas/build/index.txt

-=-
Modified: keas.build/trunk/CHANGES.txt
===================================================================
--- keas.build/trunk/CHANGES.txt	2009-12-09 08:20:14 UTC (rev 106313)
+++ keas.build/trunk/CHANGES.txt	2009-12-09 08:39:56 UTC (rev 106314)
@@ -4,6 +4,8 @@
 0.1.7 (unreleased)
 ------------------
 
+- Improvement: Check dependent configs, upload all to the server.
+
 - Improvement: Add ``--force-version`` option.
 
 - Improvement: Add version to svn log comment. That makes life easier (at least

Modified: keas.build/trunk/src/keas/build/build.py
===================================================================
--- keas.build/trunk/src/keas/build/build.py	2009-12-09 08:20:14 UTC (rev 106313)
+++ keas.build/trunk/src/keas/build/build.py	2009-12-09 08:39:56 UTC (rev 106314)
@@ -31,6 +31,8 @@
 
 logger = base.logger
 
+is_win32 = sys.platform == 'win32'
+
 def findProjectVersions(project, config, options, uploadType):
     if options.offline:
         logger.info('Offline: Skip looking for project versions.')
@@ -73,7 +75,68 @@
 
     return sorted(versions, key=lambda x: pkg_resources.parse_version(x))
 
+def getDependentConfigFiles(filename, addSelf=True, outfile=None):
+    config = ConfigParser.RawConfigParser()
+    config.read(filename)
 
+    dependents = set()
+    if addSelf:
+        dependents.add(filename)
+
+    path = os.path.dirname(filename)
+
+    try:
+        extends = config.get('buildout', 'extends')
+    except ConfigParser.NoSectionError:
+        return dependents
+    except ConfigParser.NoOptionError:
+        return dependents
+
+    extendParts = extends.split()
+    hasPath = False
+    for part in extendParts:
+        if '/' in part or '\\' in part:
+            hasPath = True
+
+        # extends filenames are always relative to the actual file
+        fullname = os.path.join(path, part)
+
+        if is_win32:
+            #most buildouts use / but win32 uses \
+            fullname = fullname.replace('/', '\\')
+
+        if not os.path.exists(fullname):
+            logger.error("FATAL: %s not found, but is referenced by %s" % (
+                fullname, filename))
+            sys.exit(0)
+
+        dependents.update(getDependentConfigFiles(fullname))
+
+    if hasPath:
+        #we need to clean relative path from extends as on the server
+        #everything is flat
+        extendParts = [os.path.split(part)[-1] for part in extendParts]
+        extends = '\n  '.join(extendParts)
+
+        config.set('buildout', 'extends', extends)
+
+        if outfile:
+            #if the config is created by ourselves
+            config.write(open(outfile, 'w'))
+        else:
+            #this is a referenced config, don't modify the original
+            newname = os.path.split(filename)[-1]
+            config.write(open(newname, 'w'))
+
+            if addSelf:
+                #adjust dependents
+                dependents.remove(filename)
+                dependents.add(newname)
+
+    return dependents
+
+
+
 def build(configFile, options):
     # Read the configuration file.
     logger.info('Loading configuration file: ' + configFile)
@@ -83,10 +146,13 @@
     # Create the project config parser
     logger.info('Creating Project Configuration')
     projectParser = ConfigParser.RawConfigParser()
+    template_path = None
     if config.has_option(base.BUILD_SECTION, 'template'):
         template = config.get(base.BUILD_SECTION, 'template')
         logger.info('Loading Project Configuration Template: ' + template)
         projectParser.read([template])
+        template_path = os.path.abspath(template)
+
     if not projectParser.has_section('versions'):
         projectParser.add_section('versions')
 
@@ -139,6 +205,16 @@
 
     filesToUpload = [projectConfigFilename]
 
+    # Process config files, check for dependent config files
+    # we should make sure that they are on the server
+    # by design only the projectConfigFilename will have variable dependencies
+
+    if template_path:
+        dependencies = getDependentConfigFiles(template_path,
+                                               addSelf=False,
+                                               outfile=projectConfigFilename)
+        filesToUpload.extend(dependencies)
+
     # Create deployment configurations
     for section in config.sections():
         if section == base.BUILD_SECTION:
@@ -177,6 +253,9 @@
 
         filesToUpload.append(deployConfigFilename)
 
+    from pub.dbgpclient import brk; brk('192.168.32.1')
+
+
     # Upload the deployment files
     if uploadType == 'local':
         #no upload, just copy to destination
@@ -198,19 +277,22 @@
                     options.offline)
     elif uploadType == 'mypypi':
         if not options.offline and not options.noUpload:
-            url = (config.get(base.BUILD_SECTION, 'buildout-server')+
-                   '/'+projectName+'/upload')
+            server = config.get(base.BUILD_SECTION, 'buildout-server')
+            if not server.endswith('/'):
+                server += '/'
+            url = (server + projectName + '/upload')
             boundary = "--------------GHSKFJDLGDS7543FJKLFHRE75642756743254"
             headers={"Content-Type":
                 "multipart/form-data; boundary=%s; charset=utf-8" % boundary}
             for filename in filesToUpload:
+                justfname = os.path.split(filename)[-1]
                 #being lazy here with the construction of the multipart form data
                 content = """--%s
 Content-Disposition: form-data; name="content";filename="%s"
 
 %s
 --%s--
-""" % (boundary, filename, open(filename, 'r').read(), boundary)
+""" % (boundary, justfname, open(filename, 'r').read(), boundary)
 
                 base.uploadContent(
                     content, filename, url,

Modified: keas.build/trunk/src/keas/build/index.txt
===================================================================
--- keas.build/trunk/src/keas/build/index.txt	2009-12-09 08:20:14 UTC (rev 106313)
+++ keas.build/trunk/src/keas/build/index.txt	2009-12-09 08:39:56 UTC (rev 106314)
@@ -40,6 +40,9 @@
 
 - Upload the buildout configuration files to a private configuration server.
 
+- Upload dependent buildout configuration files to a private configuration
+  server (by checking the extends= chain)
+
 Installation
 ============
 



More information about the checkins mailing list