179
|
1 |
#============================================================================
|
|
2 |
#Name : docs.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 |
""" Modules related to documentation """
|
|
21 |
|
|
22 |
from __future__ import with_statement
|
|
23 |
import re
|
|
24 |
import os
|
|
25 |
import string
|
|
26 |
import amara
|
|
27 |
import ant
|
|
28 |
|
|
29 |
def find_python_dependencies(setpath, dbPath, dbPrj):
|
|
30 |
""" Search python dependencies """
|
|
31 |
for root, dirs, files in os.walk(setpath, topdown=False):
|
|
32 |
for fname in files:
|
|
33 |
filePattern = re.compile('.ant.xml$')
|
|
34 |
fileMatch = filePattern.search(fname)
|
|
35 |
modulelist = []
|
|
36 |
if (fileMatch):
|
|
37 |
filePath = os.path.abspath(os.path.join(root, fname))
|
|
38 |
with open(filePath) as f:
|
|
39 |
filePathAmara = 'file:///'+ filePath.replace('\\','/')
|
|
40 |
curPrj=amara.parse(filePathAmara)
|
|
41 |
for line in f:
|
|
42 |
linePattern = re.compile('^import')
|
|
43 |
lineMatch = linePattern.search(line)
|
|
44 |
if ((lineMatch) and (line.find('.')==-1)):
|
|
45 |
newLine = line.replace('import','')
|
|
46 |
newLine = newLine.replace(',','')
|
|
47 |
moduleArray = newLine.split()
|
|
48 |
for curModule in moduleArray:
|
|
49 |
try:
|
|
50 |
importModule = __import__(curModule)
|
|
51 |
modulePath=importModule.__file__
|
|
52 |
if (modulePath.find('\\helium\\tools')!= -1):
|
|
53 |
for projectList in dbPrj.antDatabase.project:
|
|
54 |
if (projectList.name==curPrj.project.name):
|
|
55 |
if not (curModule in modulelist):
|
|
56 |
print " Python module : " +curModule
|
|
57 |
moduleElement = projectList.pythonDependency.xml_create_element(u'module', content=u''+curModule)
|
|
58 |
projectList.pythonDependency.xml_append(moduleElement)
|
|
59 |
modulelist = modulelist + [curModule]
|
|
60 |
except Exception, e:
|
|
61 |
error ="yes"
|