개정판 7633a31e
issue #1197: 백업 파일을 생성 후 도면을 저장한다.
Change-Id: Ibc3ab30b282eaf327e038c2047b8d523058efc91
HYTOS/HYTOS/AppDocData.py | ||
---|---|---|
1379 | 1379 |
if show_progress: |
1380 | 1380 |
show_progress(100) |
1381 | 1381 |
|
1382 |
def getDrawings(self):
|
|
1382 |
def get_drawings(self):
|
|
1383 | 1383 |
"""get drawings""" |
1384 | 1384 |
from Drawing import Drawing |
1385 | 1385 |
|
... | ... | |
1421 | 1421 |
@date 2019.08.07 |
1422 | 1422 |
''' |
1423 | 1423 |
|
1424 |
def updateDrawing(self, drawing):
|
|
1424 |
def update_drawing(self, drawing):
|
|
1425 | 1425 |
import uuid |
1426 | 1426 |
|
1427 | 1427 |
# Creates or opens a file called mydb with a SQLite3 DB |
... | ... | |
1434 | 1434 |
|
1435 | 1435 |
sql = """update Drawings |
1436 | 1436 |
set Name=?,DateTime=? where UID = ?""" |
1437 |
param = (drawing.path, drawing.date_time, drawing.UID) |
|
1437 |
param = (drawing.org_path, drawing.date_time, drawing.UID)
|
|
1438 | 1438 |
cursor.execute(sql, param) |
1439 | 1439 |
|
1440 | 1440 |
conn.commit() |
... | ... | |
1456 | 1456 |
@date 2018.11.03 |
1457 | 1457 |
''' |
1458 | 1458 |
|
1459 |
def saveDrawing(self, drawing):
|
|
1459 |
def save_drawing(self, drawing):
|
|
1460 | 1460 |
import uuid |
1461 | 1461 |
from shutil import copyfile |
1462 | 1462 |
|
... | ... | |
1467 | 1467 |
cursor = conn.cursor() |
1468 | 1468 |
|
1469 | 1469 |
sql = 'insert or replace into Drawings(UID, [NAME], [DATETIME]) values(?, ?, ?)' |
1470 |
param = (drawing.UID, drawing.path, drawing.date_time) |
|
1470 |
param = (drawing.UID, drawing.org_path, drawing.date_time)
|
|
1471 | 1471 |
cursor.execute(sql, param) |
1472 | 1472 |
|
1473 | 1473 |
conn.commit() |
HYTOS/HYTOS/Drawing.py | ||
---|---|---|
1 | 1 |
# coding: utf-8 |
2 | 2 |
import os |
3 | 3 |
import uuid |
4 |
import tempfile |
|
5 |
import shutil |
|
4 | 6 |
from PyQt5.QtCore import * |
5 | 7 |
from AppDocData import AppDocData |
6 | 8 |
|
... | ... | |
17 | 19 |
self._attrs = [['Drawing No', ''], ['Rev No', ''], ['Units', '']] # attributes |
18 | 20 |
|
19 | 21 |
self.UID = UID |
20 |
self.path = path |
|
22 |
self.org_path = path
|
|
21 | 23 |
self.name = os.path.splitext(os.path.split(path)[1])[0] |
24 |
self.path = os.path.join(tempfile.gettempdir(), os.path.split(path)[1]) |
|
22 | 25 |
self.date_time = date_time |
23 | 26 |
|
24 | 27 |
self.allItems = [] |
HYTOS/HYTOS/MainWindow.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 |
""" This is MainWindow module """ |
3 |
|
|
3 |
import shutil |
|
4 | 4 |
import sys |
5 | 5 |
import os |
6 | 6 |
import subprocess |
... | ... | |
897 | 897 |
|
898 | 898 |
try: |
899 | 899 |
app_doc_data = AppDocData.instance() |
900 |
drawings = app_doc_data.getDrawings()
|
|
900 |
drawings = app_doc_data.get_drawings()
|
|
901 | 901 |
|
902 | 902 |
if self.treeViewDrawingList.model(): |
903 | 903 |
self.treeViewDrawingList.model().clear() |
... | ... | |
907 | 907 |
model.appendRow(root) |
908 | 908 |
|
909 | 909 |
for drawing in drawings: |
910 |
items = [QStandardItem(drawing.name), QStandardItem(drawing.date_time), QStandardItem(drawing.path)] |
|
910 |
items = [QStandardItem(drawing.name), QStandardItem(drawing.date_time), QStandardItem(drawing.org_path)]
|
|
911 | 911 |
items[0].setIcon(QIcon(':images/PFD.png')) |
912 | 912 |
items[0].setData(drawing, Qt.UserRole) |
913 | 913 |
root[0].appendRow(items) |
... | ... | |
1022 | 1022 |
copyfile(app_doc_data.activeDrawing.path, name) |
1023 | 1023 |
app_doc_data.activeDrawing.path = name |
1024 | 1024 |
|
1025 |
matches = [drawing for drawing in app_doc_data.getDrawings()
|
|
1025 |
matches = [drawing for drawing in app_doc_data.get_drawings()
|
|
1026 | 1026 |
if os.path.exists(drawing.path) and os.path.samefile(drawing.path, name)] |
1027 | 1027 |
if not matches: |
1028 | 1028 |
drawing = Drawing(str(uuid.uuid4()), name, str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) |
1029 |
app_doc_data.saveDrawing(drawing)
|
|
1029 |
app_doc_data.save_drawing(drawing)
|
|
1030 | 1030 |
else: |
1031 | 1031 |
drawing = Drawing(str(matches[0].UID), name, str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) |
1032 |
app_doc_data.updateDrawing(drawing)
|
|
1032 |
app_doc_data.update_drawing(drawing)
|
|
1033 | 1033 |
|
1034 | 1034 |
self.load_drawing_list() |
1035 | 1035 |
self.open_border_file() |
... | ... | |
1082 | 1082 |
app_doc_data.save_sheet_history('Save') |
1083 | 1083 |
|
1084 | 1084 |
"""update drawing's modified time""" |
1085 |
drawings = app_doc_data.getDrawings()
|
|
1085 |
drawings = app_doc_data.get_drawings()
|
|
1086 | 1086 |
drawing = [drawing for drawing in drawings if app_doc_data.activeDrawing.UID == drawing.UID] |
1087 | 1087 |
if drawing: |
1088 | 1088 |
drawing[0].date_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
1089 | 1089 |
rect = self.graphicsView.viewport().rect() |
1090 | 1090 |
drawing[0].view_rect = self.graphicsView.mapToScene(rect).boundingRect() |
1091 |
app_doc_data.updateDrawing(drawing[0])
|
|
1091 |
app_doc_data.update_drawing(drawing[0])
|
|
1092 | 1092 |
|
1093 | 1093 |
app_doc_data.activeDrawing.modified = False |
1094 | 1094 |
self.setMainWindowTitle(f"{app_doc_data.activeDrawing.path}") |
1095 | 1095 |
|
1096 |
shutil.copyfile(app_doc_data.activeDrawing.org_path, app_doc_data.activeDrawing.org_path + ".bak") |
|
1097 |
shutil.copyfile(app_doc_data.activeDrawing.path, app_doc_data.activeDrawing.org_path) |
|
1096 | 1098 |
except Exception as ex: |
1097 | 1099 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
1098 | 1100 |
f"{sys.exc_info()[-1].tb_lineno}" |
... | ... | |
2641 | 2643 |
self.onCommandRejected() |
2642 | 2644 |
app_doc_data.activeDrawing = drawing |
2643 | 2645 |
|
2646 |
shutil.copyfile(drawing.org_path, drawing.path) |
|
2644 | 2647 |
success = app_doc_data.build_drawing_database(drawing.path) |
2645 | 2648 |
if not success: |
2646 | 2649 |
QMessageBox.information(self, self.tr('Warning'), self.tr( |
... | ... | |
2711 | 2714 |
# copy template.db to name |
2712 | 2715 |
copyfile(sourceDb, name) |
2713 | 2716 |
|
2714 |
matches = [drawing for drawing in app_doc_data.getDrawings() if
|
|
2717 |
matches = [drawing for drawing in app_doc_data.get_drawings() if
|
|
2715 | 2718 |
os.path.exists(drawing.path) and os.path.samefile(drawing.path, name)] |
2716 | 2719 |
if not matches: |
2717 | 2720 |
drawing = Drawing(str(uuid.uuid4()), name, str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) |
2718 |
app_doc_data.saveDrawing(drawing)
|
|
2721 |
app_doc_data.save_drawing(drawing)
|
|
2719 | 2722 |
else: |
2720 | 2723 |
drawing = Drawing(str(matches[0].UID), name, str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) |
2721 |
app_doc_data.updateDrawing(drawing)
|
|
2724 |
app_doc_data.update_drawing(drawing)
|
|
2722 | 2725 |
|
2723 | 2726 |
self.load_drawing_list() |
2724 | 2727 |
self.load_data(drawing) |
... | ... | |
2750 | 2753 |
# copy template.db to name |
2751 | 2754 |
copyfile(app_doc_data.getTemplateDbPath(), name) |
2752 | 2755 |
|
2753 |
matches = [drawing for drawing in app_doc_data.getDrawings() if
|
|
2756 |
matches = [drawing for drawing in app_doc_data.get_drawings() if
|
|
2754 | 2757 |
os.path.exists(drawing.path) and os.path.samefile(drawing.path, name)] |
2755 | 2758 |
if not matches: |
2756 | 2759 |
drawing = Drawing(str(uuid.uuid4()), name, str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) |
2757 |
app_doc_data.saveDrawing(drawing)
|
|
2760 |
app_doc_data.save_drawing(drawing)
|
|
2758 | 2761 |
else: |
2759 | 2762 |
drawing = Drawing(str(matches[0].UID), name, str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) |
2760 |
app_doc_data.updateDrawing(drawing)
|
|
2763 |
app_doc_data.update_drawing(drawing)
|
|
2761 | 2764 |
|
2762 | 2765 |
self.load_drawing_list() |
2763 | 2766 |
self.open_border_file() |
... | ... | |
2782 | 2785 |
from datetime import datetime |
2783 | 2786 |
|
2784 | 2787 |
app_doc_data = AppDocData.instance() |
2785 |
drawings = app_doc_data.getDrawings()
|
|
2786 |
matches = [drawing for drawing in drawings if os.path.samefile(drawing.path, name)] |
|
2788 |
drawings = app_doc_data.get_drawings()
|
|
2789 |
matches = [drawing for drawing in drawings if os.path.samefile(drawing.org_path, name)]
|
|
2787 | 2790 |
if not matches: |
2788 | 2791 |
drawing = Drawing(str(uuid.uuid4()), name, str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) |
2789 |
app_doc_data.saveDrawing(drawing)
|
|
2792 |
app_doc_data.save_drawing(drawing)
|
|
2790 | 2793 |
|
2791 | 2794 |
self.load_drawing_list() |
2792 | 2795 |
else: |
내보내기 Unified diff