aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-11-15 19:30:03 +0100
committerGuido Günther <agx@sigxcpu.org>2011-11-20 14:24:24 +0100
commite7bbada49300f987ae129147fffe244d0d7a4cb6 (patch)
tree16c7ae029fc61c541eb21a2a2f2da37432ffedff
parent917a496fd8ffc7e857571ca747df01051ef12e35 (diff)
Move GitModifier class to separate file
and introduce a new base exception for Git related errors.
-rw-r--r--gbp/git/__init__.py55
-rw-r--r--gbp/git/errors.py22
-rw-r--r--gbp/git/modifier.py78
-rw-r--r--tests/test_GitModifier.py4
4 files changed, 108 insertions, 51 deletions
diff --git a/gbp/git/__init__.py b/gbp/git/__init__.py
index 9b461d1c..2aef0d5a 100644
--- a/gbp/git/__init__.py
+++ b/gbp/git/__init__.py
@@ -25,60 +25,13 @@ import gbp.log as log
import dateutil.parser
import calendar
-class GitRepositoryError(Exception):
+from gbp.git.modifier import GitModifier
+from gbp.git.errors import GitError
+
+class GitRepositoryError(GitError):
"""Exception thrown by L{GitRepository}"""
pass
-
-class GitModifier(object):
- """Stores authorship/comitter information"""
- def __init__(self, name=None, email=None, date=None):
- self.name = name
- self.email = email
- self.date = date
-
- 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: C{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: C{dict}
- """
- return self._get_env('committer')
-
-
class GitCommit(object):
"""A git commit"""
sha1_re = re.compile(r'[0-9a-f]{40}$')
diff --git a/gbp/git/errors.py b/gbp/git/errors.py
new file mode 100644
index 00000000..d955a612
--- /dev/null
+++ b/gbp/git/errors.py
@@ -0,0 +1,22 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2011 Guido Guenther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""Git base error exception"""
+
+class GitError(Exception):
+ """Exception thrown by Git related classes"""
+ pass
+
diff --git a/gbp/git/modifier.py b/gbp/git/modifier.py
new file mode 100644
index 00000000..c77bb4d1
--- /dev/null
+++ b/gbp/git/modifier.py
@@ -0,0 +1,78 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2011 Guido Guenther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+Someone who modifiers something in git
+
+like committing changes or authoring a patch
+"""
+
+from gbp.git.errors import GitError
+
+
+class GitModifierError(GitError):
+ """Exception thrown by L{GitModifier}"""
+ pass
+
+
+class GitModifier(object):
+ """Stores authorship/comitter information"""
+ def __init__(self, name=None, email=None, date=None):
+ self.name = name
+ self.email = email
+ self.date = date
+
+ def _get_env(self, who):
+ """Get author or comitter information as env var dictionary"""
+ who = who.upper()
+ if who not in ['AUTHOR', 'COMMITTER']:
+ raise GitModifierError("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: C{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: C{dict}
+ """
+ return self._get_env('committer')
+
diff --git a/tests/test_GitModifier.py b/tests/test_GitModifier.py
index d463c2ea..1a5b27c4 100644
--- a/tests/test_GitModifier.py
+++ b/tests/test_GitModifier.py
@@ -20,4 +20,8 @@ def test_author():
{'GIT_AUTHOR_EMAIL': 'bar', 'GIT_AUTHOR_NAME': 'foo'}
>>> modifier.get_committer_env()
{'GIT_COMMITTER_NAME': 'foo', 'GIT_COMMITTER_EMAIL': 'bar'}
+ >>> modifier._get_env('foo')
+ Traceback (most recent call last):
+ ...
+ GitModifierError: Neither comitter nor author
"""