__init__.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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, please see
  16. # <http://www.gnu.org/licenses/>
  17. """Accessing Git from python"""
  18. import calendar
  19. import dateutil.parser
  20. from gbp.git.modifier import GitModifier
  21. from gbp.git.commit import GitCommit
  22. from gbp.git.errors import GitError
  23. from gbp.git.repository import GitRepository, GitRepositoryError
  24. from gbp.git.fastimport import FastImport
  25. from gbp.git.args import GitArgs
  26. from gbp.git.vfs import GitVfs
  27. def rfc822_date_to_git(rfc822_date):
  28. """Parse a date in RFC822 format, and convert to a 'seconds tz' C{str}ing.
  29. >>> rfc822_date_to_git('Thu, 1 Jan 1970 00:00:01 +0000')
  30. '1 +0000'
  31. >>> rfc822_date_to_git('Thu, 20 Mar 2008 01:12:57 -0700')
  32. '1206000777 -0700'
  33. >>> rfc822_date_to_git('Sat, 5 Apr 2008 17:01:32 +0200')
  34. '1207407692 +0200'
  35. """
  36. d = dateutil.parser.parse(rfc822_date)
  37. seconds = calendar.timegm(d.utctimetuple())
  38. tz = d.strftime("%z")
  39. return '%d %s' % (seconds, tz)
  40. # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: