@@ -34,7 +34,20 @@ def __init__(self, directory='.'):
3434 self .defaults = Defaults ()
3535 app .config ['cpu' ] = self .defaults .cpus .get (app .config ['arch' ],
3636 app .config ['arch' ])
37+ self .parse_files (directory )
38+ self ._check_trees ()
3739
40+ for path in self ._data :
41+ try :
42+ this = self ._data [path ]
43+ if this .get ('ref' ) and self ._trees .get (path ):
44+ if this ['ref' ] == self ._trees .get (path )[0 ]:
45+ this ['tree' ] = self ._trees .get (path )[1 ]
46+ except :
47+ app .log ('DEFINITIONS' , 'WARNING: problem with .trees file' )
48+ pass
49+
50+ def parse_files (self , directory ):
3851 schemas = self .load_schemas ()
3952 with app .chdir (directory ):
4053 for dirname , dirnames , filenames in os .walk ('.' ):
@@ -52,21 +65,9 @@ def __init__(self, directory='.'):
5265 self ._fix_keys (data )
5366 self ._tidy_and_insert_recursively (data )
5467
55- caches_are_valid = self ._check_trees ()
56- for path in self ._data :
57- try :
58- this = self ._data [path ]
59- if this .get ('ref' ) and self ._trees .get (path ):
60- if this ['ref' ] == self ._trees .get (path )[0 ]:
61- this ['tree' ] = self ._trees .get (path )[1 ]
62- except :
63- app .log ('DEFINITIONS' , 'WARNING: problem with .trees file' )
64- pass
65-
6668 if app .config .get ('mode' ) == 'parse-only' :
6769 with open (app .config ['result-file' ], 'w' ) as f :
68- f .write (json .dumps (self ._data , indent = 4 ,
69- sort_keys = True ))
70+ f .write (json .dumps (self ._data , indent = 4 , sort_keys = True ))
7071 app .log ('RESULT' , 'Parsed definitions data in json format is at' ,
7172 app .config ['result-file' ])
7273 os ._exit (0 )
@@ -90,15 +91,6 @@ def validate_schema(self, schemas, data):
9091 app .log (data , 'WARNING: schema validation failed:' )
9192 print e
9293
93- def write (self , output ):
94- for path in self ._data :
95- print path
96- for path in self ._data :
97- filename = self ._data [path ]['name' ] + '.cida'
98- with open (os .path .join (output , filename ), 'w' ) as f :
99- f .write (yaml .dump (self ._data [path ],
100- default_flow_style = False ))
101-
10294 def _load (self , path ):
10395 '''Load a single definition file as a dict.
10496
@@ -143,9 +135,8 @@ def _tidy_and_insert_recursively(self, item):
143135 # 'chunks' field in a stratum .morph file, or the 'strata' field in a
144136 # system .morph file.
145137 item ['contents' ] = item .get ('contents' , [])
146- for subset in ['chunks' , 'strata' ]:
147- for component in item .get (subset , []):
148- item ['contents' ] += [component ]
138+ for component in item .get ('chunks' , []) + item .get ('strata' , []):
139+ item ['contents' ] += [component ]
149140
150141 lookup = {}
151142 for index , component in enumerate (item .get ('contents' , [])):
@@ -165,7 +156,7 @@ def _tidy_and_insert_recursively(self, item):
165156
166157 return self ._insert (item )
167158
168- def _fix_keys (self , item , name = 'ERROR' ):
159+ def _fix_keys (self , item ):
169160 '''Normalizes keys for a definition dict and its contents
170161
171162 Some definitions have a 'morph' field which is a relative path. Others
@@ -176,8 +167,8 @@ def _fix_keys(self, item, name='ERROR'):
176167 the same as 'path' but replacing '/' by '-'
177168
178169 '''
179- item .setdefault ('path' , item .pop ('morph' , item .get ('name' , name )))
180- if item ['path' ] == 'ERROR' :
170+ item .setdefault ('path' , item .pop ('morph' , item .get ('name' , None )))
171+ if item ['path' ] is None :
181172 app .exit (item , 'ERROR: no path, no name?' )
182173 item .setdefault ('name' , item ['path' ])
183174 item ['name' ] = item ['name' ].replace ('/' , '-' )
0 commit comments