aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/utility.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2008-11-21 14:56:05 -0500
committerW. Trevor King <wking@drexel.edu>2008-11-21 14:56:05 -0500
commit23179f50092d91dbeab97ad2b88cdaadb79b615f (patch)
tree4a5579d686c573d6d438214aa0d2100f01083bef /libbe/utility.py
parenta2bdbab9ccd9ca24ce470d2beeea86afb7ede2ae (diff)
downloadbugseverywhere-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/utility.py')
-rw-r--r--libbe/utility.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/libbe/utility.py b/libbe/utility.py
index f595bdb..81023cd 100644
--- a/libbe/utility.py
+++ b/libbe/utility.py
@@ -71,6 +71,32 @@ def get_file(f):
else:
return f
+def search_parent_directories(path, filename):
+ """
+ Find the file (or directory) named filename in path or in any
+ of path's parents.
+
+ e.g.
+ search_parent_directories("/a/b/c", ".be")
+ will return the path to the first existing file from
+ /a/b/c/.be
+ /a/b/.be
+ /a/.be
+ /.be
+ or None if none of those files exist.
+ """
+ path = os.path.realpath(path)
+ assert os.path.exists(path)
+ old_path = None
+ while True:
+ check_path = os.path.join(path, filename)
+ if os.path.exists(check_path):
+ return check_path
+ if path == old_path:
+ return None
+ old_path = path
+ path = os.path.dirname(path)
+
class Dir:
"A temporary directory for testing use"
def __init__(self):