1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 """ This module is an helper to interface iMaker. """
21 import os
22 import re
23 import pathaddition.match
24 import fileutils
25 import tempfile
26 import subprocess
27
29 """ Specialize the abstract filescanner to support detection of the configuration. """
31 """ Implement scanning of relevant configuration. """
32 handle = subprocess.Popen("imaker help-config", shell=True, stdout=subprocess.PIPE).stdout
33 for line in handle.read().splitlines():
34 line = line.strip()
35 if line.startswith('/') and self.is_included(line) \
36 and not self.is_excluded(line):
37 yield line
38 handle.close()
39
41 """ Use iMaker to scan the available buildable configurations. """
42 scanner = IMakerConfigScanner()
43 for inc in includes:
44 scanner.add_include(inc)
45 for exc in excludes:
46 scanner.add_exclude(exc)
47 return [r for r in scanner.scan()]
48
50 """ Return the list of target supported by the provided configuration of iMaker. """
51 cmd = "imaker -f %s help-target-*-list" % config
52 (_, handle, child_stderr) = os.popen3(cmd)
53 result = []
54 print child_stderr.read()
55 for line in handle.read().splitlines():
56 line = line.strip()
57 if line == "" or line.startswith("Total duration"):
58 continue
59 result.append(line)
60 handle.close()
61 return result
62
63
67
68
69 -def get_variable(variable, target=None, product=None, config=None, default=None):
70 """ Get variable value from iMaker. """
71 cmdline = ""
72 if product != None:
73 cmdline = "-p%s" % product
74 if config != None:
75 cmdline += " -f %s" % config
76 if target != None:
77 cmdline += " %s" % target
78
79 logdir = tempfile.mkdtemp()
80 print "imaker %s print-%s WORKDIR=%s" % (cmdline, variable, logdir)
81 (_, handle, child_stderr) = os.popen3("imaker %s print-%s WORKDIR=%s" % (cmdline, variable, logdir))
82 print child_stderr.read()
83 result = []
84 for line in handle.read().splitlines():
85 line = line.strip()
86 if line == "" or line.startswith("Total duration"):
87 continue
88 if variable in line:
89 result.append(line)
90 handle.close()
91 result = re.match("%s\s*=\s*`(.*)'" % variable, "\n".join(result), re.DOTALL)
92 if result != None:
93 return result.group(1)
94 assert (result != None)
95 return default
96