Upgrade duplicate bugdirs if necessary (e.g. for `be diff').
authorW. Trevor King <wking@drexel.edu>
Mon, 31 Aug 2009 17:16:48 +0000 (13:16 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 31 Aug 2009 17:16:48 +0000 (13:16 -0400)
Also moved pre-YAML mapfile handling in mapfile.parse() into
upgrade.Upgrade_1_0_to_2._upgrade_mapfile().

libbe/bugdir.py
libbe/mapfile.py
libbe/upgrade.py

index 544f6b26a5b78aaef42ca8131b4701c143f08a07..5946c04d76bb038e5f0200398324c1675af0d8a9 100644 (file)
@@ -411,7 +411,8 @@ settings easy.  Don't set this attribute.  Set .rcs instead, and
         settings = self._get_saved_settings()
         self._save_settings(self.get_path("settings"), settings)
 
-    def get_version(self, path=None, use_none_rcs=False):
+    def get_version(self, path=None, use_none_rcs=False,
+                    for_duplicate_bugdir=False):
         """
         Requires disk access.
         """
@@ -426,7 +427,11 @@ settings easy.  Don't set this attribute.  Set .rcs instead, and
 
         if path == None:
             path = self.get_path("version")
-        version = RCS.get_file_contents(path).rstrip("\n")
+        allow_no_rcs = not RCS.path_in_root(path)
+        if allow_no_rcs == True:
+            assert for_duplicate_bugdir == True
+        version = RCS.get_file_contents(
+            path, allow_no_rcs=allow_no_rcs).rstrip("\n")
         return version
 
     def set_version(self):
@@ -504,6 +509,12 @@ settings easy.  Don't set this attribute.  Set .rcs instead, and
     def duplicate_bugdir(self, revision):
         duplicate_path = self.rcs.duplicate_repo(revision)
 
+        duplicate_version_path = os.path.join(duplicate_path, ".be", "version")
+        version = self.get_version(duplicate_version_path,
+                                   for_duplicate_bugdir=True)
+        if version != upgrade.BUGDIR_DISK_VERSION:
+            upgrade.upgrade(duplicate_path, version)
+
         # setup revision RCS as None, since the duplicate may not be
         # initialized for versioning
         duplicate_settings_path = os.path.join(duplicate_path,
index b959d7608c8abec2d5c0644585b76d0b936c050c..74d2b1a3adf4a2dd25a07e67febcbb18ac8bae6f 100644 (file)
@@ -95,24 +95,6 @@ def parse(contents):
     >>> dict["e"]
     'f'
     """
-    old_format = False
-    for line in contents.splitlines():
-        if len(line.split("=")) == 2:
-            old_format = True
-            break
-    if old_format: # translate to YAML.  Hack to deal with old BE bugs.
-        newlines = []
-        for line in contents.splitlines():
-            line = line.rstrip('\n')
-            if len(line) == 0:
-                continue
-            fields = line.split("=")
-            if len(fields) == 2:
-                key,value = fields
-                newlines.append('%s: "%s"' % (key, value.replace('"','\\"')))
-            else:
-                newlines.append(line)
-        contents = '\n'.join(newlines)
     return yaml.load(contents) or {}
 
 def map_save(rcs, path, map, allow_no_rcs=False):
index a31d6df39d3b2b80cc134d1a6c887b26ee7f30cf..215dbce10112bbaf031d903f2953b31cf7268c91 100644 (file)
@@ -74,22 +74,58 @@ class Upgrader (object):
     def _upgrade(self):
         raise NotImplementedError
 
+
 class Upgrade_1_0_to_2 (Upgrader):
     initial_version = "Bugs Everywhere Tree 1 0"
     final_version = "Bugs Everywhere Directory v2"
+    def _upgrade_mapfile(self, path):
+        contents = self.rcs.get_file_contents(path)
+        old_format = False
+        for line in contents.splitlines():
+            if len(line.split("=")) == 2:
+                old_format = True
+                break
+        if old_format == True:
+            # translate to YAML.
+            newlines = []
+            for line in contents.splitlines():
+                line = line.rstrip('\n')
+                if len(line) == 0:
+                    continue
+                fields = line.split("=")
+                if len(fields) == 2:
+                    key,value = fields
+                    newlines.append('%s: "%s"' % (key, value.replace('"','\\"')))
+                else:
+                    newlines.append(line)
+            contents = '\n'.join(newlines)
+            # load the YAML and save
+            map = mapfile.parse(contents)
+            mapfile.map_save(self.rcs, path, map)
+
     def _upgrade(self):
+        """
+        Comment value field "From" -> "Author".
+        Homegrown mapfile -> YAML.
+        """
+        path = self.get_path("settings")
+        self._upgrade_mapfile(path)
         for bug_uuid in os.listdir(self.get_path("bugs")):
+            path = self.get_path("bugs", bug_uuid, "values")
+            self._upgrade_mapfile(path)
             c_path = ["bugs", bug_uuid, "comments"]
             if not os.path.exists(self.get_path(*c_path)):
                 continue # no comments for this bug
             for comment_uuid in os.listdir(self.get_path(*c_path)):
                 path_list = c_path + [comment_uuid, "values"]
                 path = self.get_path(*path_list)
+                self._upgrade_mapfile(path)
                 settings = mapfile.map_load(self.rcs, path)
                 if "From" in settings:
                     settings["Author"] = settings.pop("From")
                     mapfile.map_save(self.rcs, path, settings)
 
+
 upgraders = [Upgrade_1_0_to_2]
 upgrade_classes = {}
 for upgrader in upgraders: