From b6c7f1eb2c76ac3847d5b6da60b9c31a0a69d875 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 8 Aug 2013 15:09:57 +0000 Subject: Add SystemBranchDirectory.get_filename method --- morphlib/sysbranchdir.py | 9 +++++++++ morphlib/sysbranchdir_tests.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/morphlib/sysbranchdir.py b/morphlib/sysbranchdir.py index 7e278dce..827f150b 100644 --- a/morphlib/sysbranchdir.py +++ b/morphlib/sysbranchdir.py @@ -100,6 +100,15 @@ class SystemBranchDirectory(object): return os.path.join(self.root_directory, relative) + def get_filename(self, repo_url, relative): + '''Return full pathname to a file in a checked out repository. + + This is a convenience function. + + ''' + + return os.path.join(self.get_git_directory_name(repo_url), relative) + def clone_cached_repo(self, cached_repo, checkout_ref): '''Clone a cached git repository into the system branch directory. diff --git a/morphlib/sysbranchdir_tests.py b/morphlib/sysbranchdir_tests.py index e75122cc..7ee04c7d 100644 --- a/morphlib/sysbranchdir_tests.py +++ b/morphlib/sysbranchdir_tests.py @@ -162,6 +162,15 @@ class SystemBranchDirectoryTests(unittest.TestCase): sb.get_git_directory_name(url), os.path.join(self.root_directory, stripped)) + def test_reports_correct_path_for_file_in_repository(self): + sb = morphlib.sysbranchdir.create( + self.root_directory, + self.root_repository_url, + self.system_branch_name) + self.assertEqual( + sb.get_filename('test:chunk', 'foo'), + os.path.join(self.root_directory, 'test:chunk/foo')) + def test_reports_correct_name_for_git_directory_from_file_url(self): stripped = 'foobar/morphs' url = 'file:///%s.git' % stripped -- cgit v1.2.1