CxFreeze/CxfreezeExecDialog.py

branch
eric7
changeset 134
7880b294d1d1
parent 131
86d810eea380
child 136
d9228f38cfe8
equal deleted inserted replaced
133:0f3a641c5da5 134:7880b294d1d1
10 import shutil 10 import shutil
11 import errno 11 import errno
12 import fnmatch 12 import fnmatch
13 import os.path 13 import os.path
14 14
15 from PyQt5.QtCore import pyqtSlot, QProcess, QTimer, QThread, pyqtSignal 15 from PyQt6.QtCore import pyqtSlot, QProcess, QTimer, QThread, pyqtSignal
16 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton 16 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton
17 17
18 from E5Gui import E5MessageBox 18 from EricWidgets import EricMessageBox
19 19
20 from .Ui_CxfreezeExecDialog import Ui_CxfreezeExecDialog 20 from .Ui_CxfreezeExecDialog import Ui_CxfreezeExecDialog
21 21
22 import Preferences 22 import Preferences
23 23
37 @param parent parent widget of this dialog (QWidget) 37 @param parent parent widget of this dialog (QWidget)
38 """ 38 """
39 super().__init__(parent) 39 super().__init__(parent)
40 self.setupUi(self) 40 self.setupUi(self)
41 41
42 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 42 self.buttonBox.button(
43 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 43 QDialogButtonBox.StandardButton.Close).setEnabled(False)
44 self.buttonBox.button(
45 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
44 46
45 self.process = None 47 self.process = None
46 self.copyProcess = None 48 self.copyProcess = None
47 self.cmdname = cmdname 49 self.cmdname = cmdname
48 50
49 def start(self, args, parms, ppath, mainscript): 51 def start(self, args, parms, ppath, mainscript):
50 """ 52 """
51 Public slot to start the packager command. 53 Public slot to start the packager command.
52 54
53 @param args commandline arguments for packager program (list of 55 @param args commandline arguments for packager program
54 strings) 56 @type list of str
55 @param parms parameters got from the config dialog (dict) 57 @param parms parameters got from the config dialog
56 @param ppath project path (string) 58 @type dict
59 @param ppath project path
60 @type str
57 @param mainscript main script name to be processed by by the packager 61 @param mainscript main script name to be processed by by the packager
58 (string) 62 @type str
59 @return flag indicating the successful start of the process 63 @return flag indicating the successful start of the process
64 @rtype bool
60 """ 65 """
61 self.errorGroup.hide() 66 self.errorGroup.hide()
62 script = os.path.join(ppath, mainscript) 67 script = os.path.join(ppath, mainscript)
63 dname = os.path.dirname(script) 68 dname = os.path.dirname(script)
64 script = os.path.basename(script) 69 script = os.path.basename(script)
87 92
88 program = args.pop(0) 93 program = args.pop(0)
89 self.process.start(program, args) 94 self.process.start(program, args)
90 procStarted = self.process.waitForStarted() 95 procStarted = self.process.waitForStarted()
91 if not procStarted: 96 if not procStarted:
92 E5MessageBox.critical( 97 EricMessageBox.critical(
93 self, 98 self,
94 self.tr('Process Generation Error'), 99 self.tr('Process Generation Error'),
95 self.tr( 100 self.tr(
96 'The process {0} could not be started. ' 101 'The process {0} could not be started. '
97 'Ensure, that it is in the search path.' 102 'Ensure, that it is in the search path.'
101 @pyqtSlot(QAbstractButton) 106 @pyqtSlot(QAbstractButton)
102 def on_buttonBox_clicked(self, button): 107 def on_buttonBox_clicked(self, button):
103 """ 108 """
104 Private slot called by a button of the button box clicked. 109 Private slot called by a button of the button box clicked.
105 110
106 @param button button that was clicked (QAbstractButton) 111 @param button button that was clicked
107 """ 112 @type QAbstractButton
108 if button == self.buttonBox.button(QDialogButtonBox.Close): 113 """
114 if button == self.buttonBox.button(
115 QDialogButtonBox.StandardButton.Close
116 ):
109 self.accept() 117 self.accept()
110 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): 118 elif button == self.buttonBox.button(
119 QDialogButtonBox.StandardButton.Cancel
120 ):
111 self.additionalFiles = [] # Skip copying additional files 121 self.additionalFiles = [] # Skip copying additional files
112 self.__finish() 122 self.__finish()
113 123
114 def __finish(self): 124 def __finish(self):
115 """ 125 """
116 Private slot called when the process finished. 126 Private slot called when the process finished.
117 127
118 It is called when the process finished or 128 It is called when the process finished or the user pressed the
119 the user pressed the cancel button. 129 cancel button.
120 """ 130 """
121 if self.process is not None: 131 if self.process is not None:
122 self.process.disconnect(self.__finishedFreeze) 132 self.process.disconnect(self.__finishedFreeze)
123 self.process.terminate() 133 self.process.terminate()
124 QTimer.singleShot(2000, self.process.kill) 134 QTimer.singleShot(2000, self.process.kill)
136 146
137 def __finishedFreeze(self): 147 def __finishedFreeze(self):
138 """ 148 """
139 Private slot called when the process finished. 149 Private slot called when the process finished.
140 150
141 It is called when the process finished or 151 It is called when the process finished or the user pressed the
142 the user pressed the cancel button. 152 cancel button.
143 """ 153 """
144 self.process = None 154 self.process = None
145 155
146 self.contents.insertPlainText( 156 self.contents.insertPlainText(
147 self.tr('\n{0} finished.\n').format(self.cmdname)) 157 self.tr('\n{0} finished.\n').format(self.cmdname))
157 167
158 It is called when the process finished or 168 It is called when the process finished or
159 the user pressed the cancel button. 169 the user pressed the cancel button.
160 """ 170 """
161 self.copyProcess = None 171 self.copyProcess = None
162 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 172 self.buttonBox.button(
163 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 173 QDialogButtonBox.StandardButton.Close).setEnabled(True)
164 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 174 self.buttonBox.button(
175 QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
176 self.buttonBox.button(
177 QDialogButtonBox.StandardButton.Close).setDefault(True)
165 self.contents.ensureCursorVisible() 178 self.contents.ensureCursorVisible()
166 179
167 def __readStdout(self): 180 def __readStdout(self):
168 """ 181 """
169 Private slot to handle the readyReadStandardOutput signal. 182 Private slot to handle the readyReadStandardOutput signal.
170 183
171 It reads the output of the process, formats it and inserts it into 184 It reads the output of the process, formats it and inserts it into
172 the contents pane. 185 the contents pane.
173 """ 186 """
174 self.process.setReadChannel(QProcess.StandardOutput) 187 self.process.setReadChannel(QProcess.ProcessChannel.StandardOutput)
175 188
176 while self.process.canReadLine(): 189 while self.process.canReadLine():
177 s = str(self.process.readAllStandardOutput(), 190 s = str(self.process.readAllStandardOutput(),
178 Preferences.getSystem("IOEncoding"), 191 Preferences.getSystem("IOEncoding"),
179 'replace') 192 'replace')
185 Private slot to handle the readyReadStandardError signal. 198 Private slot to handle the readyReadStandardError signal.
186 199
187 It reads the error output of the process and inserts it into the 200 It reads the error output of the process and inserts it into the
188 error pane. 201 error pane.
189 """ 202 """
190 self.process.setReadChannel(QProcess.StandardError) 203 self.process.setReadChannel(QProcess.ProcessChannel.StandardError)
191 204
192 while self.process.canReadLine(): 205 while self.process.canReadLine():
193 self.errorGroup.show() 206 self.errorGroup.show()
194 s = str(self.process.readAllStandardError(), 207 s = str(self.process.readAllStandardError(),
195 Preferences.getSystem("IOEncoding"), 208 Preferences.getSystem("IOEncoding"),
223 """ 236 """
224 Private method to copy a file or folder. 237 Private method to copy a file or folder.
225 238
226 Wildcards allowed. Existing files are overwitten. 239 Wildcards allowed. Existing files are overwitten.
227 240
228 @param src source file or folder to copy. Wildcards allowed. (str) 241 @param src source file or folder to copy. Wildcards allowed.
229 @param dst destination (str) 242 @type str
230 @exception OSError raised if there is an issue writing the package 243 @param dst destination
231 @exception OSError raised if the given source does not exist 244 @type str
232 """ # __IGNORE_WARNING__ 245 @exception OSError raised if there is an issue writing the package or
246 the given source does not exist
247 """
233 def src2dst(srcname, base, dst): 248 def src2dst(srcname, base, dst):
234 """ 249 """
235 Combines the relativ path of the source (srcname) with the 250 Combines the relativ path of the source (srcname) with the
236 destination folder. 251 destination folder.
237 252
238 @param srcname actual file or folder to copy 253 @param srcname actual file or folder to copy
254 @type str
239 @param base basename of the source folder 255 @param base basename of the source folder
256 @type str
240 @param dst basename of the destination folder 257 @param dst basename of the destination folder
258 @type str
241 @return destination path 259 @return destination path
260 @rtype str
242 """ 261 """
243 delta = srcname.split(base)[1] 262 delta = srcname.split(base)[1]
244 return os.path.join(dst, delta[1:]) 263 return os.path.join(dst, delta[1:])
245 264
246 base, fileOrFolderName = os.path.split(src) 265 base, fileOrFolderName = os.path.split(src)
247 initDone = False 266 initDone = False
248 for root, dirs, files in os.walk(base): 267 for root, dirs, files in os.walk(base):
249 copied = False 268 copied = False
250 # remove all none matching directorynames, create all others 269 # remove all none matching directory names, create all others
251 for directory in dirs[:]: 270 for directory in dirs[:]:
252 pathname = os.path.join(root, directory) 271 pathname = os.path.join(root, directory)
253 if initDone or fnmatch.fnmatch(pathname, src): 272 if initDone or fnmatch.fnmatch(pathname, src):
254 newDir = src2dst(pathname, base, dst) 273 newDir = src2dst(pathname, base, dst)
255 # avoid infinite loop 274 # avoid infinite loop

eric ide

mercurial