You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2014/01/24 17:09:15 UTC

svn commit: r1561048 - /manifoldcf/release-scripts/create-site-branch.py

Author: kwright
Date: Fri Jan 24 16:09:15 2014
New Revision: 1561048

URL: http://svn.apache.org/r1561048
Log:
Flesh out most methods

Modified:
    manifoldcf/release-scripts/create-site-branch.py

Modified: manifoldcf/release-scripts/create-site-branch.py
URL: http://svn.apache.org/viewvc/manifoldcf/release-scripts/create-site-branch.py?rev=1561048&r1=1561047&r2=1561048&view=diff
==============================================================================
--- manifoldcf/release-scripts/create-site-branch.py (original)
+++ manifoldcf/release-scripts/create-site-branch.py Fri Jan 24 16:09:15 2014
@@ -2,6 +2,7 @@ import sys
 import os
 import shutil
 import subprocess
+import codecs
 
 def svn_command(command_array):
     """ Invoke svn command """
@@ -17,15 +18,79 @@ def remove_dir(directory_path):
     """ Remove a directory and all of its contents """
     shutil.rmtree(directory_path)
 
+def match_change_txt_dev_line(line):
+    """ Find a line looking like this:
+        ===== nnn-dev =====
+    """
+    index = line.find("=== ")
+    if index == -1:
+        return False
+    end_index = line.find("-dev ===", index + 4)
+    return end_index != -1
+
+def make_change_txt_release_line(build_version):
+    return "======================= Release %s =====================" % build_version
+
 def add_change_file_release_row(change_file_path, release_version):
     """ Convert the -dev row in a change file to a release row """
-    # MHL
-    pass
-    
+    converted = False
+    temp_file = "%s.tmp" % build_file_path
+    fd = codecs.open(change_file_path, "r", "utf-8")
+    try:
+        out_fd = codecs.open(temp_file, "w", "utf-8")
+        try:
+            for line in fd:
+                if converted:
+                    out_fd.write(line)
+                else:
+                    if match_change_txt_dev_line(line):
+                        out_fd.write(make_change_txt_release_line(build_version))
+                        converted = True
+                    else:
+                        out_fd.write(line)
+        finally:
+            out_fd.close()
+    finally:
+        fd.close()
+        
+    # Remove old file and rename temp file
+    os.unlink(change_file_path)
+    os.rename(temp_file, change_file_path)
+
+def match_change_txt_add_line(line):
+    """ Look for a line with === in it """
+    return line.find("===") >= 0
+
+def make_change_txt_dev_line(dev_version):
+    return "======================= %s-dev =====================" % dev_version;
+
 def add_change_file_new_dev_row(change_file_path, dev_version):
     """ Add a new -dev row to the start of a change file """
-    # MHL
-    pass
+    added_row = False
+    temp_file = "%s.tmp" % build_file_path
+    fd = codecs.open(change_file_path, "r", "utf-8")
+    try:
+        out_fd = codecs.open(temp_file, "w", "utf-8")
+        try:
+            for line in fd:
+                if added_row:
+                    out_fd.write(line)
+                else:
+                    if match_change_txt_add_line(line):
+                        out_fd.write(make_change_txt_dev_line(dev_version))
+                        out_fd.write("")
+                        out_fd.write("")
+                        added_row = True
+                    else:
+                        out_fd.write(line)
+        finally:
+            out_fd.close()
+    finally:
+        fd.close()
+        
+    # Remove old file and rename temp file
+    os.unlink(change_file_path)
+    os.rename(temp_file, change_file_path)
     
 def fix_pom_xml(pom_file_path, pom_version):
     """
@@ -40,11 +105,37 @@ def update_poms(root_directory, pom_vers
     dirs = fix_pom_xml( "%s/pom.xml" % root_directory, pom_version )
     for dir in dirs:
         update_poms( "%s/%s" % (root_directory, dir), pom_version )
-    
+
+def convert_build_xml_line(line, build_version):
+    """
+        Fills value in where property name is "release-version", e.g. <property name="release-version" value="1.6-dev"/>
+    """
+    string_to_match = "<property name=\"release-version\" value=\""
+    index = line.find(string_to_match)
+    if index == -1:
+        return line
+    end_index = line.find("\"", index + len(string_to_match))
+    if end_index == -1:
+        raise Exception("Can't substitute line '%s'" % line)
+    return line[0:index] + build_version + line[end_index:len(line)]
+
 def fix_build_xml(build_file_path, build_version):
     """ Update version number in build.xml to be the specified one. """
-    # MHL
-    pass
+    temp_file = "%s.tmp" % build_file_path
+    fd = codecs.open(build_file_path, "r", "utf-8")
+    try:
+        out_fd = codecs.open(temp_file, "w", "utf-8")
+        try:
+            for line in fd:
+                out_fd.write(convert_build_xml_line(line, build_version))
+        finally:
+            out_fd.close()
+    finally:
+        fd.close()
+        
+    # Remove old file and rename temp file
+    os.unlink(build_file_path)
+    os.rename(temp_file, build_file_path)
 
 def checkout_tree(tree_directory_path, svn_url):
     """ Check out the specified svn tree to the specified place """
@@ -63,9 +154,9 @@ def create_release_branch(release_versio
     # Basic checks
     if not os.exists(working_directory):
         raise Exception("Working directory '%s' does not appear to exist" % working_directory)
-    if release_version.index("-SNAPSHOT") >= 0 or release_version.index("-dev") >= 0:
+    if release_version.find("-SNAPSHOT") >= 0 or release_version.find("-dev") >= 0:
         raise Exception("Release version '%s' cannot contain SNAPSHOT or dev" % release_version)
-    if new_trunk_version.index("-SNAPSNOT") >= 0 or new_trunk_version.index("-dev") >= 0:
+    if new_trunk_version.find("-SNAPSNOT") >= 0 or new_trunk_version.find("-dev") >= 0:
         raise Exception("New trunk version '%s' cannot contain SNAPSHOT or dev" % new_trunk_version)
 
     # Point to all the right places