[Checkins] SVN: keas.build/trunk/ add option ``hash-config-files``

Adam Groszer agroszer at gmail.com
Wed Apr 6 08:32:44 EDT 2011


Log message for revision 121301:
  add option ``hash-config-files``

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	2011-04-06 12:30:09 UTC (rev 121300)
+++ keas.build/trunk/CHANGES.txt	2011-04-06 12:32:43 UTC (rev 121301)
@@ -9,7 +9,9 @@
 - Improvement: add SVN repo infos to the project config file.
   Yah, I know this can be checked anytime, but adding this saves a lot of time.
 
+- Improvement: add option ``hash-config-files``
 
+
 0.1.8 (2010-05-11)
 ------------------
 

Modified: keas.build/trunk/src/keas/build/build.py
===================================================================
--- keas.build/trunk/src/keas/build/build.py	2011-04-06 12:30:09 UTC (rev 121300)
+++ keas.build/trunk/src/keas/build/build.py	2011-04-06 12:32:43 UTC (rev 121301)
@@ -21,6 +21,7 @@
 import StringIO
 import base64
 import logging
+import md5
 import pkg_resources
 import re
 import sys
@@ -75,7 +76,8 @@
 
     return sorted(versions, key=lambda x: pkg_resources.parse_version(x))
 
-def getDependentConfigFiles(baseFolder, infile, addSelf=True, outfile=None):
+def getDependentConfigFiles(baseFolder, infile, addSelf=True, outfile=None,
+                            hashes=None):
     # go and read all cfg files that are required by the master
     # to collect them all
     # if they have a path, modify according to that the the files are flat
@@ -86,6 +88,12 @@
     # in that case we want to read/write the modified file, but look for
     # the others in the template_path
 
+    if hashes is not None:
+        justname = os.path.split(infile)[-1]
+        if justname not in hashes:
+            hash = md5.new(open(infile, 'rb').read()).hexdigest()
+            hashes[justname] = hash
+
     config = ConfigParser.RawConfigParser()
     config.read(infile)
 
@@ -119,7 +127,7 @@
             sys.exit(0)
 
         dependents.update(getDependentConfigFiles(os.path.dirname(fullname),
-                                                  fullname))
+                                                  fullname, hashes=hashes))
 
     if hasPath:
         #we need to clean relative path from extends as on the server
@@ -144,8 +152,54 @@
 
     return dependents
 
+def addHashes(dependencies, hashes, rename=True):
+    # add hashes to files
 
+    rdep = []
+    for fname in dependencies:
+        modified = False
+        justname = os.path.split(fname)[-1]
 
+        config = ConfigParser.RawConfigParser()
+        config.read(fname)
+
+        try:
+            # 1. modify file contents
+            extends = config.get('buildout', 'extends')
+            for oldname, hash in hashes.items():
+                parts = os.path.splitext(oldname)
+                newname = "%s-%s%s" % (parts[0], hash, parts[1])
+
+                if oldname in extends:
+                    extends = extends.replace(oldname, newname)
+                    modified = True
+
+            if modified:
+                config.set('buildout', 'extends', extends)
+        except ConfigParser.NoSectionError:
+            pass
+        except ConfigParser.NoOptionError:
+            pass
+
+        # 2. rename/copy files
+        newname = justname
+        if rename:
+            try:
+                hash = hashes[justname]
+                parts = os.path.splitext(justname)
+                newname = "%s-%s%s" % (parts[0], hash, parts[1])
+                modified = True
+            except KeyError:
+                pass
+
+        if modified:
+            config.write(open(newname, 'w'))
+            rdep.append(newname)
+        else:
+            rdep.append(fname)
+
+    return rdep
+
 def build(configFile, options):
     # Read the configuration file.
     logger.info('Loading configuration file: ' + configFile)
@@ -223,14 +277,32 @@
 
     filesToUpload = [projectConfigFilename]
 
+    try:
+        hashConfigFiles = config.getboolean(base.BUILD_SECTION,
+                                            'hash-config-files')
+    except ConfigParser.NoOptionError:
+        hashConfigFiles = False
+
     # 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:
+        if hashConfigFiles:
+            hashes = {}
+        else:
+            hashes = None
+
         dependencies = getDependentConfigFiles(os.path.dirname(template_path),
                                                projectConfigFilename,
                                                addSelf=False,
-                                               outfile=projectConfigFilename)
+                                               outfile=projectConfigFilename,
+                                               hashes=hashes)
+
+        if hashConfigFiles:
+            dependencies = addHashes(dependencies, hashes)
+            #fix main config too
+            addHashes([projectConfigFilename], hashes, rename=False)
+
         filesToUpload.extend(dependencies)
 
     # Dump package repo infos

Modified: keas.build/trunk/src/keas/build/index.txt
===================================================================
--- keas.build/trunk/src/keas/build/index.txt	2011-04-06 12:30:09 UTC (rev 121300)
+++ keas.build/trunk/src/keas/build/index.txt	2011-04-06 12:32:43 UTC (rev 121301)
@@ -241,6 +241,9 @@
 
 - **svn-repos-password** - The password for the url repository.
 
+- **hash-config-files** - Add hashes based on file content to dependent config
+  filenames.
+
 - **packages** - a list of packages that are part of the project.
   These are the packages that live in the svn repository and that
   should be released in conjunction with each other.



More information about the checkins mailing list