Skip to content

Commit 0c3fada

Browse files
committed
args.root actually works
1 parent 5822c75 commit 0c3fada

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

tools/format_tzdata.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pathlib
1212
import re
1313
import sys
14+
import pathlib
1415

1516
from importlib import resources
1617

@@ -57,19 +58,20 @@ def tzdata_resource_from_name(name):
5758
return resources.files(f'tzdata.zoneinfo.{pair[0].replace("/", ".")}') / pair[1]
5859

5960

60-
def make_zones_list(zones):
61-
with open(zones, "r") as f:
62-
zones = [zone.strip() for zone in f.readlines()]
63-
64-
return zones
61+
def make_zones_list(f):
62+
return [zone.strip() for zone in f.readlines()]
6563

6664

6765
def make_zones(args):
6866
out = []
6967

7068
for zone in make_zones_list(args.zones):
71-
target = tzdata_resource_from_name(zone)
72-
with tzdata_resource_from_name(zone).open("rb") as f:
69+
if args.root:
70+
target = args.root / zone
71+
else:
72+
target = tzdata_resource_from_name(zone)
73+
74+
with target.open("rb") as f:
7375
magic = f.read(4)
7476
if magic != b"TZif":
7577
continue
@@ -138,7 +140,7 @@ def header(zones):
138140
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
139141
parser.add_argument(
140142
"--output",
141-
type=argparse.FileType("w"),
143+
type=argparse.FileType("w", encoding="utf-8"),
142144
default=sys.stdout,
143145
)
144146
parser.add_argument(
@@ -148,13 +150,14 @@ def header(zones):
148150
)
149151
parser.add_argument(
150152
"--zones",
151-
help="Zone names, one per line",
153+
type=argparse.FileType("r", encoding="utf-8"),
154+
help="Zone names file, one per line",
152155
default=os.path.join(os.path.dirname(tzdata.__file__), "zones"),
153156
)
154157
parser.add_argument(
155158
"--root",
156159
help="Where do we get raw zoneinfo files from",
157-
default=os.path.join(os.path.dirname(tzdata.__file__), "zoneinfo"),
160+
type=pathlib.Path,
158161
)
159162

160163
args = parser.parse_args()

0 commit comments

Comments
 (0)