26 """reads 'atlas def' files into atlas Objects"""
31 def parse_lines(self, lines, depth, parent_obj):
33 while self.
lineno < len(lines):
35 space_count=len(re.match(
"( *)",line).group(1))
37 if line[0]
in '#\n' or \
38 space_count==len(line)-1:
43 raise SyntaxError(
"Unexpected indentation",
52 rest=line[space_count:-1]
54 match=re.match(
"""([^"':]*):(.*)""",rest)
56 parts.append(match.group(1))
70 raise SyntaxError(
"Unexpected element numbers (things delimited with ':')",
83 value = last_obj =
Object()
84 last_obj.specification_file =
Object(attribute_order = [],
85 filename = os.path.basename(self.
filename),
89 if value[:3]==
'"""' and not value[-3:]==
'"""':
95 if not line
or line.find(
'"""')>=0:
104 setattr(parent_obj, name, value)
105 parent_obj.specification_file.attribute_order.append(name)
107 parent_obj.append(value)
115 lines = fp.readlines()
120 def syntax_error(self, msg, obj):
121 info = obj.specification_file
122 raise SyntaxError(
"%s at %s:%s" % (msg, info.filename, info.lineno))
125 """fill missing attributes and check for attribute definitions"""
128 find_parents_children_objects(self.
id_dict)
132 """fill id_dict with all objects"""
138 'Object with "'+id+
'"-id already exists', obj)
140 except AttributeError:
142 "Id attribute is not specified for object", obj)
144 def fill_children(self):
146 attr_order = obj.specification_file.attribute_order
148 parent_loc = attr_order.index(
"parent")
149 attr_order.insert(parent_loc+1,
"children")
151 self.
syntax_error(
"Parent attribute missing in %s" % obj.id, obj)
155 if pid
is not None and pid !=
"":
158 parent_obj.children.append(obj.id)
160 self.
syntax_error(
'Parent "%s" is missing in %s' % (pid, obj.id), obj)
163 """recursively check types for all objects"""
164 if isinstance(obj, list):
167 elif isinstance(obj, dict):
168 for name, value
in list(obj.items()):
175 self.
syntax_error(
'Name "'+name+
'" is not specified for type %s' % obj.id, obj)
177 self.
syntax_error(
'Name "'+name+
'" is not specified', obj)
178 should_be_type = get_atlas_type(value)
179 if not type_obj.has_parent(should_be_type):
181 'Type doesn\'t match or is not found: "'+name+
'"',obj)
183 def check_type(self):
189 def read_all_defs(filelist):
191 for file
in filelist:
192 parser.read_file(file)
197 if __name__==
"__main__":
198 filelist=[
"root",
"entity",
"operation",
"type"]
199 defs=read_all_defs([file+
".def" for file
in filelist])