Skip to content

Commit 2a4bbd0

Browse files
committed
Adapt distrib/gen_gps.py to python3, minor formatting.
This comes from the GitHub pull request #50 no-tn-check Change-Id: I0f011449d5d4c3f71e10ee8620f2013ec826cb49
2 parents d8f5477 + 3944204 commit 2a4bbd0

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

distrib/gen_gps.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,46 @@
44
import os.path
55
import re
66

7-
pkg_re = re.compile("^(private)?\s*package\s*(\S+)")
7+
pkg_re = re.compile(r"^(private)?\s*package\s*(\S+)")
88

99

1010
def recursive_ls(dir):
1111
"""Return the list of ads files in dir and its subdirs"""
1212
result = set()
1313
for f in os.listdir(dir):
14+
path = os.path.join(dir, f)
1415
if f.endswith(".ads") \
1516
and f.startswith("gnatcoll-"):
1617

1718
private = False
1819
pkg = ""
19-
for l in file(os.path.join(dir, f)).readlines():
20-
m = pkg_re.search(l)
21-
if m:
22-
private = m.group(1)
23-
pkg = m.group(2)
24-
break
20+
with open(path) as h:
21+
for line in h.readlines():
22+
m = pkg_re.search(line)
23+
if m:
24+
private = m.group(1)
25+
pkg = m.group(2)
26+
break
2527

2628
if not private:
2729
result.add((pkg, os.path.splitext(f)[0]))
2830

29-
elif os.path.isdir(os.path.join(dir, f)):
30-
result = result.union(recursive_ls(os.path.join(dir, f)))
31+
elif os.path.isdir(path):
32+
result = result.union(recursive_ls(path))
3133

3234
return result
3335

36+
3437
list = recursive_ls("../src")
35-
out = file("gnatcoll/runtime.py", "wb")
36-
out.write("""XML = r'''<?xml version="1.0"?>
38+
with open("gnatcoll/runtime.py", "w") as out:
39+
out.write("""XML = r'''<?xml version="1.0"?>
3740
<GPS>
3841
""")
3942

40-
for pkg, f in sorted(list):
41-
if '__' in f:
42-
# An internal package with a specific naming scheme
43-
continue
43+
for pkg, f in sorted(list):
44+
if '__' in f:
45+
# An internal package with a specific naming scheme
46+
continue
4447

4548
menu = pkg.replace(".", "/").replace("_", "__")
4649

@@ -61,8 +64,7 @@ def recursive_ls(dir):
6164
6265
""" % {"file": f, "menu": menu, "package": pkg})
6366

64-
out.write("""</GPS>'''
67+
out.write("""</GPS>'''
6568
import GPS
6669
GPS.parse_xml(XML)
6770
""")
68-
out.close()

0 commit comments

Comments
 (0)