ProjectFlask/FlaskMigrateExtension/MigrateSummaryDialog.py

Tue, 01 Dec 2020 20:22:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 01 Dec 2020 20:22:23 +0100
changeset 47
144b67fd111a
parent 39
120f30d7b949
child 60
02243723ac17
permissions
-rw-r--r--

Started implementing project specific flask settings.

35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de>
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog showing a summary of all created.migrations.
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt5.QtCore import pyqtSlot, Qt, QProcess, QEventLoop, QTimer
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt5.QtGui import QGuiApplication
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt5.QtWidgets import (
39
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
13 QDialog, QDialogButtonBox, QAbstractButton, QTreeWidgetItem,
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
14 QAbstractItemView
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 )
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from E5Gui import E5MessageBox
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from .Ui_MigrateSummaryDialog import Ui_MigrateSummaryDialog
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 class MigrateSummaryDialog(QDialog, Ui_MigrateSummaryDialog):
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Class implementing a dialog showing a summary of all created.migrations.
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 def __init__(self, project, migrateProject, migrations="", parent=None):
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Constructor
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
36
548dea93941c Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
30 @param project reference to the project object
548dea93941c Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
31 @type Project
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @param migrateProject reference to the migrate project extension
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @type MigrateProject
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @param migrations directory path containing the migrations
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @type str
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @param parent reference to the parent widget
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @type QWidget
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 super(MigrateSummaryDialog, self).__init__(parent)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.setupUi(self)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.__refreshButton = self.buttonBox.addButton(
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.tr("Refresh"), QDialogButtonBox.ActionRole)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.__refreshButton.clicked.connect(self.showSummary)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.__project = project
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.__migrateProject = migrateProject
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__migrations = migrations
39
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
49
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.__process = None
39
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
51 self.__currentItemIndex = 1000000
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
52 self.__currentRevision = ""
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 def showSummary(self):
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 Public method to show the migrations summary.
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 workdir, env = self.__project.prepareRuntimeEnvironment()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 if env is not None:
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.show()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.raise_()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.buttonBox.button(QDialogButtonBox.Cancel).setFocus(
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 Qt.OtherFocusReason)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 QGuiApplication.processEvents(QEventLoop.ExcludeUserInputEvents)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 command = self.__project.getFlaskCommand()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__process = QProcess()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__process.setProcessEnvironment(env)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.__process.setWorkingDirectory(workdir)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 args = ["db", "history", "--indicate-current"]
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 if self.__migrations:
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 args += ["--directory", self.__migrations]
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 QGuiApplication.setOverrideCursor(Qt.WaitCursor)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.__process.start(command, args)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 ok = self.__process.waitForStarted(10000)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 if ok:
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 ok = self.__process.waitForFinished(10000)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 if ok:
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 out = str(self.__process.readAllStandardOutput(), "utf-8")
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.__processOutput(out)
39
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
88 self.__selectItem(self.__currentRevision)
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 else:
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 E5MessageBox.critical(
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 None,
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.tr("Migrations Summary"),
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.tr("""The Flask process did not finish within"""
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """ 10 seconds."""))
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 else:
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 E5MessageBox.critical(
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 None,
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.tr("Migrations Summary"),
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 self.tr("""The Flask process could not be started."""))
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 for column in range(self.summaryWidget.columnCount()):
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 self.summaryWidget.resizeColumnToContents(column)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 QGuiApplication.restoreOverrideCursor()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 self.buttonBox.button(QDialogButtonBox.Close).setFocus(
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 Qt.OtherFocusReason)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 def __processOutput(self, output):
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 Private method to process the flask output and populate the summary
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 list.
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @param output output of the flask process
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @type str
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 self.summaryWidget.clear()
39
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
119 self.upDownButton.setEnabled(False)
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
120 self.__currentItemIndex = 1000000
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
121 self.__currentRevision = ""
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 lines = output.splitlines()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 for line in lines:
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 isCurrent = False
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 oldRev, rest = line.split("->")
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 rest, message = rest.split(",", 1)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 newRev, *labels = rest.split()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 if labels:
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 labelList = [
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 label.replace("(", "").replace(")", "")
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 for label in labels
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 ]
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 labelsStr = ", ".join(labelList)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 if "current" in labelList:
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 isCurrent = True
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 else:
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 labelsStr = ""
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 itm = QTreeWidgetItem(self.summaryWidget, [
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 oldRev.strip(),
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 newRev.strip(),
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 message.strip(),
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 labelsStr,
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 ])
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 if isCurrent:
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 font = itm.font(0)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 font.setBold(True)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 for column in range(self.summaryWidget.columnCount()):
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 itm.setFont(column, font)
39
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
151
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
152 self.__currentItemIndex = (
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
153 self.summaryWidget.indexOfTopLevelItem(itm)
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
154 )
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
155 self.__currentRevision = newRev.strip()
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 @pyqtSlot()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 def on_summaryWidget_itemSelectionChanged(self):
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 Private slot to handle the selection of an entry.
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 """
39
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
162 items = self.summaryWidget.selectedItems()
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
163 if items:
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
164 index = self.summaryWidget.indexOfTopLevelItem(items[0])
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
165 if index < self.__currentItemIndex:
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
166 self.upDownButton.setText(self.tr("Upgrade"))
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
167 elif index > self.__currentItemIndex:
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
168 self.upDownButton.setText(self.tr("Downgrade"))
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
169 self.upDownButton.setEnabled(index != self.__currentItemIndex)
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
170 else:
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
171 self.upDownButton.setEnabled(False)
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 @pyqtSlot()
39
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
174 def on_upDownButton_clicked(self):
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 """
39
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
176 Private slot to upgrade/downgrade to the selected revision.
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 itm = self.summaryWidget.selectedItems()[0]
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 rev = itm.text(1)
39
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
180 if self.upDownButton.text() == self.tr("Upgrade"):
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
181 self.__migrateProject.upgradeDatabase(revision=rev)
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
182 else:
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
183 self.__migrateProject.downgradeDatabase(revision=rev)
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 self.showSummary()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 @pyqtSlot(QAbstractButton)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 def on_buttonBox_clicked(self, button):
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 """
36
548dea93941c Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 35
diff changeset
189 Private slot handling a button press of the button box.
35
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 @param button reference to the pressed button
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 @type QAbstractButton
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 if button is self.buttonBox.button(QDialogButtonBox.Cancel):
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 self.__cancelProcess()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 @pyqtSlot()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 def __cancelProcess(self):
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 Private slot to terminate the current process.
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 """
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 if (
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 self.__process is not None and
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 self.__process.state() != QProcess.NotRunning
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 ):
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 self.__process.terminate()
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 QTimer.singleShot(2000, self.__process.kill)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 self.__process.waitForFinished(3000)
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209
65a377b7a52c Added actions to show a migrations summary and migrations history.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 self.__process = None
39
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
211
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
212 def __selectItem(self, revision):
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
213 """
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
214 Private method to select an item given its revision.
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
215
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
216 @param revision revision of the item to select
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
217 @type str
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
218 """
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
219 if revision:
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
220 items = self.summaryWidget.findItems(
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
221 revision, Qt.MatchExactly, 1)
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
222 if items:
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
223 # select the first item
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
224 items[0].setSelected(True)
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
225 self.summaryWidget.scrollToItem(
120f30d7b949 MigrateSummaryDialog: fine tuned the dialog handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 36
diff changeset
226 items[0], QAbstractItemView.PositionAtCenter)

eric ide

mercurial