개정판 bf2f0565
issue #1998: 실행 권한 오류 수정(App.db와 log 파일을 USERLOCAL 폴더에 저장하도록 수정)
Change-Id: I0942556044317dea10d47d5fb4c8801c69c41dc7
HYTOS/HYTOS/App.py | ||
---|---|---|
24 | 24 |
COMPANY = 'SECL' |
25 | 25 |
NAME = 'HYTOS' # 'Hydraulic Calculation' # program name |
26 | 26 | |
27 |
COMMON_APP_DATA_FOLDER = os.path.join(os.getenv('ALLUSERSPROFILE'), NAME) |
|
28 |
LOCAL_APP_DATA_FOLDER = os.path.join(os.getenv('USERPROFILE'), NAME) |
|
29 | ||
27 | 30 |
def __init__(self, args): |
28 | 31 |
import locale |
29 | 32 |
from AppDocData import AppDocData |
... | ... | |
162 | 165 | |
163 | 166 | |
164 | 167 |
if __name__ == '__main__': |
168 |
import shutil |
|
165 | 169 |
from AppDocData import AppDocData |
166 | 170 |
from MainWindow import MainWindow |
167 | 171 |
from ExceptionHandler import QExceptionHandler |
168 | 172 |
from SystemInformation import QSystemInformationDialog |
169 | 173 | |
174 |
try: |
|
175 |
if not os.path.exists(App.LOCAL_APP_DATA_FOLDER): |
|
176 |
os.mkdir(App.LOCAL_APP_DATA_FOLDER) |
|
177 |
shutil.copyfile(os.path.join(App.COMMON_APP_DATA_FOLDER, 'App.db'), |
|
178 |
os.path.join(App.LOCAL_APP_DATA_FOLDER, 'App.db')) |
|
179 |
except Exception as ex: |
|
180 |
message = f'error occurred({ex}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:' \ |
|
181 |
f'{sys.exc_info()[-1].tb_lineno}' |
|
182 |
print(message) |
|
183 |
|
|
170 | 184 |
app = App(sys.argv) |
171 | 185 |
app_doc_data = AppDocData.instance() |
172 | 186 |
configs = app_doc_data.getAppConfigs('app', 'update_url') |
HYTOS/HYTOS/AppDocData.py | ||
---|---|---|
115 | 115 |
''' |
116 | 116 | |
117 | 117 |
def getTemplateDbPath(self): |
118 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME)
|
|
118 |
path = App.COMMON_APP_DATA_FOLDER
|
|
119 | 119 |
templateDbPath = os.path.join(path, 'Template.db') |
120 | 120 |
return templateDbPath |
121 | 121 | |
... | ... | |
244 | 244 |
@date 2018.10.01 |
245 | 245 |
""" |
246 | 246 | |
247 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME)
|
|
247 |
path = App.LOCAL_APP_DATA_FOLDER
|
|
248 | 248 |
app_database = os.path.join(path, 'App.db') |
249 | 249 |
return app_database |
250 | 250 | |
... | ... | |
258 | 258 |
from App import App |
259 | 259 | |
260 | 260 |
try: |
261 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME)
|
|
261 |
path = App.LOCAL_APP_DATA_FOLDER
|
|
262 | 262 |
appDatabaseFilePath = os.path.join(path, 'App.db') |
263 | 263 | |
264 | 264 |
# Creates or opens a file called mydb with a SQLite3 DB |
... | ... | |
370 | 370 |
def border_file_path(self): |
371 | 371 |
""" return border file path """ |
372 | 372 | |
373 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME)
|
|
373 |
path = App.COMMON_APP_DATA_FOLDER
|
|
374 | 374 |
return os.path.join(path, 'Border.png') |
375 | 375 | |
376 | 376 |
@property |
377 | 377 |
def symbol_file_path(self): |
378 | 378 |
""" return svg symbol file path """ |
379 | 379 | |
380 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME)
|
|
380 |
path = App.COMMON_APP_DATA_FOLDER
|
|
381 | 381 |
return os.path.join(path, 'svg') |
382 | 382 | |
383 | 383 |
def update_symbol_shape(self, drawing, symbol, svg_file): |
HYTOS/HYTOS/ExceptionHandler.py | ||
---|---|---|
21 | 21 |
def __init__(self): |
22 | 22 |
super(QExceptionHandler, self).__init__() |
23 | 23 | |
24 |
self.log_path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME, App.NAME + '.log') |
|
24 |
local_app_data_folder = os.path.join(os.getenv('USERPROFILE'), App.NAME) |
|
25 |
if not os.path.exists(local_app_data_folder): |
|
26 |
os.mkdir(local_app_data_folder) |
|
27 | ||
28 |
self.log_path = os.path.join(local_app_data_folder, App.NAME + '.log') |
|
25 | 29 |
self.logger = logging.getLogger(__name__) |
26 |
logging.basicConfig(filename=self.log_path , filemode='w', level=logging.CRITICAL)
|
|
30 |
logging.basicConfig(filename=self.log_path, filemode='w', level=logging.CRITICAL) |
|
27 | 31 | |
28 | 32 |
def handler(self, exctype, value, traceback): |
29 |
""" log exception, file namd and line number """
|
|
33 |
""" log exception, file name and line number """
|
|
30 | 34 | |
31 |
message = 'error occurred({}) in {}:{}'.format(value, traceback.tb_frame.f_code.co_filename, traceback.tb_lineno)
|
|
35 |
message = f'error occurred({value}) in {traceback.tb_frame.f_code.co_filename}:{traceback.tb_lineno}'
|
|
32 | 36 |
self.errorSignal.emit() |
33 | 37 |
self.logger.critical('Unhandled exception: {}'.format(message)) |
HYTOS/HYTOS/MainWindow.py | ||
---|---|---|
1599 | 1599 |
file_name, _ = QFileDialog.getSaveFileName(self, self.tr('Report'), file_name, 'Excel(*.xlsx)', |
1600 | 1600 |
options=options) |
1601 | 1601 | |
1602 |
template = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME, 'Report_Template.xlsx')
|
|
1602 |
template = os.path.join(App.COMMON_APP_DATA_FOLDER, 'Report_Template.xlsx')
|
|
1603 | 1603 | |
1604 | 1604 |
# get image file path |
1605 |
company_image_path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME, 'Company.png') |
|
1606 |
horizontal_flow_image_path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME, 'Horizontal_Flow.png') |
|
1607 |
vertical_upward_flow_image_path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME, |
|
1608 |
'Vertical_Upward_Flow.png') |
|
1609 |
vertical_downward_flow_image_path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME, |
|
1610 |
'Vertical_Downward_Flow.png') |
|
1605 |
company_image_path = os.path.join(App.COMMON_APP_DATA_FOLDER, 'Company.png') |
|
1606 |
horizontal_flow_image_path = os.path.join(App.COMMON_APP_DATA_FOLDER, 'Horizontal_Flow.png') |
|
1607 |
vertical_upward_flow_image_path = os.path.join(App.COMMON_APP_DATA_FOLDER, 'Vertical_Upward_Flow.png') |
|
1608 |
vertical_downward_flow_image_path = os.path.join(App.COMMON_APP_DATA_FOLDER, 'Vertical_Downward_Flow.png') |
|
1611 | 1609 |
# up to here |
1612 | 1610 |
if file_name and os.path.exists(template): |
1613 | 1611 |
units = [attr[1] for attr in app_doc_data.activeDrawing.attrs if attr[0] == 'Units'][0] |
HYTOS/HYTOS/SymbolEditorDialog.py | ||
---|---|---|
190 | 190 |
self.set_svg_file_path() |
191 | 191 | |
192 | 192 |
def setImage(self): |
193 |
path = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME)
|
|
193 |
path = App.COMMON_APP_DATA_FOLDER
|
|
194 | 194 |
category = self.ui.categoryComboBox.currentText() |
195 | 195 |
type = self.ui.typeComboBox.currentText() |
196 | 196 |
name = self.ui.nameComboBox.currentText() |
내보내기 Unified diff