Am 16/02/2016 um 13:40 schrieb Andreas Ringlstetter:
From: Benjamin Hiefner <benjamin.hiefner@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Benjamin Hiefner <benjamin.hiefner@xxxxxxxxxxxxxxxxxxxx>
---
codeface/sourceAnalysis.py | 60
++++++++++++++++++++++++++++++----------------
1 file changed, 40 insertions(+), 20 deletions(-)
diff --git a/codeface/sourceAnalysis.py b/codeface/sourceAnalysis.py
index 6114cbb..1ff5de1 100644
--- a/codeface/sourceAnalysis.py
+++ b/codeface/sourceAnalysis.py
@@ -1,13 +1,27 @@
-#! /usr/bin/env python
+# This file is part of Codeface. Codeface is free software: you can
+# redistribute it and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation, version 2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Copyright 2013 by Siemens AG, Wolfgang Mauerer
<wolfgang.mauerer@xxxxxxxxxxx>
+# Copyright 2014 by Matthias Dittrich <matthi.d@xxxxxxxxx>
+# All Rights Reserved.
import xml.etree.ElementTree as ET
-from subprocess import Popen, PIPE
from os import path
-import sys
+from subprocess import Popen, PIPE
-class FileAnalysis:
- ## List of source code elements we want to capture
+class FileAnalysis:
+ """ List of source code elements we want to capture """
SRC_ELEMS = ['function']
def __init__(self, filename, doxygen_conf, outdir):
@@ -17,14 +31,14 @@ class FileAnalysis:
self.src_elem_list = []
def gen_XML_files(self):
- # Run source code analysis and generate xml files
+ """ Run source code analysis and generate xml files """
input_file = 'INPUT=' + self.filename
output_dir = 'OUTPUT_DIRECTORY=' + self.outdir
cmd_1 = ['cat', self.conf]
- p1 = Popen(cmd_1 ,stdout=PIPE)
+ p1 = Popen(cmd_1, stdout=PIPE)
doxy_conf = p1.communicate()[0]
doxy_conf = doxy_conf + input_file + '\n'
- doxy_conf = doxy_conf + output_dir
+ doxy_conf += output_dir
please fix typo
cmd = 'doxygen -'
cmd_2 = cmd.split()
@@ -33,8 +47,11 @@ class FileAnalysis:
p2.communicate()
def _parse_XML_index(self):
- # Parse index file generate by deoxygen that contains the compound
- # elements
+ """ Parse index file generate by deoxygen that contains the compound
+ elements
+ Returns:
+
+ """
comp_list = []
index_file = path.join(self.outdir, 'xml', 'index.xml')
tree = ET.parse(index_file)
@@ -44,18 +61,19 @@ class FileAnalysis:
for elem in comp_elements:
# Check if the element contains a child function
member_kind = [child.get('kind') for child in
elem.iter('member')]
- if any([src_elem in member_kind for src_elem in \
+ if any([src_elem in member_kind for src_elem in
FileAnalysis.SRC_ELEMS]):
refid = elem.get('refid')
kind = elem.get('kind')
name = elem.find('name').text
- comp_list.append({'refid':refid, 'kind':kind, 'name':name})
+ comp_list.append({'refid': refid, 'kind': kind, 'name':
name})
- return(comp_list)
+ return comp_list
def _parse_XML_compound(self, comp_list):
for comp_elem in comp_list:
- comp_file = path.join(self.outdir, 'xml', comp_elem['refid'] +
'.xml')
+ comp_file = path.join(self.outdir, 'xml',
+ comp_elem['refid'] + '.xml')
xml_string = self._prepare_clean_xml(comp_file)
root = ET.fromstring(xml_string)
@@ -69,16 +87,18 @@ class FileAnalysis:
# Some elements of function type are not assigned
# start and end (e.g., definitions)
if None not in [start, end, name]:
- self.src_elem_list.append({'bodystart':start,
- 'bodyend':end,
- 'name':name,
+ self.src_elem_list.append({'bodystart': start,
+ 'bodyend': end,
+ 'name': name,
'mem_kind': kind,
- 'comp_kind':
comp_elem['kind'],
- 'comp_name':
comp_elem['name']})
+ 'comp_kind': comp_elem[
+ 'kind'],
+ 'comp_name': comp_elem[
+ 'name']})
def _prepare_clean_xml(self, filename):
# Read file
- with open (filename, "r") as file:
+ with open(filename, "r") as file:
xml_string = file.read()
# Clean file of control characters