src/eric7/Plugins/VcsPlugins/vcsGit/GitPatchStatisticsDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
21 21
22 class GitPatchStatisticsDialog(QDialog, Ui_GitPatchStatisticsDialog): 22 class GitPatchStatisticsDialog(QDialog, Ui_GitPatchStatisticsDialog):
23 """ 23 """
24 Class implementing a dialog to show some patch file statistics. 24 Class implementing a dialog to show some patch file statistics.
25 """ 25 """
26
26 def __init__(self, vcs, parent=None): 27 def __init__(self, vcs, parent=None):
27 """ 28 """
28 Constructor 29 Constructor
29 30
30 @param vcs reference to the VCS object (Git) 31 @param vcs reference to the VCS object (Git)
31 @param parent reference to the parent widget (QWidget) 32 @param parent reference to the parent widget (QWidget)
32 """ 33 """
33 super().__init__(parent) 34 super().__init__(parent)
34 self.setupUi(self) 35 self.setupUi(self)
35 self.setWindowFlags(Qt.WindowType.Window) 36 self.setWindowFlags(Qt.WindowType.Window)
36 37
37 self.__vcs = vcs 38 self.__vcs = vcs
38 39
39 self.changesTreeWidget.headerItem().setText( 40 self.changesTreeWidget.headerItem().setText(
40 self.changesTreeWidget.columnCount(), "") 41 self.changesTreeWidget.columnCount(), ""
41 self.changesTreeWidget.header().setSortIndicator( 42 )
42 2, Qt.SortOrder.AscendingOrder) 43 self.changesTreeWidget.header().setSortIndicator(2, Qt.SortOrder.AscendingOrder)
43 44
44 def start(self, projectDir, patchCheckData): 45 def start(self, projectDir, patchCheckData):
45 """ 46 """
46 Public method to start the statistics process. 47 Public method to start the statistics process.
47 48
48 @param projectDir directory name of the project (string) 49 @param projectDir directory name of the project (string)
49 @param patchCheckData tuple of data as returned by the 50 @param patchCheckData tuple of data as returned by the
50 GitPatchFilesDialog.getData() method 51 GitPatchFilesDialog.getData() method
51 """ 52 """
52 self.__patchCheckData = patchCheckData 53 self.__patchCheckData = patchCheckData
53 54
54 self.changesTreeWidget.clear() 55 self.changesTreeWidget.clear()
55 self.summaryEdit.clear() 56 self.summaryEdit.clear()
56 57
57 # find the root of the repo 58 # find the root of the repo
58 repodir = projectDir 59 repodir = projectDir
59 while not os.path.isdir(os.path.join(repodir, self.__vcs.adminDir)): 60 while not os.path.isdir(os.path.join(repodir, self.__vcs.adminDir)):
60 repodir = os.path.dirname(repodir) 61 repodir = os.path.dirname(repodir)
61 if os.path.splitdrive(repodir)[1] == os.sep: 62 if os.path.splitdrive(repodir)[1] == os.sep:
62 return 63 return
63 64
64 from .GitPatchFilesDialog import GitPatchFilesDialog 65 from .GitPatchFilesDialog import GitPatchFilesDialog
66
65 dlg = GitPatchFilesDialog(repodir, patchCheckData) 67 dlg = GitPatchFilesDialog(repodir, patchCheckData)
66 if dlg.exec() == QDialog.DialogCode.Accepted: 68 if dlg.exec() == QDialog.DialogCode.Accepted:
67 patchFilesList, stripCount, inaccurateEof, recount = dlg.getData() 69 patchFilesList, stripCount, inaccurateEof, recount = dlg.getData()
68 self.__patchCheckData = (patchFilesList, stripCount, 70 self.__patchCheckData = (patchFilesList, stripCount, inaccurateEof, recount)
69 inaccurateEof, recount)
70 if patchFilesList: 71 if patchFilesList:
71 process = QProcess() 72 process = QProcess()
72 process.setWorkingDirectory(repodir) 73 process.setWorkingDirectory(repodir)
73 74
74 # step 1: get the statistics 75 # step 1: get the statistics
75 args = self.__vcs.initCommand("apply") 76 args = self.__vcs.initCommand("apply")
76 args.append("--numstat") 77 args.append("--numstat")
77 if inaccurateEof: 78 if inaccurateEof:
78 args.append("--inaccurate-eof") 79 args.append("--inaccurate-eof")
79 if recount: 80 if recount:
80 args.append("--recount") 81 args.append("--recount")
81 args.append("-p{0}".format(stripCount)) 82 args.append("-p{0}".format(stripCount))
82 args.extend(patchFilesList) 83 args.extend(patchFilesList)
83 84
84 process.start('git', args) 85 process.start("git", args)
85 procStarted = process.waitForStarted(5000) 86 procStarted = process.waitForStarted(5000)
86 if not procStarted: 87 if not procStarted:
87 EricMessageBox.critical( 88 EricMessageBox.critical(
88 self, 89 self,
89 self.tr('Process Generation Error'), 90 self.tr("Process Generation Error"),
90 self.tr( 91 self.tr(
91 'The process {0} could not be started. ' 92 "The process {0} could not be started. "
92 'Ensure, that it is in the search path.' 93 "Ensure, that it is in the search path."
93 ).format('git')) 94 ).format("git"),
95 )
94 return 96 return
95 else: 97 else:
96 finished = process.waitForFinished(30000) 98 finished = process.waitForFinished(30000)
97 if finished and process.exitCode() == 0: 99 if finished and process.exitCode() == 0:
98 output = str(process.readAllStandardOutput(), 100 output = str(
99 Preferences.getSystem("IOEncoding"), 101 process.readAllStandardOutput(),
100 'replace') 102 Preferences.getSystem("IOEncoding"),
103 "replace",
104 )
101 for line in output.splitlines(): 105 for line in output.splitlines():
102 self.__createStatisticsItem(line) 106 self.__createStatisticsItem(line)
103 107
104 # step 2: get the summary 108 # step 2: get the summary
105 args = self.__vcs.initCommand("apply") 109 args = self.__vcs.initCommand("apply")
106 args.append("--summary") 110 args.append("--summary")
107 if inaccurateEof: 111 if inaccurateEof:
108 args.append("--inaccurate-eof") 112 args.append("--inaccurate-eof")
109 if recount: 113 if recount:
110 args.append("--recount") 114 args.append("--recount")
111 args.append("-p{0}".format(stripCount)) 115 args.append("-p{0}".format(stripCount))
112 args.extend(patchFilesList) 116 args.extend(patchFilesList)
113 117
114 process.start('git', args) 118 process.start("git", args)
115 procStarted = process.waitForStarted(5000) 119 procStarted = process.waitForStarted(5000)
116 if not procStarted: 120 if not procStarted:
117 EricMessageBox.critical( 121 EricMessageBox.critical(
118 self, 122 self,
119 self.tr('Process Generation Error'), 123 self.tr("Process Generation Error"),
120 self.tr( 124 self.tr(
121 'The process {0} could not be started. ' 125 "The process {0} could not be started. "
122 'Ensure, that it is in the search path.' 126 "Ensure, that it is in the search path."
123 ).format('git')) 127 ).format("git"),
128 )
124 return 129 return
125 else: 130 else:
126 finished = process.waitForFinished(30000) 131 finished = process.waitForFinished(30000)
127 if finished and process.exitCode() == 0: 132 if finished and process.exitCode() == 0:
128 output = str(process.readAllStandardOutput(), 133 output = str(
129 Preferences.getSystem("IOEncoding"), 134 process.readAllStandardOutput(),
130 'replace') 135 Preferences.getSystem("IOEncoding"),
136 "replace",
137 )
131 for line in output.splitlines(): 138 for line in output.splitlines():
132 self.summaryEdit.appendPlainText(line.strip()) 139 self.summaryEdit.appendPlainText(line.strip())
133 140
134 def __createStatisticsItem(self, line): 141 def __createStatisticsItem(self, line):
135 """ 142 """
136 Private method to create a file statistics entry. 143 Private method to create a file statistics entry.
137 144
138 @param line string with file statistics data (string) 145 @param line string with file statistics data (string)
139 """ 146 """
140 insertions, deletions, filename = line.strip().split(None, 2) 147 insertions, deletions, filename = line.strip().split(None, 2)
141 itm = QTreeWidgetItem(self.changesTreeWidget, 148 itm = QTreeWidgetItem(self.changesTreeWidget, [insertions, deletions, filename])
142 [insertions, deletions, filename])
143 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight) 149 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight)
144 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight) 150 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight)
145 151
146 def __resizeColumns(self): 152 def __resizeColumns(self):
147 """ 153 """
148 Private method to resize the list columns. 154 Private method to resize the list columns.
149 """ 155 """
150 self.changesTreeWidget.header().resizeSections( 156 self.changesTreeWidget.header().resizeSections(
151 QHeaderView.ResizeMode.ResizeToContents) 157 QHeaderView.ResizeMode.ResizeToContents
158 )
152 self.changesTreeWidget.header().setStretchLastSection(True) 159 self.changesTreeWidget.header().setStretchLastSection(True)
153 160
154 def getData(self): 161 def getData(self):
155 """ 162 """
156 Public method to get the data used to generate the statistics. 163 Public method to get the data used to generate the statistics.
157 164
158 @return tuple of list of patch files, strip count, flag indicating 165 @return tuple of list of patch files, strip count, flag indicating
159 that the patch has inaccurate end-of-file marker and a flag 166 that the patch has inaccurate end-of-file marker and a flag
160 indicating to not trust the line count information 167 indicating to not trust the line count information
161 (list of string, integer, boolean, boolean) 168 (list of string, integer, boolean, boolean)
162 """ 169 """

eric ide

mercurial