diff options
author | Ed Bartosh <eduard.bartosh@intel.com> | 2012-05-30 09:02:55 +0300 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-11-14 14:22:07 +0200 |
commit | 4d705ed90a40def906ecf9726f16c42e4137de21 (patch) | |
tree | 7527a37776b290d79dc70cf1c33b286fc356eacc | |
parent | 99ded0575c8064698564884102cdd07e371b9af9 (diff) | |
download | git-buildpackage-4d705ed90a40def906ecf9726f16c42e4137de21.tar.gz git-buildpackage-4d705ed90a40def906ecf9726f16c42e4137de21.tar.bz2 git-buildpackage-4d705ed90a40def906ecf9726f16c42e4137de21.zip |
gbp.git: Reimplement rfc822 date parsing without dateutil
In order to get rid of dependency to dateutil.
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r-- | debian/control | 2 | ||||
-rw-r--r-- | gbp/git/__init__.py | 29 |
2 files changed, 24 insertions, 7 deletions
diff --git a/debian/control b/debian/control index 45d28a98..e9cc8932 100644 --- a/debian/control +++ b/debian/control @@ -12,7 +12,6 @@ Build-Depends: pychecker, python (>> 2.6.6-3~), python-coverage, - python-dateutil, python-epydoc, python-mock, python-nose, @@ -42,7 +41,6 @@ Depends: ${python:Depends}, devscripts (>= 2.13.5~), git (>= 1:1.7.9.1-1~), man-db, - python-dateutil, python-pkg-resources, Recommends: pristine-tar (>= 0.5), cowbuilder Suggests: python-notify, unzip, zipmerge diff --git a/gbp/git/__init__.py b/gbp/git/__init__.py index 55dc3a82..cbd84cb5 100644 --- a/gbp/git/__init__.py +++ b/gbp/git/__init__.py @@ -17,7 +17,8 @@ """Accessing Git from python""" import calendar -import dateutil.parser +import datetime +import rfc822 from gbp.git.modifier import GitModifier from gbp.git.commit import GitCommit @@ -28,6 +29,23 @@ from gbp.git.args import GitArgs from gbp.git.vfs import GitVfs +class FixedOffset(datetime.tzinfo): + """Fixed offset in seconds east from UTC.""" + + ZERO = datetime.timedelta(0) + + def __init__(self, offset): + datetime.tzinfo.__init__(self) + self._offset = datetime.timedelta(seconds=offset) + + def utcoffset(self, dtime): + return self._offset + self.dst(dtime) + + def dst(self, dtime): + assert dtime.tzinfo is self + return self.ZERO + + def rfc822_date_to_git(rfc822_date): """Parse a date in RFC822 format, and convert to a 'seconds tz' C{str}ing. @@ -38,9 +56,10 @@ def rfc822_date_to_git(rfc822_date): >>> rfc822_date_to_git('Sat, 5 Apr 2008 17:01:32 +0200') '1207407692 +0200' """ - d = dateutil.parser.parse(rfc822_date) - seconds = calendar.timegm(d.utctimetuple()) - tz = d.strftime("%z") - return '%d %s' % (seconds, tz) + parsed = rfc822.parsedate_tz(rfc822_date) + date = datetime.datetime(*parsed[:6], tzinfo=FixedOffset(parsed[-1])) + seconds = calendar.timegm(date.utctimetuple()) + tzone = date.strftime("%z") + return '%d %s' % (seconds, tzone) # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: |