Notice: the grml team is migrating from Mercurial to Git.
Please visit git.grml.org instead!
| author | Michael Gebetsroither <michael.geb@gmx.at> |
| Mon Mar 24 16:42:23 2008 +0100 (8 months ago) | |
| changeset 180 | 3f56617d709e |
| manifest | 3f56617d709e |
| parent 179 | 1945b9335188 |
| child 181 | 9fa2584e40ec |
--- a/reposearch Mon Mar 24 15:39:50 2008 +0100+++ b/reposearch Mon Mar 24 16:42:23 2008 +0100@@ -11,11 +11,13 @@ def walkrepos(path, filter):raise errfor root, dirs, files in os.walk(path, onerror=errhandler):+ if filter(root):+ yield rootfor d in dirs:- if d == filter():- yield root- dirs[:] = []- break+ dir = os.path.join(root, d)+ if filter(dir):+ yield dir+ dirs.remove(d)def walkrepos_flat(path, filter):"""yield every hg repository in the current directory"""@@ -27,11 +29,18 @@ def walkrepos_flat(path, filter):yield dirdef repofilter(dir, x):- if dir == None: return x- else: return os.path.isdir(os.path.join(dir, x))+ return os.path.isdir(os.path.join(dir, x))++def gitbarefilter(dir, x):+ if dir.endswith(x):+ if len(os.path.basename(dir)) >4:+ if os.path.exists(os.path.join(dir, 'config')):+ return True+ return Falserepo_types = {'hg': lambda dir=None: repofilter(dir, '.hg'),'git': lambda dir=None: repofilter(dir, '.git'),+ 'gitbare': lambda dir=None: gitbarefilter(dir, '.git'),'bzr': lambda dir=None: repofilter(dir, '.bzr'),'darcs': lambda dir=None: repofilter(dir, '_darcs')}
--- a/tests/reposearch_tests.py Mon Mar 24 15:39:50 2008 +0100+++ b/tests/reposearch_tests.py Mon Mar 24 16:42:23 2008 +0100@@ -20,6 +20,7 @@ class Base(unittest.TestCase):class Git(Base):def testFlatOuter(self):+ '''Test walkrepos_flat from outer directory'''should = ['reposearch_data/git/a', 'reposearch_data/git/b']curr = list(rs.walkrepos_flat(op.join(self.dir, 'git'), rs.repo_types['git']))@@ -28,7 +29,6 @@ class Git(Base):should = ['git/a', 'git/b']curr = self.inner(lambda: list(rs.walkrepos_flat('git', rs.repo_types['git'])))self.assertEqual(should, curr)-def testRecOuter(self):should = ['reposearch_data/git/a', 'reposearch_data/git/b','reposearch_data/git/dir/a', 'reposearch_data/git/dir/b']@@ -40,5 +40,27 @@ class Git(Base):curr = self.inner(lambda: list(rs.walkrepos('git', rs.repo_types['git'])))self.assertEqual(should, curr)+class GitBare(Base):+ def testFlatOuter(self):+ should = 'reposearch_data/gitbare/a.git reposearch_data/gitbare/b.git'.split()+ curr = list(rs.walkrepos_flat(+ op.join(self.dir, 'gitbare'), rs.repo_types['gitbare']))+ self.assertEqual(should, curr)+ def testFlatInner(self):+ should = 'gitbare/a.git gitbare/b.git'.split()+ curr = self.inner(lambda: list(rs.walkrepos_flat('gitbare', rs.repo_types['gitbare'])))+ self.assertEqual(should, curr)+ def testRecOuter(self):+ should = ['reposearch_data/gitbare/a.git', 'reposearch_data/gitbare/b.git',+ 'reposearch_data/gitbare/dir/a.git', 'reposearch_data/gitbare/dir/b.git']+ curr = list(rs.walkrepos(+ op.join(self.dir, 'gitbare'), rs.repo_types['gitbare']))+ self.assertEqual(should, curr)+ def testRecInner(self):+ should = ['gitbare/a.git', 'gitbare/b.git', 'gitbare/dir/a.git', 'gitbare/dir/b.git']+ curr = self.inner(lambda: list(rs.walkrepos('gitbare', rs.repo_types['gitbare'])))+ self.assertEqual(should, curr)++if __name__ == "__main__":unittest.main()