Fixed documentation and pylint messages

pull/999/head
GustavWi 2015-03-25 14:43:06 +01:00
parent 40ccdd5b1f
commit 94e6ba9441
1 changed files with 54 additions and 31 deletions

View File

@ -14,11 +14,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from exporters import Exporter
from workspace_tools.export.exporters import Exporter
import re
import os
from os.path import join, dirname
class IAREmbeddedWorkbench(Exporter):
"""
Exporter class for IAR Systems.
"""
NAME = 'IAR'
TOOLCHAIN = 'IAR'
@ -71,15 +73,18 @@ class IAREmbeddedWorkbench(Exporter):
]
def generate(self):
"""
Generates the project files
"""
sources = []
sources += self.resources.c_sources
sources += self.resources.cpp_sources
sources += self.resources.s_sources
iar_files = IAR_FOLDER("","",[])
iar_files = IarFolder("", "", [])
for source in sources:
iar_files.insert_file(source)
ctx = {
'name': self.program_name,
'include_paths': self.resources.inc_dirs,
@ -94,18 +99,31 @@ class IAREmbeddedWorkbench(Exporter):
self.gen_file('iar.eww.tmpl', ctx, '%s.eww' % self.program_name)
self.gen_file('iar_%s.ewd.tmpl' % self.target.lower(), ctx, '%s.ewd' % self.program_name)
class IAR_FOLDER:
#input:
#folder_level : folder path to current folder
#folder_name : name of current folder
#source_files : list of source_files (all must be in same directory)
class IarFolder():
"""
This is a recursive folder object.
To present the folder structure in the IDE as it is presented on the disk.
This can be used for uvision as well if you replace the __str__ method.
Example:
files: ./main.cpp, ./apis/I2C.h, ./mbed/common/I2C.cpp
in the project this would look like:
main.cpp
common/I2C.cpp
input:
folder_level : folder path to current folder
folder_name : name of current folder
source_files : list of source_files (all must be in same directory)
"""
def __init__(self, folder_level, folder_name, source_files):
self.folder_level = folder_level
self.folder_name = folder_name
self.source_files = source_files
self.sub_folders = {};
self.sub_folders = {}
def __str__(self):
"""
converts the folder structue to IAR project format.
"""
group_start = ""
group_end = ""
if self.folder_name != "":
@ -117,41 +135,46 @@ class IAR_FOLDER:
if self.source_files:
for src in self.source_files:
str_content += "<file>\n<name>$PROJ_DIR$/%s</name>\n</file>\n" % src
##Add sub folders
#Add sub folders
if self.sub_folders:
for folder_name in self.sub_folders.iterkeys():
str_content += self.sub_folders[folder_name].__str__()
str_content += group_end
return str_content
def insert_file(self, source_input):
if self.source_files:
dir_sources = IAR_FOLDER.get_directory(self.source_files[0]) ##All source_files in a IAR_FOLDER must be in same directory.
if not self.folder_level == dir_sources: ## Check if sources are already at their deepest level.
"""
Inserts a source file into the folder tree
"""
if self.source_files:
#All source_files in a IarFolder must be in same directory.
dir_sources = IarFolder.get_directory(self.source_files[0])
#Check if sources are already at their deepest level.
if not self.folder_level == dir_sources:
_reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
folder_name = re.match( _reg_exp, dir_sources).group(1)
self.sub_folders[folder_name] = IAR_FOLDER(os.path.join(self.folder_level,folder_name), folder_name, self.source_files)
folder_name = re.match(_reg_exp, dir_sources).group(1)
self.sub_folders[folder_name] = IarFolder(os.path.join(self.folder_level, folder_name), folder_name, self.source_files)
self.source_files = []
dir_input = IAR_FOLDER.get_directory(source_input)
dir_input = IarFolder.get_directory(source_input)
if dir_input == self.folder_level:
self.source_files.append(source_input)
else:
_reg_exp = r"^" + re.escape(self.folder_level) + r"[/\\]?([^/\\]+)"
folder_name = re.match( _reg_exp, dir_input).group(1)
folder_name = re.match(_reg_exp, dir_input).group(1)
if self.sub_folders.has_key(folder_name):
self.sub_folders[folder_name].insert_file(source_input)
else:
if self.folder_level == "": #Top level exception
self.sub_folders[folder_name] = IAR_FOLDER(folder_name, folder_name, [source_input])
if self.folder_level == "":
#Top level exception
self.sub_folders[folder_name] = IarFolder(folder_name, folder_name, [source_input])
else:
self.sub_folders[folder_name] = IAR_FOLDER(os.path.join(self.folder_level,folder_name), folder_name, [source_input])
self.sub_folders[folder_name] = IarFolder(os.path.join(self.folder_level, folder_name), folder_name, [source_input])
@staticmethod
@staticmethod
def get_directory(file_path):
"""
Returns the directory of the file
"""
return os.path.dirname(file_path)