diff options
Diffstat (limited to 'client/utils/git.py')
| -rw-r--r-- | client/utils/git.py | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/client/utils/git.py b/client/utils/git.py index 11b00c1..587e5a4 100644 --- a/client/utils/git.py +++ b/client/utils/git.py @@ -8,75 +8,75 @@ from utils.logging import log class GitRepository(object): - 'a simple management of a git repository / source building' + 'a simple management of a git repository / source building' - def __init__(self, url, path): - 'url - repository URL, path - local directory for the clone' + def __init__(self, url, path): + 'url - repository URL, path - local directory for the clone' - self._url = url - self._path = path + self._url = url + self._path = path + def _exists(self): + 'check that a local repository clone exists' - def _exists(self): - 'check that a local repository clone exists' + # TODO verify that the repository uses the proper upstream url + return os.path.exists(self._path) - # TODO verify that the repository uses the proper upstream url - return os.path.exists(self._path) + def _clone(self): + '' + log("cloning repository '%s' to '%s'" % (self._url, self._path)) + with TemporaryFile() as strout: + call(['git', 'clone', self._url, self._path], stdout=strout, + stderr=STDOUT) - def _clone(self): - '' - log("cloning repository '%s' to '%s'" % (self._url, self._path)) + def _update(self): + 'update an existing repository clone' - with TemporaryFile() as strout: - call(['git', 'clone', self._url, self._path], stdout=strout, stderr=STDOUT) + log("updating repository '%s' from '%s'" % (self._path, self._url)) + # simply call git-pull and redirect stdout/stderr + # FIXME should verify that the repository uses the proper upstream url + with TemporaryFile() as strout: + call(['git', 'pull'], cwd=self._path, stdout=strout, stderr=STDOUT) - def _update(self): - 'update an existing repository clone' + def current_commit(self): + 'returns current commit hash' - log("updating repository '%s' from '%s'" % (self._path, self._url)) + with TemporaryFile() as strout: + call(['git', 'rev-parse', 'HEAD'], cwd=self._path, stdout=strout, + stderr=STDOUT) + strout.seek(0) + return strout.read().strip() - # simply call git-pull and redirect stdout/stderr - # FIXME should verify that the repository uses the proper upstream url - with TemporaryFile() as strout: - call(['git', 'pull'], cwd=self._path, stdout=strout, stderr=STDOUT) + def clone_or_update(self): + 'refreshes the repository (either clone from scratch or refresh)' + if self._exists(): + self._update() + else: + self._clone() - def current_commit(self): - 'returns current commit hash' + log("current commit '%s'" % (self.current_commit(),)) - with TemporaryFile() as strout: - call(['git', 'rev-parse', 'HEAD'], cwd=self._path, stdout=strout, stderr=STDOUT) - strout.seek(0) - return strout.read().strip() + def build_and_install(self, path, remove=True): + 'builds and installs the sources' + # TODO collect output of configure and make commands + if os.path.exists(path): + shutil.rmtree(path) - def clone_or_update(self): - 'refreshes the repository (either clone from scratch or refresh)' + with TemporaryFile() as strout: + log("configuring sources in '%s' with prefix '%s'" % + (self._path, path)) + call(['./configure', '--prefix', path], cwd=self._path, + stdout=strout, stderr=STDOUT) - if self._exists(): - self._update() - else: - self._clone() + with TemporaryFile() as strout: + log("building sources and installing into '%s'" % (path,)) - log("current commit '%s'" % (self.current_commit(),)) - - - def build_and_install(self, path, remove=True): - 'builds and installs the sources' - - # TODO collect output of configure and make commands - if os.path.exists(path): - shutil.rmtree(path) - - with TemporaryFile() as strout: - log("configuring sources in '%s' with prefix '%s'" % (self._path, path)) - call(['./configure', '--prefix', path], cwd=self._path, stdout=strout, stderr=STDOUT) - - with TemporaryFile() as strout: - log("building sources and installing into '%s'" % (path,)) - - # cleanup and build using multiple cpus - call(['make', '-s', 'clean'], cwd=self._path, stdout=strout, stderr=STDOUT) - call(['make', '-s', '-j', str(cpu_count()), 'install'], cwd=self._path, stdout=strout, stderr=STDOUT) + # cleanup and build using multiple cpus + call(['make', '-s', 'clean'], cwd=self._path, stdout=strout, + stderr=STDOUT) + call(['make', '-s', '-j', str(cpu_count()), 'install'], + cwd=self._path, stdout=strout, stderr=STDOUT) |
