porting code to python3.x with os patch
[tools/git-buildpackage.git] / gbp / git / __init__.py
1 # vim: set fileencoding=utf-8 :
2 #
3 # (C) 2006,2007,2008,2011 Guido Guenther <agx@sigxcpu.org>
4 #    This program is free software; you can redistribute it and/or modify
5 #    it under the terms of the GNU General Public License as published by
6 #    the Free Software Foundation; either version 2 of the License, or
7 #    (at your option) any later version.
8 #
9 #    This program is distributed in the hope that it will be useful,
10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #    GNU General Public License for more details.
13 #
14 #    You should have received a copy of the GNU General Public License
15 #    along with this program; if not, write to the Free Software
16 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 """Accessing Git from python"""
18
19 import calendar
20 import dateutil.parser
21
22 from gbp.git.modifier import GitModifier
23 from gbp.git.commit import GitCommit
24 from gbp.git.errors import GitError
25 from gbp.git.repository import GitRepository, GitRepositoryError
26 from gbp.git.fastimport import FastImport
27 from gbp.git.args import GitArgs
28 from gbp.git.vfs import GitVfs
29
30
31 def rfc822_date_to_git(rfc822_date):
32     """Parse a date in RFC822 format, and convert to a 'seconds tz' C{str}ing.
33     >>> rfc822_date_to_git('Thu, 1 Jan 1970 00:00:01 +0000')
34     '1 +0000'
35     >>> rfc822_date_to_git('Thu, 20 Mar 2008 01:12:57 -0700')
36     '1206000777 -0700'
37     >>> rfc822_date_to_git('Sat, 5 Apr 2008 17:01:32 +0200')
38     '1207407692 +0200'
39     """
40     d = dateutil.parser.parse(rfc822_date)
41     seconds = calendar.timegm(d.utctimetuple())
42     tz = d.strftime("%z")
43     return '%d %s' % (seconds, tz)
44
45 # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
46