Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/dateutil/zoneinfo/rebuild.py
7801 views
import logging1import os2import tempfile3import shutil4import json5from subprocess import check_call, check_output6from tarfile import TarFile78from dateutil.zoneinfo import METADATA_FN, ZONEFILENAME91011def rebuild(filename, tag=None, format="gz", zonegroups=[], metadata=None):12"""Rebuild the internal timezone info in dateutil/zoneinfo/zoneinfo*tar*1314filename is the timezone tarball from ``ftp.iana.org/tz``.1516"""17tmpdir = tempfile.mkdtemp()18zonedir = os.path.join(tmpdir, "zoneinfo")19moduledir = os.path.dirname(__file__)20try:21with TarFile.open(filename) as tf:22for name in zonegroups:23tf.extract(name, tmpdir)24filepaths = [os.path.join(tmpdir, n) for n in zonegroups]2526_run_zic(zonedir, filepaths)2728# write metadata file29with open(os.path.join(zonedir, METADATA_FN), 'w') as f:30json.dump(metadata, f, indent=4, sort_keys=True)31target = os.path.join(moduledir, ZONEFILENAME)32with TarFile.open(target, "w:%s" % format) as tf:33for entry in os.listdir(zonedir):34entrypath = os.path.join(zonedir, entry)35tf.add(entrypath, entry)36finally:37shutil.rmtree(tmpdir)383940def _run_zic(zonedir, filepaths):41"""Calls the ``zic`` compiler in a compatible way to get a "fat" binary.4243Recent versions of ``zic`` default to ``-b slim``, while older versions44don't even have the ``-b`` option (but default to "fat" binaries). The45current version of dateutil does not support Version 2+ TZif files, which46causes problems when used in conjunction with "slim" binaries, so this47function is used to ensure that we always get a "fat" binary.48"""4950try:51help_text = check_output(["zic", "--help"])52except OSError as e:53_print_on_nosuchfile(e)54raise5556if b"-b " in help_text:57bloat_args = ["-b", "fat"]58else:59bloat_args = []6061check_call(["zic"] + bloat_args + ["-d", zonedir] + filepaths)626364def _print_on_nosuchfile(e):65"""Print helpful troubleshooting message6667e is an exception raised by subprocess.check_call()6869"""70if e.errno == 2:71logging.error(72"Could not find zic. Perhaps you need to install "73"libc-bin or some other package that provides it, "74"or it's not in your PATH?")757677