buildframework/helium/tools/common/python/lib/docs.py
author wbernard
Wed, 23 Dec 2009 19:29:07 +0200
changeset 179 d8ac696cc51f
permissions -rw-r--r--
helium_7.0-r14027
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     1
#============================================================================ 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     2
#Name        : docs.py 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     4
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     6
#All rights reserved.
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    11
#
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    12
#Initial Contributors:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    14
#
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    15
#Contributors:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    16
#
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    17
#Description:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    18
#===============================================================================
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    19
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    20
""" Modules related to documentation """
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    21
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    22
from __future__ import with_statement
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    23
import re
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    24
import os
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    25
import string
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    26
import amara
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    27
import ant
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    28
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    29
def find_python_dependencies(setpath, dbPath, dbPrj):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    30
    """ Search python dependencies """
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    31
    for root, dirs, files in os.walk(setpath, topdown=False):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    32
        for fname in files:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    33
            filePattern = re.compile('.ant.xml$')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    34
            fileMatch = filePattern.search(fname)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    35
            modulelist = []
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    36
            if (fileMatch):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    37
                filePath = os.path.abspath(os.path.join(root, fname))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    38
                with open(filePath) as f:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    39
                    filePathAmara = 'file:///'+ filePath.replace('\\','/')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    40
                    curPrj=amara.parse(filePathAmara)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    41
                    for line in f:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    42
                        linePattern = re.compile('^import')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    43
                        lineMatch = linePattern.search(line)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    44
                        if ((lineMatch) and (line.find('.')==-1)):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    45
                            newLine = line.replace('import','')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    46
                            newLine = newLine.replace(',','')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    47
                            moduleArray = newLine.split()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    48
                            for curModule in moduleArray:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    49
                                try:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    50
                                    importModule = __import__(curModule)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    51
                                    modulePath=importModule.__file__
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    52
                                    if (modulePath.find('\\helium\\tools')!= -1):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    53
                                        for projectList in dbPrj.antDatabase.project:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    54
                                            if (projectList.name==curPrj.project.name):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    55
                                                if not (curModule in modulelist):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    56
                                                    print " Python module : " +curModule
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    57
                                                    moduleElement = projectList.pythonDependency.xml_create_element(u'module', content=u''+curModule)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    58
                                                    projectList.pythonDependency.xml_append(moduleElement)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    59
                                                modulelist = modulelist + [curModule]
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    60
                                except Exception, e:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    61
                                    error ="yes"