587
|
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 amara
|
|
26 |
|
|
27 |
def find_python_dependencies(setpath, _, dbPrj):
|
|
28 |
""" Search python dependencies """
|
|
29 |
for root, _, files in os.walk(setpath, topdown=False):
|
|
30 |
for fname in files:
|
|
31 |
filePattern = re.compile('.ant.xml$')
|
|
32 |
fileMatch = filePattern.search(fname)
|
|
33 |
modulelist = []
|
|
34 |
if (fileMatch):
|
|
35 |
filePath = os.path.abspath(os.path.join(root, fname))
|
|
36 |
with open(filePath) as f_file:
|
|
37 |
filePathAmara = 'file:///'+ filePath.replace('\\','/')
|
628
|
38 |
curPrj = amara.parse(filePathAmara)
|
587
|
39 |
for line in f_file:
|
|
40 |
linePattern = re.compile('^import')
|
|
41 |
lineMatch = linePattern.search(line)
|
|
42 |
if ((lineMatch) and (line.find('.')==-1)):
|
|
43 |
newLine = line.replace('import','')
|
|
44 |
newLine = newLine.replace(',','')
|
|
45 |
moduleArray = newLine.split()
|
|
46 |
for curModule in moduleArray:
|
|
47 |
try:
|
|
48 |
importModule = __import__(curModule)
|
|
49 |
if hasattr(importModule, '__file__'):
|
628
|
50 |
modulePath = importModule.__file__
|
587
|
51 |
if 'helium' in modulePath:
|
|
52 |
for projectList in dbPrj.antDatabase.project:
|
|
53 |
if (projectList.name == curPrj.project.name):
|
|
54 |
if not (curModule in modulelist):
|
|
55 |
print " Python module : " + curModule
|
|
56 |
moduleElement = projectList.pythonDependency.xml_create_element(u'module', content=u''+curModule)
|
|
57 |
projectList.pythonDependency.xml_append(moduleElement)
|
|
58 |
modulelist = modulelist + [curModule]
|
|
59 |
except ImportError:
|
|
60 |
pass
|