diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-05-05 15:16:54 +0000 |
---|---|---|
committer | Baserock Gerrit <gerrit@baserock.org> | 2015-05-22 15:07:43 +0000 |
commit | 05b2b062afa2ab4cbd504735fd16cf53d969a2a5 (patch) | |
tree | 67ef311dde7af51353b18823736dbcbf19882162 /morphlib/sysbranchdir.py | |
parent | 538780673002b49aa1193e3617c81024ba64e434 (diff) | |
download | morph-05b2b062afa2ab4cbd504735fd16cf53d969a2a5.tar.gz |
Move 'git config' wrapper into its own class
We use 'git config' format config files outside Git repos, so it's
useful to have a helper class independent of the GitDirectory class.
This allows us to use it in the sysbranchdir.open() function to remove
a hack.
Change-Id: Ifa5e87f404d10666c98b9469079b7925d16becf6
Diffstat (limited to 'morphlib/sysbranchdir.py')
-rw-r--r-- | morphlib/sysbranchdir.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/morphlib/sysbranchdir.py b/morphlib/sysbranchdir.py index 69119f5b..3ca5a8cb 100644 --- a/morphlib/sysbranchdir.py +++ b/morphlib/sysbranchdir.py @@ -50,6 +50,8 @@ class SystemBranchDirectory(object): self.root_repository_url = root_repository_url self.system_branch_name = system_branch_name + self.config = morphlib.gitdir.Config(config_file=self._config_path) + @property def _magic_path(self): return os.path.join(self.root_directory, '.morph-system-branch') @@ -60,14 +62,11 @@ class SystemBranchDirectory(object): def set_config(self, key, value): '''Set a configuration key/value pair.''' - morphlib.git.gitcmd(cliapp.runcmd, 'config', '-f', - self._config_path, key, value) + self.config[key] = value def get_config(self, key): '''Get a configuration value for a given key.''' - value = morphlib.git.gitcmd(cliapp.runcmd, 'config', '-f', - self._config_path, key) - return value.strip() + return self.config[key] def _find_git_directory(self, repo_url): for gd in self.list_git_directories(): @@ -210,6 +209,7 @@ class SystemBranchDirectory(object): yield m + def create(root_directory, root_repository_url, system_branch_name): '''Create a new system branch directory on disk. @@ -242,10 +242,12 @@ def create(root_directory, root_repository_url, system_branch_name): def open(root_directory): '''Open an existing system branch directory.''' - # Ugly hack follows. - sb = SystemBranchDirectory(root_directory, None, None) - root_repository_url = sb.get_config('branch.root') - system_branch_name = sb.get_config('branch.name') + config_file_path = os.path.join( + root_directory, '.morph-system-branch', 'config') + config = morphlib.gitdir.Config(config_file=config_file_path) + + root_repository_url = config['branch.root'] + system_branch_name = config['branch.name'] return SystemBranchDirectory( root_directory, root_repository_url, system_branch_name) |