hytos / DTI_PID / DTI_PID / Project.py @ 00027421
이력 | 보기 | 이력해설 | 다운로드 (5.74 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is project module """
|
3 |
|
4 |
import os |
5 |
from shutil import copyfile |
6 |
from AppDatabase import AppDatabase |
7 |
|
8 |
|
9 |
class Project: |
10 |
DATABASE = 'ITI_PID.db'
|
11 |
|
12 |
def __init__(self, project): |
13 |
self.id = project['Id'] |
14 |
self._name = project['Name'] |
15 |
self._desc = project['Desc'] |
16 |
self._prj_unit = project['Unit'] |
17 |
self.path = project['Path'] |
18 |
self.createDate = project['CreatedDate'] |
19 |
self.updateDate = project['UpdatedDate'] |
20 |
self._database = AppDatabase(type=project['DBType'], host=project['Host'], user=project['User'], |
21 |
password=project['Password'],
|
22 |
db_path=os.path.join(self.path, 'db', Project.DATABASE) if |
23 |
project['DBType'] == 'SQLite' else project['Name']) |
24 |
|
25 |
def setId(self, id): |
26 |
self.id = id |
27 |
|
28 |
def getId(self): |
29 |
return self.id |
30 |
|
31 |
def setName(self, name): |
32 |
self._name = name
|
33 |
|
34 |
@property
|
35 |
def name(self): |
36 |
return self._name |
37 |
|
38 |
@property
|
39 |
def desc(self): |
40 |
return self._desc |
41 |
|
42 |
@desc.setter
|
43 |
def desc(self, value): |
44 |
""" setter of desc """
|
45 |
self._desc = value
|
46 |
|
47 |
@property
|
48 |
def prj_unit(self): |
49 |
return self._prj_unit |
50 |
|
51 |
@prj_unit.setter
|
52 |
def prj_unit(self, value): |
53 |
""" setter of prj_unit """
|
54 |
self._prj_unit = value
|
55 |
|
56 |
@property
|
57 |
def database(self): |
58 |
""" return database instance """
|
59 |
return self._database |
60 |
|
61 |
def setPath(self, path): |
62 |
self.path = path
|
63 |
|
64 |
def getPath(self): |
65 |
return self.path |
66 |
|
67 |
def getDrawingFilePath(self) -> str: |
68 |
"""
|
69 |
:return: drawing file path
|
70 |
"""
|
71 |
return os.path.join(self.getPath(), 'drawings') |
72 |
|
73 |
def getGraphicFilePath(self) -> str: |
74 |
"""
|
75 |
:return: graphic file path
|
76 |
"""
|
77 |
return os.path.join(self.getPath(), 'graphic') |
78 |
|
79 |
def getOutputPath(self) -> str: |
80 |
"""
|
81 |
:return: output path
|
82 |
"""
|
83 |
return os.path.join(self.getPath(), 'output') |
84 |
def getImageFilePath(self) -> str: |
85 |
"""
|
86 |
:return: image file path
|
87 |
"""
|
88 |
return os.path.join(self.getPath(), 'image') |
89 |
|
90 |
'''
|
91 |
@brief return db file path
|
92 |
@author Jeongwoo
|
93 |
@date 2018.04.10
|
94 |
'''
|
95 |
def getDbFilePath(self): |
96 |
return os.path.join(self.getPath(), 'db') |
97 |
|
98 |
'''
|
99 |
@brief return svg file path
|
100 |
@author humkyung
|
101 |
@date 2018.04.08
|
102 |
'''
|
103 |
def getSvgFilePath(self): |
104 |
return os.path.join(self.getPath(), 'svg') |
105 |
|
106 |
def getTempPath(self): |
107 |
"""return temporary path"""
|
108 |
return os.path.join(self.getPath(), 'Temp') |
109 |
|
110 |
'''
|
111 |
@brief return training path
|
112 |
@author euisung
|
113 |
@date 2018.09.28
|
114 |
'''
|
115 |
def getTrainingFilePath(self): |
116 |
return os.path.join(self.getPath(), 'Training') |
117 |
|
118 |
def getTrainingSymbolFilePath(self): |
119 |
""" return symbol training path """
|
120 |
return os.path.join(self.getPath(), 'Training_Symbol') |
121 |
|
122 |
def get_data_sheet_path(self): |
123 |
""" return data sheet path """
|
124 |
|
125 |
return os.path.join(self.getPath(), 'Datasheets') |
126 |
|
127 |
def setCreateDate(self, createDate): |
128 |
self.createDate = createDate
|
129 |
|
130 |
def getCreateDate(self): |
131 |
return self.createDate |
132 |
|
133 |
def setUpdateDate(self, updateDate): |
134 |
self.updateDate = updateDate
|
135 |
|
136 |
def getUpdateDate(self): |
137 |
return self.updateDate |
138 |
|
139 |
'''
|
140 |
@brief return project unit
|
141 |
@author humkyung
|
142 |
@date 2018.04.25
|
143 |
'''
|
144 |
def unit(self): |
145 |
from AppDocData import AppDocData |
146 |
res = 'Metric' # default value |
147 |
|
148 |
docData = AppDocData.instance() |
149 |
configs = docData.getConfigs('Line No', 'Size Unit') |
150 |
if 1 == len(configs): res = configs[0].value |
151 |
|
152 |
return res
|
153 |
|
154 |
def make_sub_directories(self): |
155 |
""" make directories for project """
|
156 |
|
157 |
dbDir = self.getDbFilePath()
|
158 |
if not os.path.exists(dbDir): |
159 |
os.makedirs(dbDir) |
160 |
imgDir = self.getImageFilePath()
|
161 |
if not os.path.exists(imgDir): |
162 |
os.makedirs(imgDir) |
163 |
svgDir = self.getSvgFilePath()
|
164 |
if not os.path.exists(svgDir): |
165 |
os.makedirs(svgDir) |
166 |
outputDir = self.getOutputPath()
|
167 |
if not os.path.exists(outputDir): |
168 |
os.makedirs(outputDir) |
169 |
tempDir = self.getTempPath()
|
170 |
if not os.path.exists(tempDir): |
171 |
os.makedirs(tempDir) |
172 |
drawingPath = self.getDrawingFilePath()
|
173 |
if not os.path.exists(drawingPath): |
174 |
os.makedirs(drawingPath) |
175 |
trainingPath = self.getTrainingFilePath()
|
176 |
if not os.path.exists(trainingPath): |
177 |
os.makedirs(trainingPath) |
178 |
trainingSymbolPath = self.getTrainingSymbolFilePath()
|
179 |
if not os.path.exists(trainingSymbolPath): |
180 |
os.makedirs(trainingSymbolPath) |
181 |
graphicPath = self.getGraphicFilePath()
|
182 |
if not os.path.exists(graphicPath): |
183 |
os.makedirs(graphicPath) |
184 |
|
185 |
path = os.path.join(tempDir, 'Tile')
|
186 |
if not os.path.exists(path): |
187 |
os.makedirs(path) |
188 |
path = os.path.join(drawingPath, 'Native')
|
189 |
if not os.path.exists(path): |
190 |
os.makedirs(path) |
191 |
|
192 |
# create folder and copy data sheet files
|
193 |
path = self.get_data_sheet_path()
|
194 |
if not os.path.exists(path): |
195 |
os.makedirs(path) |
196 |
|
197 |
source_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Datasheets')
|
198 |
data_sheet_files = [f for f in os.listdir(source_path) if os.path.isfile(os.path.join(source_path, f)) |
199 |
and (os.path.splitext(f)[1].upper() == '.XLSX')] |
200 |
for data_sheet in data_sheet_files: |
201 |
copyfile(os.path.join(source_path, data_sheet), os.path.join(path, data_sheet)) |