diff -r 7685cec9fd3c -r f2ddfa555b0f doc/api/python/imaker.ant-pysrc.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/api/python/imaker.ant-pysrc.html Fri Sep 11 11:54:49 2009 +0100 @@ -0,0 +1,454 @@ + + + + + imaker.ant + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Package imaker :: + Module ant + + + + + + +
[hide private]
[frames] | no frames]
+
+

Source Code for Module imaker.ant

+
+  1  #============================================================================  
+  2  #Name        : ant.py  
+  3  #Part of     : Helium  
+  4   
+  5  #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+  6  #All rights reserved. 
+  7  #This component and the accompanying materials are made available 
+  8  #under the terms of the License "Eclipse Public License v1.0" 
+  9  #which accompanies this distribution, and is available 
+ 10  #at the URL "http://www.eclipse.org/legal/epl-v10.html". 
+ 11  # 
+ 12  #Initial Contributors: 
+ 13  #Nokia Corporation - initial contribution. 
+ 14  # 
+ 15  #Contributors: 
+ 16  # 
+ 17  #Description: 
+ 18  #=============================================================================== 
+ 19   
+ 20  """ 
+ 21      iMaker related functionalities. 
+ 22      * configuration introspection 
+ 23      * target introspection  
+ 24  """ 
+ 25  import os 
+ 26  import pathaddition.match 
+ 27  import re 
+ 28  import fileutils 
+ 29  import imaker.api 
+ 30   
+
31 -def ant_run(task, config, target, variables=None): +
32 """ Running iMaker under Ant. """ + 33 if variables == None: + 34 variables = {} + 35 cmdline = "imaker" + 36 cmdline += " -f %s" % config + 37 cmdline += " %s" % target + 38 for key in variables.keys(): + 39 cmdline += ' "%s=%s"' % (key, variables[key]) + 40 # run imaker and log to Ant. + 41 task.log("Running %s" % cmdline) + 42 handle = os.popen(cmdline) + 43 for line in handle.read().splitlines(): + 44 task.log(line) + 45 return handle.close() +
46 + 47 +
48 -def is_included(incs, target): +
49 """ Does target matches an include pattern. """ + 50 for inc in incs: + 51 if inc.match(target): + 52 return True + 53 return False +
54 +
55 -def is_excluded(excs, target): +
56 """ Does target matches an exclude pattern. """ + 57 for exc in excs: + 58 if exc.match(target): + 59 return True + 60 return False +
61 + 62 +
63 -def ant_task_configuration(project, task, elements, attributes): +
64 """ Implementation of the Ant task. """ + 65 # assert attributes.get('property') != None, "'property' attribute is not defined." + 66 if attributes.get('dir') != None: + 67 os.chdir(str(attributes.get('dir'))) + 68 tdd = "[\n" + 69 if elements.get("imakerconfigurationset") is not None: + 70 if elements.get("imakerconfigurationset").size() == 0: + 71 task.log(str("No configuration defined.")) + 72 for cid in range(elements.get("imakerconfigurationset").size()): + 73 configurationset = elements.get("imakerconfigurationset").get(int(cid)) + 74 if configurationset.isReference() == 1: + 75 task.log("Using configuration from reference '%s'." % str(configurationset.getRefid().getRefId())) + 76 ref = project.getReference(str(configurationset.getRefid().getRefId())) + 77 if ref == None: + 78 raise Exception("Could not find reference '%s'" % str(configurationset.getRefid().getRefId())) + 79 configurationset = ref + 80 for configuration in configurationset.getImakerConfiguration().toArray(): + 81 tdd += handle_configuration(project, task, elements, attributes, configuration) + 82 else: + 83 task.log(str("No configuration defined.")) + 84 tdd += "]\n" + 85 + 86 if attributes.get('property') != None: + 87 task.log("Setting property '%s'." % str(attributes.get('property'))) + 88 project.setProperty(str(attributes.get('property')), str(tdd)) + 89 if attributes.get('file') != None: + 90 task.log("Creating file '%s'." % str(attributes.get('file'))) + 91 out = open(str(attributes.get('file')), "w") + 92 out.write(tdd) + 93 out.close() +
94 +
95 -def handle_configuration(project, task, elements, attributes, configuration): +
96 """ Convert a configuration into a TDD for future FMPP transformation. """ + 97 includes = [] + 98 excludes = [] + 99 tincludes = [] +100 texcludes = [] +101 variables = {} +102 +103 for configs in configuration.getMakefileSet().toArray(): +104 incs = configs.getIncludePatterns(project) +105 if incs is not None: +106 for inc in incs: +107 includes.append(str(inc)) +108 excs = configs.getExcludePatterns(project) +109 if excs is not None: +110 for exc in excs: +111 excludes.append(str(exc)) +112 +113 for targets in configuration.getTargetSet().toArray(): +114 incs = targets.getIncludePatterns(project) +115 if incs is not None: +116 for inc in incs: +117 tincludes.append(re.compile(str(inc))) +118 excs = targets.getExcludePatterns(project) +119 if excs is not None: +120 for exc in excs: +121 texcludes.append(re.compile(str(exc))) +122 if len(tincludes) == 0: +123 tincludes.append(re.compile(r".*")) +124 +125 # Reading the variables +126 for variableset in configuration.getVariableSet().toArray(): +127 vector = variableset.getVariables() +128 for variable in vector.toArray(): +129 variables[str(variable.getName())] = str(variable.getValue()) +130 +131 configs = imaker.api.scan_configs(includes, excludes) +132 targets = {} +133 for config in configs: +134 task.log("Configuration: %s" % config) +135 if config not in targets: +136 targets[config] = [] +137 for target in imaker.api.targets_for_config(config): +138 if is_included(tincludes, target) and not is_excluded(texcludes, target)\ +139 and target not in targets[config]: +140 targets[config].append(target) +141 +142 task.log(str("Regional variation: %s" % configuration.getRegionalVariation())) +143 if configuration.getRegionalVariation(): +144 task.log("Sorting target by region.") +145 regiontargets = {} +146 for config in targets.keys(): +147 task.log(" * %s:" % config) +148 for target in targets[config]: +149 region = imaker.api.get_variable('LANGPACK_REGION', target=target, config=config, default="western") +150 task.log(" - %s: %s" % (target, region)) +151 if not regiontargets.has_key(region): +152 regiontargets[region] = {} +153 if not regiontargets[region].has_key(config): +154 regiontargets[region][config] = [] +155 regiontargets[region][config].append(target) +156 # sort by region +157 tdd = "" +158 for region in regiontargets.keys(): +159 tdd += region_switch_to_tdd(region) +160 tdd += imaker_command_to_tdd(regiontargets[region], variables) +161 return tdd +162 +163 # generating the TDD +164 return imaker_command_to_tdd(targets, variables) +
165 +166 +
167 -def region_switch_to_tdd(region): +
168 tdd = "{\n" +169 tdd += "\t\"command\": \"switch_region\",\n" +170 tdd += "\t\"region\": \"%s\",\n" % region +171 tdd += "},\n" +172 return tdd +
173 +174 +
175 -def imaker_command_to_tdd(targets, variables): +
176 # generating the TDD +177 tdd = "{\n" +178 tdd += "\t\"command\": \"imaker\",\n" +179 tdd += "\t\"config\": {\n" +180 for config in targets.keys(): +181 tdd += "\t\t\"%s\": [\n" % config +182 for target in targets[config]: +183 tdd += "\t\t\t{\n" +184 tdd += "\t\t\t\"target\": \"%s\",\n" % target +185 tdd += "\t\t\t\"variables\": {\n" +186 for varname in variables.keys(): +187 tdd += "\t\t\t\t\"%s\": \"%s\",\n" % (varname, variables[varname]) +188 tdd += "\t\t\t\t},\n" +189 tdd += "\t\t\t},\n" +190 tdd += "\t\t],\n" +191 tdd += "\t},\n" +192 tdd += "},\n" +193 return tdd +
194 +
+
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + +