diff options
author | W. Trevor King <wking@drexel.edu> | 2008-11-21 14:56:05 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2008-11-21 14:56:05 -0500 |
commit | 23179f50092d91dbeab97ad2b88cdaadb79b615f (patch) | |
tree | 4a5579d686c573d6d438214aa0d2100f01083bef /libbe/rcs.py | |
parent | a2bdbab9ccd9ca24ce470d2beeea86afb7ede2ae (diff) | |
download | bugseverywhere-23179f50092d91dbeab97ad2b88cdaadb79b615f.tar.gz |
Another major rewrite. Now BugDir, Bug, and Comment are more distinct.
I pushed a lot of the little helper functions into the main classes,
which makes it easier for me to keep track of what's going on. I'm
now at the point where I can run through `python test.py` with each of
the backends (by changing the search order in rcs.py
_get_matching_rcs) without any unexpected errors for each backend
(except Arch). I can also run `test_usage.sh` without non-Arch errors
either.
However, don't consider this a stable commit yet. The bzr backend is
*really*slow*, and the other's aren't blazingly fast either. I think
I'm rewriting the entire database every time I save it :p. Still, it
passes the checks. and I don't like it when zounds of changes build up.
Diffstat (limited to 'libbe/rcs.py')
-rw-r--r-- | libbe/rcs.py | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/libbe/rcs.py b/libbe/rcs.py index 2993a80..abd92cb 100644 --- a/libbe/rcs.py +++ b/libbe/rcs.py @@ -24,7 +24,7 @@ import tempfile import shutil import unittest import doctest -from utility import Dir +from utility import Dir, search_parent_directories def _get_matching_rcs(matchfn): """Return the first module for which matchfn(RCS_instance) is true""" @@ -32,9 +32,9 @@ def _get_matching_rcs(matchfn): import bzr import hg import git - for module in [arch, bzr, hg, git]: + for module in [git, arch, bzr, hg, git]: rcs = module.new() - if matchfn(rcs): + if matchfn(rcs) == True: return rcs else: del(rcs) @@ -62,6 +62,9 @@ class CommandError(Exception): class SettingIDnotSupported(NotImplementedError): pass +class PathNotInRoot(Exception): + pass + def new(): return RCS() @@ -152,7 +155,10 @@ class RCS(object): pass def _rcs_get_file_contents(self, path, revision=None): """ - Get the file as it was in a given revision. + Get the file contents as they were in a given revision. Don't + worry about decoding the contents, the RCS.get_file_contents() + method will handle that. + Revision==None specifies the current revision. """ assert revision == None, \ @@ -180,7 +186,7 @@ class RCS(object): if e.errno == errno.ENOENT: return False raise e - def detect(self, path=None): + def detect(self, path="."): """ Detect whether a directory is revision controlled with this RCS. """ @@ -264,23 +270,28 @@ class RCS(object): Revision==None specifies the current revision. """ relpath = self._u_rel_path(path) - return self._rcs_get_file_contents(relpath, revision) + return self._rcs_get_file_contents(relpath, revision).decode("utf-8") def set_file_contents(self, path, contents): """ Set the file contents under version control. """ add = not os.path.exists(path) - file(path, "wb").write(contents) + file(path, "wb").write(contents.encode("utf-8")) if add: self.add(path) else: self.update(path) def mkdir(self, path): """ - Created directory at path under version control. + Create (if neccessary) a directory at path under version + control. """ - os.mkdir(path) - self.add(path) + if not os.path.exists(path): + os.mkdir(path) + self.add(path) + else: + assert os.path.isdir(path) + self.update(path) def duplicate_repo(self, revision=None): """ Get the repository as it was in a given revision. @@ -366,16 +377,7 @@ class RCS(object): /.be or None if none of those files exist. """ - path = os.path.realpath(path) - assert os.path.exists(path) - old_path = None - while True: - if os.path.exists(os.path.join(path, filename)): - return os.path.join(path, filename) - if path == old_path: - return None - old_path = path - path = os.path.dirname(path) + return search_parent_directories(path, filename) def _u_rel_path(self, path, root=None): """ Return the relative path to path from root. @@ -389,8 +391,9 @@ class RCS(object): if os.path.isabs(path): absRoot = os.path.abspath(root) absRootSlashedDir = os.path.join(absRoot,"") - assert path.startswith(absRootSlashedDir), \ - "file %s not in root %s" % (path, absRootSlashedDir) + if not path.startswith(absRootSlashedDir): + raise PathNotInRoot, \ + "file %s not in root %s" % (path, absRootSlashedDir) assert path != absRootSlashedDir, \ "file %s == root directory %s" % (path, absRootSlashedDir) path = path[len(absRootSlashedDir):] |