comparison env/lib/python3.9/site-packages/dateutil/zoneinfo/rebuild.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 import logging
2 import os
3 import tempfile
4 import shutil
5 import json
6 from subprocess import check_call
7 from tarfile import TarFile
8
9 from dateutil.zoneinfo import METADATA_FN, ZONEFILENAME
10
11
12 def rebuild(filename, tag=None, format="gz", zonegroups=[], metadata=None):
13 """Rebuild the internal timezone info in dateutil/zoneinfo/zoneinfo*tar*
14
15 filename is the timezone tarball from ``ftp.iana.org/tz``.
16
17 """
18 tmpdir = tempfile.mkdtemp()
19 zonedir = os.path.join(tmpdir, "zoneinfo")
20 moduledir = os.path.dirname(__file__)
21 try:
22 with TarFile.open(filename) as tf:
23 for name in zonegroups:
24 tf.extract(name, tmpdir)
25 filepaths = [os.path.join(tmpdir, n) for n in zonegroups]
26 try:
27 check_call(["zic", "-d", zonedir] + filepaths)
28 except OSError as e:
29 _print_on_nosuchfile(e)
30 raise
31 # write metadata file
32 with open(os.path.join(zonedir, METADATA_FN), 'w') as f:
33 json.dump(metadata, f, indent=4, sort_keys=True)
34 target = os.path.join(moduledir, ZONEFILENAME)
35 with TarFile.open(target, "w:%s" % format) as tf:
36 for entry in os.listdir(zonedir):
37 entrypath = os.path.join(zonedir, entry)
38 tf.add(entrypath, entry)
39 finally:
40 shutil.rmtree(tmpdir)
41
42
43 def _print_on_nosuchfile(e):
44 """Print helpful troubleshooting message
45
46 e is an exception raised by subprocess.check_call()
47
48 """
49 if e.errno == 2:
50 logging.error(
51 "Could not find zic. Perhaps you need to install "
52 "libc-bin or some other package that provides it, "
53 "or it's not in your PATH?")