44import os .path
55import 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
1010def 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+
3437list = 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>'''
6568import GPS
6669GPS.parse_xml(XML)
6770""" )
68- out .close ()
0 commit comments