From d722aad590e82cf547f291e8641b4e5bfd712af5 Mon Sep 17 00:00:00 2001 From: Yaron de Leeuw Date: Thu, 20 Nov 2014 22:36:52 +0200 Subject: change updatezinfo, and travis config chnaged updatezinfo to download a specific tag (e.g. 2014j), and checksum it. Also make travis create it's own python envs, and run updatezinfo. Without downloading the file it fails. --- .travis.yml | 20 +++++++++++--------- updatezinfo.py | 53 ++++++++++++++++++++--------------------------------- 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__": -- cgit v1.2.3