45"""Split the specfile to its parts"""
+ 46attributes={}
+ 47properties={}
+ 48builder=configuration.NestedConfigurationBuilder(specfile)
+ 49configs=builder.getConfigurations()
+ 50# the supported configs are either attributes or properties
+ 51# collect each in a dictionary and return them.
+ 52forconfiginconfigs:
+ 53ifconfig.name=='attributes':
+ 54forattrinconfig:
+ 55attributes[attr]=config[attr]
+ 56ifconfig.name=='properties':
+ 57forpropinconfig:
+ 58properties[prop]=config[prop]
+ 59return(properties,attributes)
+
63"""
+ 64 Parser for CPP tool output. Returns cleaned output from the execution
+ 65 of CPP with or without parent paths included in the output.
+ 66 """
+ 67
+
72"""
+ 73 To clean out conditionals from the compilation it is necessary to
+ 74 use C preprocessing to clean out those.
+ 75
+ 76 If ('n' - normal) output is chosen, parser returns list of paths
+ 77 If ('e' - extended) output is chosen parser returns list of (path, parent_path) tuples
+ 78 If ('d' - dependency) output is chosen parser returns a dicitionary (can be a nested dictionary)
+ 79 of paths dependency (-ies).
+ 80
+ 81 'imacros' can also be given as parameters for CPP options.
+ 82
+ 83 if bld file is not given, the function will try to find the file(s) on the given location with extension ".inf"
+ 84 """
+ 85
+ 86clean_path_list=[]
+ 87path_list=[]
+ 88temp_path=os.getcwd()
+ 89if"bld.inf"instr(bld_path).lower():
+ 90os.chdir(os.path.normpath(os.path.join(bld_path,os.pardir)))
+ 91else:
+ 92os.chdir(os.path.normpath(os.path.join(bld_path)))
+ 93ifimacrosisnotNone:
+ 94command=u"cpp -imacros %s bld.inf"%str(imacros)
+ 95else:
+ 96command=u"cpp bld.inf"
+ 97process=subprocess.Popen(command,shell=True,stdout=subprocess.PIPE)
+ 98pipe=process.stdout
+ 99
+100ifoutput_parameter=="d":
+101returnself.create_dependency_dictionary(pipe,bld_path)
+102
+103forlineinpipe.readlines():
+104ifre.search(r"\A#\s.*?",line.strip())orre.search(r"\A#.*?[0-9]",line.strip()):
+105ifline.strip()notinpath_list:
+106path_list.append(line.strip())
+107process.wait()
+108ifprocess.returncode==1:
+109_logger.error('CPP failed: '+command+' in: '+os.getcwd())
+110pipe.close()
+111
+112os.chdir(temp_path)
+113ifoutput_parameteris"n":
+114for_pathinself.clean_cpp_output(bld_path,path_list):
+115clean_path_list.append(_path[0])
+116elifoutput_parameteris"e":
+117clean_path_list=self.clean_cpp_output(bld_path,path_list)
+118
+119clean_path_list=list(set(clean_path_list))
+120
+121bfp=BldFileParser()
+122
+123fortsrcinclean_path_list:
+124mmp_path=bfp.get_test_mmp_files(tsrc[0])
+125iftsrc[0]==tsrc[1]:
+126ifmmp_path==Noneormmp_path==[]:
+127clean_path_list.remove(tsrc)
+128
+129returnclean_path_list
+
219"""
+220 The output from CPP needs to be "cleaned" so that extra chars needs
+221 to be removed and also hierarchy which cpp is following is preserved
+222 and returned as an output.
+223 """
+224
+225pat=""
+226value=""
+227cleaned_output=[]
+228if"bld.inf"inbld_path:
+229path_to_parent=os.path.dirname(bld_path)
+230else:
+231path_to_parent=bld_path
+232pat=re.compile(r'\A#\s*?.*?[\"](.*?)[\"].*?')
+233for_pathinpath_list:
+234ifre.match(r".*[bld.inf]\s*?[^0-9]\Z",string.strip(string.lower(_path))):
+235value=pat.match(_path.strip())
+236path_to_tc=os.path.dirname(os.path.normpath(os.path.join((bld_path),value.group(1))))
+237cleaned_output.append((path_to_tc,path_to_parent))
+238ifre.match(r".*[1]\s*?\Z",string.strip(string.lower(_path))):
+239value=pat.match(_path.strip())
+240path_to_tc=os.path.dirname(os.path.normpath(os.path.join(bld_path,value.group(1))))
+241cleaned_output.append((path_to_tc,path_to_parent))
+242ifre.match(r".*[2]\s*?\Z",string.strip(string.lower(_path))):
+243ifcleaned_output:
+244forcoutincleaned_output:
+245ifstring.lower(path_to_parent)==string.lower(cout[0]):
+246path_to_tc=cout[1]
+247path_to_parent=path_to_tc
+248returncleaned_output
+
265"""
+266 returns a list of test mmp files
+267 Usage: if "x:\abc\bldfile", "PRJ_TESTMMPFILES".
+268 1. get_test_mmp_files("x:\abc\bldfile") - with full paths e.g. ["x:\abc\abc.mmp"]
+269 2. get_test_mmp_files("x:\abc\bldfile", False) - without full paths e.g. ["abc.mmp"]
+270
+271 if bld file is not given, the function will try to find the file(s) on the given location with extension ".inf"
+272 """
+273
+274ifbld_file_path==None:
+275_logger.warning("Incorrect bld file")
+276returnNone
+277else:
+278self.bld_file_path=path(bld_file_path)
+279ifnot"bld.inf"instr(self.bld_file_path).lower():
+280self.bld_file_path=os.path.join(os.path.normpath(self.bld_file_path),"bld.inf")
+281
+282ifnotos.path.exists(self.bld_file_path):
+283_logger.error(r"bld file path does not exist: '%s'"%self.bld_file_path)
+284returnNone
+285
+286returnself.get_files(path(self.bld_file_path),"PRJ_TESTMMPFILES",with_full_path)
+
358"""
+359 Parser for .mmp files. Returns wanted information from the mmp-file
+360 - file type (executable dll, plugin, exe, etc)
+361 - test harness (STIF, EUNIT) if mmp is related to the test component
+362 - file name
+363 - libraries listed in the mmp
+364 """
+365
+
370"""
+371 Filetype given using TARGETTYPE in .mmp file is returned.
+372 If "c:\path\to\mmp" is a location where mmp file is stored
+373 get_target_filetype("c:\path\to\mmp")
+374
+375 if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp"
+376 """
+377returnself.read_information_from_mmp(path_to_mmp,4)
+
380"""
+381 Filename given using TARGET in .mmp file is returned
+382 If "c:\path\to\mmp" is a location where mmp file is stored
+383 get_target_filename("c:\path\to\mmp")
+384
+385 if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp"
+386 """
+387returnself.read_information_from_mmp(path_to_mmp,3)
+
390"""
+391 Libraries listed in the MMP file are returned in a list
+392 If "c:\path\to\mmp" is a location where mmp file is stored
+393 get_libraries("c:\path\to\mmp")
+394
+395 if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp"
+396 """
+397returnself.read_information_from_mmp(path_to_mmp,5)
+
400"""
+401 Returns harness of test component
+402 If "c:\path\to\mmp" is a location where mmp file is stored
+403 get_harness("c:\path\to\mmp")
+404
+405 if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp"
+406 """
+407returnself.read_information_from_mmp(path_to_mmp,6)
+
410"""
+411 Returns type of test whether 'executable' or 'dependent' (dependent can be a stub or plugin)
+412 If "c:\path\to\mmp" is a location where mmp file is stored
+413 get_dll_type("c:\path\to\mmp")
+414
+415 if mmp file is not given, the function will try to find the file(s) on the given location with extension ".mmp"
+416 """
+417returnself.read_information_from_mmp(path_to_mmp,7)
+
513"""
+514 Parses .pkg files. Returns a list of:
+515 a. src path of the file
+516 b. dst path on the phone
+517 c. type of the file
+518 for every file in the pkg file
+519 """
+520
+
525"""
+526 Returns list of PKG files on the given location. If True, full path is returned
+527 otherwise only filenames. Default is set to True
+528
+529 Assume at location "c:\abd\files", two pkg file '1.pkg' and '2.pkg', then the funtion
+530 can be called as:
+531 1. get_pkg_files("c:\abd\files") - will return a list of pkg files with full paths.
+532 like ['c:\abd\files\1.pkg', 'c:\abd\files\2.pkg']
+533 2. get_pkg_files("c:\abd\files", False) - will return a list of pkg files only.
+534 like ['1.pkg', '2.pkg']
+535 """
+536self.location=path(location)
+537self.pkg_files=[]
+538ifnotself.location.exists():
+539returnNone
+540
+541forp,subdirs,filesinos.walk(self.location):
+542pfiles=[fforfinfilesifself.platform!=Noneandf.endswith(self.platform)]
+543ifself.platform!=Noneandlen(pfiles)>0:
+544ifwith_full_path:
+545self.pkg_files.append(os.path.join(p,pfiles[0]))
+546else:
+547self.pkg_files.append(str(pfiles[0]))
+548else:
+549fornameinfiles:
+550iffnmatch.fnmatch(name,"*.pkg"):
+551ifwith_full_path:
+552self.pkg_files.append(os.path.join(p,name))
+553else:
+554self.pkg_files.append(str(name))
+555
+556returnself.pkg_files
+
559"""
+560 Returns data files, source and destination of the files to be installed
+561 on the phone
+562 e.g. location = tsrc\testComponent\group
+563
+564 Function can be called in any of the following ways:
+565 1. get_data_files("c:\abc\abc.pkg") - only data files' paths are returnd
+566 as they are mention in the pkg file
+567 2. get_data_files("c:\abc\abc.pkg", "x:") - Proper data files' paths are returnd
+568 with drive letter included
+569 3. get_data_files("c:\abc\abc.pkg", "x:", "\.dll") - Data files' paths are returnd with
+570 drive letter included but the dll
+571 files will be excluded if found in
+572 the pkg file
+573
+574 if pkg file is not given, the function will try to find the file(s) on the given location with extension ".pkg"
+575 """
+576
+577self.drive=drive
+578self.exclude=exclude
+579self._files=[]
+580
+581iftype(location)isnotlist:
+582locations=[location]
+583else:
+584locations=location
+585
+586for_file_inlocations:
+587
+588#if location is already a file
+589if".pkg"instr(_file_).lower():
+590self._files=_file_
+591else:
+592self.location=path(_file_)
+593
+594ifnotself.location.exists():
+595continue
+596forp_fileinself.get_pkg_files(self.location,True):
+597self._files.append(p_file)
+598
+599returnself.__read_pkg_file(self._files)
+