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