aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml20
-rwxr-xr-xupdatezinfo.py53
2 files changed, 31 insertions, 42 deletions
diff --git a/.travis.yml b/.travis.yml
index ef539fc..1c12758 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,14 @@
language: python
-python: "3.4"
-env:
- - TOX_ENV=py26
- - TOX_ENV=py27
- - TOX_ENV=py32
- - TOX_ENV=py33
- - TOX_ENV=py34
+python:
+ - "2.6"
+ - "2.7"
+ - "3.2"
+ - "3.3"
+ - "3.4"
+ - "pypy"
+ - "pypy3"
install:
- - pip install tox
+ - pip install six
+ - python updatezinfo.py
script:
- - tox -e $TOX_ENV
+ - python test.py
diff --git a/updatezinfo.py b/updatezinfo.py
index 627231a..78708ca 100755
--- a/updatezinfo.py
+++ b/updatezinfo.py
@@ -1,44 +1,31 @@
#!/usr/bin/env python
import os
-import re
-import sys
+import hashlib
+
+from six.moves.urllib import request
from dateutil.zoneinfo import rebuild
-SERVER = "ftp.iana.org"
-DIR = "/tz"
-NAME = re.compile("tzdata(.*).tar.gz")
+
+# ad-hoc solution. TODO: use configuration file or something
+TZRELEASES = "ftp://ftp.iana.org/tz/releases/"
+TZFILEPATTERN = "tzdata{tag}.tar.gz"
+TZTAG = "2014j"
+SHA512 = "4c2979be3a96f91f8576304ec905d571b73df0842c8300c1d7317819b45ab3e29948ed911aa265b12a4ad587d5cba44f646dd02e40e4fbf9e68556a2d327142e"
+
+TZFILE = TZFILEPATTERN.format(tag=TZTAG)
def main():
- if len(sys.argv) == 2:
- tzdata = sys.argv[1]
- else:
- from ftplib import FTP
- print("Connecting to %s..." % SERVER)
- ftp = FTP(SERVER)
- print("Logging in...")
- ftp.login()
- print("Changing to %s..." % DIR)
- ftp.cwd(DIR)
- print("Listing files...")
- for name in ftp.nlst():
- if NAME.match(name):
- break
- else:
- sys.exit("error: file matching %s not found" % NAME.pattern)
- if os.path.isfile(name):
- print("Found local %s..." % name)
- else:
- print("Retrieving %s..." % name)
- file = open(name, "w")
- ftp.retrbinary("RETR "+name, file.write)
- file.close()
- ftp.close()
- tzdata = name
- if not tzdata or not NAME.match(tzdata):
- sys.exit("Usage: updatezinfo.py tzdataXXXXX.tar.gz")
+ if not os.path.isfile(TZFILE):
+ print("Downloading tz file from iana")
+ request.urlretrieve(TZRELEASES + TZFILE, TZFILE)
+ with open(TZFILE,'rb') as tzfile:
+ sha_hasher = hashlib.sha512()
+ sha_hasher.update(tzfile.read())
+ sha_512_file = sha_hasher.hexdigest()
+ assert SHA512 == sha_512_file, "SHA failed for downloaded tz file"
print("Updating timezone information...")
- rebuild(tzdata, NAME.match(tzdata).group(1))
+ rebuild(TZFILE, TZTAG)
print("Done.")
if __name__ == "__main__":