annotate python/ppci/recipe.py @ 393:6ae782a085e0

Added init program
author Windel Bouwman
date Sat, 17 May 2014 21:17:40 +0200
parents 9667d78ba79e
children
rev   line source
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
1 #!/usr/bin/python3
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
2
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
3 import os
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
4 import xml.dom.minidom
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
5
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
6 from .tasks import Project, Target
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
7
353
b8ad45b3a573 Started with strings
Windel Bouwman
parents: 342
diff changeset
8
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
9 class RecipeLoader:
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
10 """ Loads a recipe into a runner from a dictionary or file """
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
11 def load_file(self, recipe_file):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
12 """ Loads a build configuration from file """
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
13 recipe_dir = os.path.abspath(os.path.dirname(recipe_file))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
14 dom = xml.dom.minidom.parse(recipe_file)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
15 project = self.load_project(dom)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
16 project.set_property('basedir', recipe_dir)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
17 return project
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
18
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
19 def load_project(self, elem):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
20 elem = elem.getElementsByTagName("project")[0]
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
21 name = elem.getAttribute('name')
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
22 project = Project(name)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
23 if elem.hasAttribute('default'):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
24 project.default = elem.getAttribute('default')
367
577ed7fb3fe4 Try to make thumb work again
Windel Bouwman
parents: 366
diff changeset
25 else:
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
26 project.default = None
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
27
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
28 for pe in elem.getElementsByTagName("property"):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
29 name = pe.getAttribute('name')
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
30 value = pe.getAttribute('value')
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
31 project.set_property(name, value)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
32 for te in elem.getElementsByTagName("target"):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
33 name = te.getAttribute('name')
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
34 target = Target(name, project)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
35 if te.hasAttribute('depends'):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
36 dependencies = te.getAttribute('depends').split(',')
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
37 for dep in dependencies:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
38 target.add_dependency(dep)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
39 # print(name)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
40 project.add_target(target)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
41 for cn in te.childNodes:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
42 # print(cn, type(cn))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
43 if type(cn) is xml.dom.minidom.Element:
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
44 task_name = cn.tagName
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
45 task_props = {}
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
46 for i in range(cn.attributes.length):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
47 atr = cn.attributes.item(i)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
48 #print(atr, atr.name, atr.value)
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
49 task_props[atr.name] = atr.value
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
50 target.add_task((task_name, task_props))
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
51 return project
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
52