All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
dependencyAnalysis.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 import os
3 import xml.etree.ElementTree as ET
4 import sys
5 
6 
7 def QMTsniffer(path) :
8 
9  tree = ET.parse(RationalizePath(path))
10  root = tree.getroot()
11  finalList=[]
12  for child in root:
13  type = child.attrib['name']
14  if type == 'prerequisites' :
15  tupleList = child[0].findall('tuple')
16  textList= [l.findall("text") for l in tupleList]
17  for tl in textList :
18  finalList.append(tl[0].text)
19  return finalList
20 
21 def QMSsniffer(path):
22  tree = ET.parse(RationalizePath(path))
23  root = tree.getroot()
24  finalList=[]
25  for child in root:
26  type = child.attrib['name']
27  if type == 'suite_ids' or type=='test_ids':
28  setList = child[0].findall('set')
29  textList = [l.findall('text') for l in tupleList]
30  for tl in texList:
31  finalList.append(tl[0].text)
32  return finalList
33 
35 
36  newPath = os.path.normpath(os.path.expandvars(p))
37  if os.path.exists(newPath) :
38  p = os.path.realpath(newPath)
39  p = os.path.realpath(newPath)
40  return p
41 
42 
43 def sniffer(dir,originDirectory='',package=''):
44  dir = RationalizePath(dir)
45  os.chdir(dir)
46  finalList = dict()
47  newPackage=package
48  fileList = [ l for l in os.listdir(dir) if not l.startswith('.')]
49  if dir.endswith(".qms"):
50  t,p=os.path.split(dir)
51  newPackage+=p+"/"
52  for file in fileList:
53  if file.endswith(".qmt"):
54  finalList[newPackage+os.path.basename(file)]=QMTsniffer(file)
55  elif file.endswith(".qms") and os.path.isfile(file):
56  finalList[newPackage+os.path.basename(file)]=QMSsniffer(file)
57  elif file.endswith(".qms"):
58  file=RationalizePath(file)
59  newResult=sniffer(file,dir,package=newPackage)
60  finalList=dict(finalList.items()+newResult.items())
61  finalList[newPackage+os.path.basename(file)]=[ ld for ld in os.listdir(file) if (not l.startswith('.') and (l.endswith('.qmt') or not l.endswith('.qms')))]
62  elif os.path.isdir(file):
63  file=RationalizePath(file)
64  newResult=sniffer(file,dir,package=newPackage)
65  finalList=dict(finalList.items()+newResult.items())
66  if originDirectory!='' :
67  os.chdir(originDirectory)
68  return finalList