377
|
1 #!/usr/bin/python3
|
342
|
2
|
377
|
3 import os
|
|
4 import xml.dom.minidom
|
|
5
|
|
6 from .tasks import Project, Target
|
342
|
7
|
353
|
8
|
342
|
9 class RecipeLoader:
|
|
10 """ Loads a recipe into a runner from a dictionary or file """
|
377
|
11 def load_file(self, recipe_file):
|
|
12 """ Loads a build configuration from file """
|
|
13 recipe_dir = os.path.abspath(os.path.dirname(recipe_file))
|
|
14 dom = xml.dom.minidom.parse(recipe_file)
|
|
15 project = self.load_project(dom)
|
|
16 project.set_property('basedir', recipe_dir)
|
|
17 return project
|
342
|
18
|
377
|
19 def load_project(self, elem):
|
|
20 elem = elem.getElementsByTagName("project")[0]
|
|
21 name = elem.getAttribute('name')
|
|
22 project = Project(name)
|
|
23 if elem.hasAttribute('default'):
|
|
24 project.default = elem.getAttribute('default')
|
367
|
25 else:
|
377
|
26 project.default = None
|
342
|
27
|
377
|
28 for pe in elem.getElementsByTagName("property"):
|
|
29 name = pe.getAttribute('name')
|
|
30 value = pe.getAttribute('value')
|
|
31 project.set_property(name, value)
|
|
32 for te in elem.getElementsByTagName("target"):
|
|
33 name = te.getAttribute('name')
|
|
34 target = Target(name, project)
|
|
35 if te.hasAttribute('depends'):
|
|
36 dependencies = te.getAttribute('depends').split(',')
|
|
37 for dep in dependencies:
|
|
38 target.add_dependency(dep)
|
|
39 # print(name)
|
|
40 project.add_target(target)
|
|
41 for cn in te.childNodes:
|
|
42 # print(cn, type(cn))
|
|
43 if type(cn) is xml.dom.minidom.Element:
|
|
44 task_name = cn.tagName
|
|
45 task_props = {}
|
|
46 for i in range(cn.attributes.length):
|
|
47 atr = cn.attributes.item(i)
|
|
48 #print(atr, atr.name, atr.value)
|
|
49 task_props[atr.name] = atr.value
|
|
50 target.add_task((task_name, task_props))
|
|
51 return project
|
342
|
52
|