diff options
author | Guido Guenther <agx@sigxcpu.org> | 2008-04-14 14:08:28 +0200 |
---|---|---|
committer | Guido Guenther <agx@sigxcpu.org> | 2008-04-14 14:08:28 +0200 |
commit | a8992fe33881dcfff7b9cf04448eaa54f6afc219 (patch) | |
tree | d634d1050336241418052e0697e744ad7b14d9d0 | |
parent | 33b31ef170ed55454dc6ce60920d2825192d03f1 (diff) | |
download | git-buildpackage-a8992fe33881dcfff7b9cf04448eaa54f6afc219.tar.gz git-buildpackage-a8992fe33881dcfff7b9cf04448eaa54f6afc219.tar.bz2 git-buildpackage-a8992fe33881dcfff7b9cf04448eaa54f6afc219.zip |
add rfc822_date_to_git()
this function converts a date in RFC822 format to a string
'seconds_since_epoch tz' that can be used for eg. GIT_AUTHOR_DATE.
-rw-r--r-- | gbp/git_utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/gbp/git_utils.py b/gbp/git_utils.py index 72abdd95..af55c207 100644 --- a/gbp/git_utils.py +++ b/gbp/git_utils.py @@ -6,6 +6,8 @@ import subprocess import os.path from command_wrappers import (GitAdd, GitRm, copy_from) +import dateutil.parser +import calendar class GitRepositoryError(Exception): """Exception thrown by GitRepository""" @@ -135,4 +137,19 @@ def replace_source_tree(repo, src_dir, filters, verbose=False): GitRm(verbose=verbose)(files) return not repo.is_clean()[0] + +def rfc822_date_to_git(rfc822_date): + """Parse a date in RFC822 format, and convert to a 'seconds tz' string. + >>> rfc822_date_to_git('Thu, 1 Jan 1970 00:00:01 +0000') + '1 +0000' + >>> rfc822_date_to_git('Thu, 20 Mar 2008 01:12:57 -0700') + '1206000777 -0700' + >>> 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) + # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: |