-
Notifications
You must be signed in to change notification settings - Fork 8
/
si_ide_writer.py
61 lines (48 loc) · 2.15 KB
/
si_ide_writer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# SPDX-FileCopyrightText: (c) 2020 Western Digital Corporation or its affiliates,
# Arseniy Aharonov <[email protected]>
#
# SPDX-License-Identifier: MIT
import os
from zipfile import ZipFile
import stat_attributes as attributes
from ide_writer import IdeWriter
WORKSPACE_PATH = "{basePath}/{name}"
SOURCE_INSIGHT_4 = "si4project.zip"
FILE_LIST_FILENAME = "{path}/si_filelist.txt"
SI_FILES_PREFIX = 'stat'
SI_PROJECT_EXT = ".siproj"
class SourceInsightWriter(IdeWriter):
IDE = 'SourceInsight'
def __init__(self, contents, *args):
super(SourceInsightWriter, self).__init__(contents, *args)
self.__files = [self._contents.makefile]
self.__workspacePath = \
WORKSPACE_PATH.format(basePath=attributes.IDE_DIRECTORY, name=self._contents.name)
def createRootToken(self):
return None
def createDirectoryToken(self, name, parentDirectoryToken):
pass
def addFile(self, filePath, parentDirectoryToken):
self.__files.append(filePath)
def write(self):
projectFile = os.path.join(self.__workspacePath, self._contents.name + SI_PROJECT_EXT)
if not os.path.isfile(projectFile):
self.__createWorkspace()
outputText = 'Source-Insight project "{path}" has been build.'
else:
outputText = 'Source-Insight file-list for project "{path}" has been rebuilt.'
self.__writeProjectFileList()
print(outputText.format(path=self.__workspacePath))
def __createWorkspace(self):
os.makedirs(self.__workspacePath)
zipSource = os.path.join(attributes.TOOL_PATH, attributes.RESOURCES_DIRECTORY, SOURCE_INSIGHT_4)
with ZipFile(zipSource, "r") as source:
for member in source.filelist:
member.filename = member.filename.replace(SI_FILES_PREFIX, self._contents.name)
source.extract(member, self.__workspacePath)
def __writeProjectFileList(self):
fileName = FILE_LIST_FILENAME.format(path=self.__workspacePath)
targetFile = open(fileName, 'w')
targetFile.write('\n'.join(self.__files))
targetFile.close()