diff options
author | Guido Günther <agx@sigxcpu.org> | 2011-10-22 13:53:48 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2011-10-23 16:18:53 +0200 |
commit | a65c430b9414e166d9b6d9731fab636f710565b5 (patch) | |
tree | 638ee22eb3e7ccf15b38b5cbfc1c667bd3ffe6d6 /gbp/git.py | |
parent | f3df4bf7e0ba64f78b33f6d2a3dd3439bfebbd3f (diff) |
git: Add GitModifier
to make passing author/comitter information easier.
Git-Dch: Ignore
Diffstat (limited to 'gbp/git.py')
-rw-r--r-- | gbp/git.py | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -30,6 +30,53 @@ class GitRepositoryError(Exception): pass +class GitModifier(object): + """Stores authorship/comitter information""" + def __init__(self, name=None, email=None, date=None): + self.__dict__.update(locals()) + + def _get_env(self, who): + """Get author or comitter information as env var dictionary""" + who = who.upper() + if who not in ['AUTHOR', 'COMMITTER']: + raise GitRepository("Neither comitter nor author") + + extra_env = {} + if self.name: + extra_env['GIT_%s_NAME' % who] = self.name + if self.email: + extra_env['GIT_%s_EMAIL' % who] = self.email + if self.date: + extra_env['GIT_%s_DATE' % who] = self.date + return extra_env + + def get_author_env(self): + """ + Get env vars for authorship information + + >>> g = GitModifier("foo", "bar") + >>> g.get_author_env() + {'GIT_AUTHOR_EMAIL': 'bar', 'GIT_AUTHOR_NAME': 'foo'} + + @return: Author information suitable to use as environment variables + @rtype: dict + """ + return self._get_env('author') + + def get_committer_env(self): + """ + Get env vars for comitter information + + >>> g = GitModifier("foo", "bar") + >>> g.get_committer_env() + {'GIT_COMMITTER_NAME': 'foo', 'GIT_COMMITTER_EMAIL': 'bar'} + + @return: Commiter information suitable to use as environment variables + @rtype: dict + """ + return self._get_env('committer') + + class GitRepository(object): """ Represents a git repository at I{path}. It's currently assumed that the git |