From 63a0bbe14d0b5b3a29f9647f4089604d8436458e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 7 Jun 2011 11:47:14 +0200 Subject: Added version_info property to git command --- git/cmd.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'git/cmd.py') diff --git a/git/cmd.py b/git/cmd.py index 60887f5d..17734178 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -5,7 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import os, sys -from util import * +from util import LazyMixin from exc import GitCommandError from subprocess import ( @@ -26,7 +26,7 @@ __all__ = ('Git', ) def dashify(string): return string.replace('_', '-') -class Git(object): +class Git(LazyMixin): """ The Git class manages communication with the Git binary. @@ -41,7 +41,7 @@ class Git(object): of the command to stdout. Set its value to 'full' to see details about the returned values. """ - __slots__ = ("_working_dir", "cat_file_all", "cat_file_header") + __slots__ = ("_working_dir", "cat_file_all", "cat_file_header", "_version_info") # CONFIGURATION # The size in bytes read from stdout when copying git's output to another stream @@ -214,14 +214,30 @@ class Git(object): """A convenience method as it allows to call the command as if it was an object. :return: Callable object that will execute call _call_process with your arguments.""" - if name[:1] == '_': - raise AttributeError(name) + if name[0] == '_': + return LazyMixin.__getattr__(self, name) return lambda *args, **kwargs: self._call_process(name, *args, **kwargs) + def _set_cache_(self, attr): + if attr == '_version_info': + version_numbers = self._call_process('version').rpartition(' ')[2] + self._version_info = tuple(int(n) for n in version_numbers.split('.')) + else: + super(Git, self)._set_cache_(attr) + #END handle version info + + @property def working_dir(self): """:return: Git directory we are working on""" return self._working_dir + + @property + def version_info(self): + """:return: tuple(int, ...) tuple with integers representing the major, minor + and additional version numbers as parsed from git version. + This value is generated on demand and is cached""" + return self._version_info def execute(self, command, istream=None, -- cgit v1.2.3 From 9bf3fdec93fe427bb5f0bd39c986a4e977969f41 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 7 Jun 2011 13:38:48 +0200 Subject: First run in order to fix the remote handling. Cleaned up interfaces and figured out that the implementation really should be specific to the git command. This leaves the interface open for other implemntations which use a different way to provide feedback (as we do not make assumptions about the format of a feedback line) --- git/cmd.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'git/cmd.py') diff --git a/git/cmd.py b/git/cmd.py index 17734178..29d942ae 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -5,7 +5,10 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import os, sys -from util import LazyMixin +from util import ( + LazyMixin, + stream_copy + ) from exc import GitCommandError from subprocess import ( -- cgit v1.2.3