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

Source Code for Package vbaconf

+
+  1  #============================================================================  
+  2  #Name        : __init__.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  """ Helper to convert delivery.xml and prep.xml to VirtualBuildArea 
+ 21      configuration file. 
+ 22  """ 
+ 23  from  xml.dom.minidom import getDOMImplementation 
+ 24  import amara 
+ 25  import ccm 
+ 26  import re 
+ 27  import os.path 
+ 28  import sys 
+ 29  import configuration 
+ 30   
+
31 -def cleanup_path(path): +
32 """ Returns path without any sequence of '/' and replacing '\' by '/' """ + 33 return re.sub(r'/+', '/', re.sub(r'\\', '/', path)) +
34 +
35 -def generate_config(deliveryinput, prepinput): +
36 """ deliveryinput: path to delivery conf file (old format). + 37 prepinput: path to the prep conf file. + 38 Return XML Document object. + 39 """ + 40 impl = getDOMImplementation() + 41 doc = getDOMImplementation().createDocument(None, "virtualBuildArea", None) + 42 vba = doc.getElementsByTagName("virtualBuildArea")[0] + 43 + 44 # Loading delivery content + 45 delivery = amara.parse(open(deliveryinput, 'r')) + 46 # loading prep file + 47 prep = amara.parse(open(prepinput, 'r')) + 48 # analysing preparation creation + 49 for source in prep.xml_xpath('/prepSpec/source'): + 50 basedir = cleanup_path(source.basedir) + 51 for copy in source.xml_xpath('./copy'): + 52 src = cleanup_path(copy.name) + 53 for p in delivery.xml_xpath('/deliveryConfiguration/*'): + 54 ccmp = ccm.FourPartName(p.project) + 55 p_dir = cleanup_path(p.dir) + 56 #print "ccmp: %s" % ccmp + 57 #print "pdir: %s" % p_dir + 58 # looking for project_name/project_name pattern, and if dest doesn't exist + 59 if (re.match(r"%s/%s" % (ccmp.name, ccmp.name), src, re.I) is not None) and not hasattr(copy, 'dest'): + 60 print "All object from root." + 61 add = doc.createElementNS("", "add") + 62 add.setAttributeNS("", "project", str(ccmp)) + 63 vba.appendChild(add) + 64 objs = doc.createElementNS("", "objects") + 65 objs.setAttributeNS("", "from", ccmp.name) + 66 add.appendChild(objs) + 67 # looking for project_name/project_name pattern, and if dest exists + 68 elif (re.match(r"%s/%s" % (ccmp.name, ccmp.name), src, re.I) is not None) and hasattr(copy, 'dest'): + 69 if os.path.basename(copy.dest).lower() == ccmp.name.lower(): + 70 add = doc.createElementNS("", "add") + 71 add.setAttributeNS("", "project", str(ccmp)) + 72 add.setAttributeNS("", "to", cleanup_path('/' + os.path.dirname(copy.dest))) + 73 vba.appendChild(add) + 74 else: + 75 add = doc.createElementNS("", "add") + 76 add.setAttributeNS("", "project", str(ccmp)) + 77 add.setAttributeNS("", "to", cleanup_path('/' + copy.dest)) + 78 vba.appendChild(add) + 79 # for directory copy + 80 elif cleanup_path(basedir + "/" + src) == p_dir: + 81 print "Adding to subdirectory" + 82 print ccmp.name, basedir + "/" + src, p_dir + 83 add = doc.createElementNS("", "add") + 84 add.setAttributeNS("", "project", str(ccmp)) + 85 if hasattr(copy, 'dest'): + 86 add.setAttributeNS("", "to", cleanup_path('/' + copy.dest + '/' + ccmp.name)) + 87 else: + 88 add.setAttributeNS("", "to", cleanup_path('/'+ ccmp.name)) + 89 vba.appendChild(add) + 90 elif p_dir.startswith(cleanup_path(basedir + "/" + src + '/')): + 91 print "Adding to subdirectory" + 92 delta = p_dir[len(cleanup_path(basedir)):] + 93 add = doc.createElementNS("", "add") + 94 add.setAttributeNS("", "project", str(ccmp)) + 95 if hasattr(copy, 'dest'): + 96 add.setAttributeNS("", "to", cleanup_path('/' + os.path.dirname(copy.dest) + '/' + delta + '/' + ccmp.name)) + 97 else: + 98 add.setAttributeNS("", "to", cleanup_path(delta + '/' + ccmp.name)) + 99 vba.appendChild(add) +100 return doc +
101 +102 +103 +
104 -class AbstractConfigConverter: +
105 +
106 - def __init__(self): +
107 pass +
108 +
109 - def _get_projects_configs(self): +
110 raise Exception("Todo: not implemented.") +
111 +
112 - def _get_prep_configs(self): +
113 raise Exception("Todo: not implemented.") +
114 +
115 - def generate_config(self): +
116 """ deliveryinput: path to delivery conf file (old format). +117 prepinput: path to the prep conf file. +118 Return XML Document object. +119 """ +120 impl = getDOMImplementation() +121 doc = getDOMImplementation().createDocument(None, "virtualBuildArea", None) +122 vba = doc.getElementsByTagName("virtualBuildArea")[0] +123 +124 # analysing preparation creation +125 for copy in self._get_prep_configs(): +126 basedir = cleanup_path(copy.basedir) +127 src = cleanup_path(copy.name) +128 for p in self._get_projects_configs(): +129 ccmp = ccm.FourPartName(p.project) +130 p_dir = cleanup_path(p.dir) +131 #print "ccmp: %s" % ccmp +132 #print "pdir: %s" % p_dir +133 # looking for project_name/project_name pattern, and if dest doesn't exist +134 if (re.match(r"%s/%s" % (ccmp.name, ccmp.name), src, re.I) is not None) and not hasattr(copy, 'dest'): +135 print "All object from root." +136 add = doc.createElementNS("", "add") +137 add.setAttributeNS("", "project", str(ccmp)) +138 vba.appendChild(add) +139 objs = doc.createElementNS("", "objects") +140 objs.setAttributeNS("", "from", ccmp.name) +141 add.appendChild(objs) +142 # looking for project_name/project_name pattern, and if dest exists +143 elif (re.match(r"%s/%s" % (ccmp.name, ccmp.name), src, re.I) is not None) and hasattr(copy, 'dest'): +144 if os.path.basename(copy.dest).lower() == ccmp.name.lower(): +145 add = doc.createElementNS("", "add") +146 add.setAttributeNS("", "project", str(ccmp)) +147 add.setAttributeNS("", "to", cleanup_path('/' + os.path.dirname(copy.dest))) +148 vba.appendChild(add) +149 else: +150 add = doc.createElementNS("", "add") +151 add.setAttributeNS("", "project", str(ccmp)) +152 add.setAttributeNS("", "to", cleanup_path('/' + copy.dest)) +153 vba.appendChild(add) +154 # for directory copy +155 elif cleanup_path(basedir + "/" + src) == p_dir: +156 print "Adding to subdirectory" +157 print ccmp.name, basedir + "/" + src, p_dir +158 add = doc.createElementNS("", "add") +159 add.setAttributeNS("", "project", str(ccmp)) +160 if hasattr(copy, 'dest'): +161 add.setAttributeNS("", "to", cleanup_path('/' + copy.dest + '/' + ccmp.name)) +162 else: +163 add.setAttributeNS("", "to", cleanup_path('/'+ ccmp.name)) +164 vba.appendChild(add) +165 elif p_dir.startswith(cleanup_path(basedir + "/" + src + '/')): +166 print "Adding to subdirectory" +167 delta = p_dir[len(cleanup_path(basedir)):] +168 add = doc.createElementNS("", "add") +169 add.setAttributeNS("", "project", str(ccmp)) +170 if hasattr(copy, 'dest'): +171 add.setAttributeNS("", "to", cleanup_path('/' + os.path.dirname(copy.dest) + '/' + delta + '/' + ccmp.name)) +172 else: +173 add.setAttributeNS("", "to", cleanup_path(delta + '/' + ccmp.name)) +174 vba.appendChild(add) +175 return doc +
176 +177 +
178 -class ConfigConverter(AbstractConfigConverter): +
179 - def __init__(self, deliveryinput, prepinput): +
180 AbstractConfigConverter.__init__(self) +181 self._deliveryinput = deliveryinput +182 self._prepinput = prepinput +
183 +
184 - def _get_projects_configs(self): +
185 # Loading delivery content +186 delivery = amara.parse(open(self._deliveryinput, 'r')) +187 return delivery.xml_xpath('/deliveryConfiguration/*') +
188 +
189 - def _get_prep_configs(self): +
190 # loading prep file +191 prep = amara.parse(open(self._prepinput, 'r')) +192 class __ConfigWrapper: +193 """ wrapper object to access directly conf property. """ +194 def __init__(self, source, config): +195 self.basedir = source.basedir +196 self.name = config.name +197 if hasattr(copy, 'dest'): +198 self.dest = copy.dest +
199 +200 result = [] +201 for source in prep.xml_xpath('/prepSpec/source'): +202 for copy in source.xml_xpath('./copy'): +203 result.append(__ConfigWrapper(source, copy)) +204 return result +205 +206 +
207 -class ConfigConverterNewDelivery(ConfigConverter): +
208 - def __init__(self, deliveryinput, prepinput): +
209 ConfigConverter.__init__(self, deliveryinput, prepinput) +210 configBuilder = configuration.NestedConfigurationBuilder(open(self._deliveryinput, 'r')) +211 self.__configs = configBuilder.getConfiguration().getConfigurations() +
212 +
213 - def _get_projects_configs(self): +
214 class __ConfigWrapper: +215 """ wrapper object to access directly conf property. """ +216 def __init__(self, config): +217 self.project = config.name +218 self.dir = config['dir'] +
219 # Loading delivery content +220 return map(lambda c: __ConfigWrapper(c), self.__configs) +221 +
+
+ + + + + + + + + + + + + + + + + + + + + +
+ + + + +