aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libbe/bugdir.py15
-rw-r--r--libbe/mapfile.py18
-rw-r--r--libbe/upgrade.py36
3 files changed, 49 insertions, 20 deletions
diff --git a/libbe/bugdir.py b/libbe/bugdir.py
index 544f6b2..5946c04 100644
--- a/libbe/bugdir.py
+++ b/libbe/bugdir.py
@@ -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,
diff --git a/libbe/mapfile.py b/libbe/mapfile.py
index b959d76..74d2b1a 100644
--- a/libbe/mapfile.py
+++ b/libbe/mapfile.py
@@ -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):
diff --git a/libbe/upgrade.py b/libbe/upgrade.py
index a31d6df..215dbce 100644
--- a/libbe/upgrade.py
+++ b/libbe/upgrade.py
@@ -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: