Pylint refactoring on ewpproject.py

This commit is contained in:
cylon 2016-09-25 12:30:40 +02:00
parent e3fad2d08b
commit fca8ab0bd7

View File

@ -1,12 +1,18 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" Module for converting EWP project format file
@file
"""
import os import os
from lxml import objectify from lxml import objectify
class EWPProject (object):
class EWPProject(object):
""" Class for converting EWP project format file
"""
def __init__(self, path, xmlFile): def __init__(self, path, xmlFile):
self.project = {} self.project = {}
self.path = path self.path = path
self.xmlFile = xmlFile self.xmlFile = xmlFile
@ -14,26 +20,24 @@ class EWPProject (object):
self.root = xmltree.getroot() self.root = xmltree.getroot()
def parseProject(self): def parseProject(self):
""" Parses EWP project file for project settings
"""
self.project['name'] = self.root.configuration.name self.project['name'] = self.root.configuration.name
self.project['chip'] = '' self.project['chip'] = ''
#TODO: parse into tree structure #TODO: parse into tree structure
self.project['srcs'] = [] self.project['srcs'] = []
self.searchGroups(self.root, self.project['srcs']) self.searchGroups(self.root, self.project['srcs'])
self.project['defs'] = [] self.project['defs'] = []
self.project['incs'] = [] self.project['incs'] = []
for element in self.root.configuration.getchildren(): for element in self.root.configuration.getchildren():
if element.tag == 'settings': if element.tag == 'settings':
for e in element.data.getchildren(): for e in element.data.getchildren():
if e.tag == 'option':
if e.tag == 'option': if e.name.text == 'OGChipSelectEditMenu':
if e.name.text == 'OGChipSelectEditMenu': self.project['chip'] = str(e.state)
self.project['chip'] = str(e.state)
elif e.name.text == 'CCDefines': elif e.name.text == 'CCDefines':
for d in e.getchildren(): for d in e.getchildren():
if d.tag == 'state' and d.text != None: if d.tag == 'state' and d.text != None:
@ -42,54 +46,55 @@ class EWPProject (object):
for d in e.getchildren(): for d in e.getchildren():
if d.tag == 'state' and d.text != None: if d.tag == 'state' and d.text != None:
self.project['incs'].append(d.text) self.project['incs'].append(d.text)
for i in range(0, len(self.project['incs'])): for i in range(0, len(self.project['incs'])):
s = str(self.project['incs'][i]) s = str(self.project['incs'][i])
if os.path.sep not in s: if os.path.sep not in s:
if os.path.sep == '\\': if os.path.sep == '\\':
s = s.replace('/','\\') s = s.replace('/', '\\')
elif os.path.sep == '/': elif os.path.sep == '/':
s = s.replace('\\','/') s = s.replace('\\', '/')
self.project['incs'][i] = s.replace('$PROJ_DIR$'+os.path.sep+'..', self.path) self.project['incs'][i] = s.replace('$PROJ_DIR$'+os.path.sep+'..', self.path)
self.project['files']=[] self.project['files'] = []
i=0 i = 0
if os.path.exists(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc'): if os.path.exists(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc'):
for entry in os.listdir(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc'): for entry in os.listdir(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc'):
if entry.endswith('.S') or entry.endswith('.s'): if entry.endswith('.S') or entry.endswith('.s'):
self.project['files'].append(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc/'+entry) self.project['files'].append(self.path + '/Drivers/CMSIS/Device/ST/STM32F0xx/Source/Templates/gcc/'+entry)
def displaySummary(self): def displaySummary(self):
""" Display summary of parsed project settings
print ('Project Name:' + self.project['name']) """
print ('Project chip:' + self.project['chip']) print('Project Name:' + self.project['name'])
print ('Project includes: ' + ' '.join(self.project['incs'])) print('Project chip:' + self.project['chip'])
print ('Project defines: ' + ' '.join(self.project['defs'])) print('Project includes: ' + ' '.join(self.project['incs']))
print ('Project srcs: ' + ' '.join(self.project['srcs'])) print('Project defines: ' + ' '.join(self.project['defs']))
print('Project srcs: ' + ' '.join(self.project['srcs']))
def searchGroups(self, xml, sources): def searchGroups(self, xml, sources):
""" Display summary of parsed project settings
@param xml XML file with project settings configuration
@param sources List containing source files
"""
for element in xml.getchildren(): for element in xml.getchildren():
if element.tag == 'group': if element.tag == 'group':
self.searchGroups(element,sources) self.searchGroups(element, sources)
elif element.tag == 'file':
elif element.tag == 'file':
if not str(element.name).endswith('.s'): if not str(element.name).endswith('.s'):
s = str(element.name) s = str(element.name)
if os.path.sep not in s: if os.path.sep not in s:
if os.path.sep == '\\': if os.path.sep == '\\':
s = s.replace('/','\\') s = s.replace('/', '\\')
elif os.path.sep == '/': elif os.path.sep == '/':
s = s.replace('\\','/') s = s.replace('\\', '/')
sources.append(s.replace('$PROJ_DIR$'+os.path.sep+'..', self.path)) sources.append(s.replace('$PROJ_DIR$'+os.path.sep+'..', self.path))
def getProject(self): def getProject(self):
""" Return parsed project settings stored as dictionary
return self.project @return Dictionary containing project settings
"""
return self.project