54 |
54 |
55 def start(self, args, parms, ppath, mainscript): |
55 def start(self, args, parms, ppath, mainscript): |
56 """ |
56 """ |
57 Public slot to start the packager command. |
57 Public slot to start the packager command. |
58 |
58 |
59 @param args commandline arguments for packager program (list of strings) |
59 @param args commandline arguments for packager program (list of |
|
60 strings) |
60 @param parms parameters got from the config dialog (dict) |
61 @param parms parameters got from the config dialog (dict) |
61 @param ppath project path (string) |
62 @param ppath project path (string) |
62 @param script main script name to be processed by by the packager (string) |
63 @param mainscript main script name to be processed by by the packager |
|
64 (string) |
63 @return flag indicating the successful start of the process |
65 @return flag indicating the successful start of the process |
64 """ |
66 """ |
65 self.errorGroup.hide() |
67 self.errorGroup.hide() |
66 script = os.path.join(ppath, mainscript) |
68 script = os.path.join(ppath, mainscript) |
67 dname = os.path.dirname(script) |
69 dname = os.path.dirname(script) |
68 script = os.path.basename(script) |
70 script = os.path.basename(script) |
69 |
71 |
70 self.ppath = ppath |
72 self.ppath = ppath |
71 self.additionalFiles = parms.get('additionalFiles', []) |
73 self.additionalFiles = parms.get('additionalFiles', []) |
72 self.targetDirectory = os.path.join(parms.get('targetDirectory', 'dist')) |
74 self.targetDirectory = os.path.join( |
|
75 parms.get('targetDirectory', 'dist')) |
73 |
76 |
74 self.contents.clear() |
77 self.contents.clear() |
75 self.errors.clear() |
78 self.errors.clear() |
76 |
79 |
77 args.append(script) |
80 args.append(script) |
81 |
84 |
82 self.process.readyReadStandardOutput.connect(self.__readStdout) |
85 self.process.readyReadStandardOutput.connect(self.__readStdout) |
83 self.process.readyReadStandardError.connect(self.__readStderr) |
86 self.process.readyReadStandardError.connect(self.__readStderr) |
84 self.process.finished.connect(self.__finishedFreeze) |
87 self.process.finished.connect(self.__finishedFreeze) |
85 |
88 |
86 self.setWindowTitle(self.trUtf8('{0} - {1}').format(self.cmdname, script)) |
89 self.setWindowTitle(self.trUtf8('{0} - {1}').format( |
|
90 self.cmdname, script)) |
87 self.contents.insertPlainText(' '.join(args) + '\n\n') |
91 self.contents.insertPlainText(' '.join(args) + '\n\n') |
88 self.contents.ensureCursorVisible() |
92 self.contents.ensureCursorVisible() |
89 |
93 |
90 program = args.pop(0) |
94 program = args.pop(0) |
91 self.process.start(program, args) |
95 self.process.start(program, args) |
92 procStarted = self.process.waitForStarted() |
96 procStarted = self.process.waitForStarted() |
93 if not procStarted: |
97 if not procStarted: |
94 E5MessageBox.critical(None, |
98 E5MessageBox.critical( |
|
99 self, |
95 self.trUtf8('Process Generation Error'), |
100 self.trUtf8('Process Generation Error'), |
96 self.trUtf8( |
101 self.trUtf8( |
97 'The process {0} could not be started. ' |
102 'The process {0} could not be started. ' |
98 'Ensure, that it is in the search path.' |
103 'Ensure, that it is in the search path.' |
99 ).format(program)) |
104 ).format(program)) |
145 self.process = None |
150 self.process = None |
146 |
151 |
147 self.contents.insertPlainText( |
152 self.contents.insertPlainText( |
148 self.trUtf8('\n{0} finished.\n').format(self.cmdname)) |
153 self.trUtf8('\n{0} finished.\n').format(self.cmdname)) |
149 |
154 |
150 self.copyProcess = copyAdditionalFiles(self) |
155 self.copyProcess = CopyAdditionalFiles(self) |
151 self.copyProcess.insertPlainText.connect(self.contents.insertPlainText) |
156 self.copyProcess.insertPlainText.connect(self.contents.insertPlainText) |
152 self.copyProcess.finished.connect(self.__enableButtons) |
157 self.copyProcess.finished.connect(self.__enableButtons) |
153 self.copyProcess.start() |
158 self.copyProcess.start() |
154 |
159 |
155 def __enableButtons(self): |
160 def __enableButtons(self): |
197 'replace') |
202 'replace') |
198 self.errors.insertPlainText(s) |
203 self.errors.insertPlainText(s) |
199 self.errors.ensureCursorVisible() |
204 self.errors.ensureCursorVisible() |
200 |
205 |
201 |
206 |
202 class copyAdditionalFiles(QThread): |
207 class CopyAdditionalFiles(QThread): |
203 """ |
208 """ |
204 Thread to copy the distribution dependend files. |
209 Thread to copy the distribution dependend files. |
205 |
210 |
206 @signal insertPlainText(text) emitted to inform user about the copy progress |
211 @signal insertPlainText(text) emitted to inform user about the copy |
|
212 progress |
207 """ |
213 """ |
208 insertPlainText = pyqtSignal(str) |
214 insertPlainText = pyqtSignal(str) |
209 |
215 |
210 def __init__(self, main): |
216 def __init__(self, main): |
211 """ |
217 """ |
212 Constructor, which stores the needed variables. |
218 Constructor, which stores the needed variables. |
213 |
219 |
214 @param main self-object of the caller |
220 @param main self-object of the caller |
215 """ |
221 """ |
216 super(copyAdditionalFiles, self).__init__() |
222 super(CopyAdditionalFiles, self).__init__() |
217 |
223 |
218 self.ppath = main.ppath |
224 self.ppath = main.ppath |
219 self.additionalFiles = main.additionalFiles |
225 self.additionalFiles = main.additionalFiles |
220 self.targetDirectory = main.targetDirectory |
226 self.targetDirectory = main.targetDirectory |
221 |
227 |
222 def __copytree(self, src, dst): |
228 def __copytree(self, src, dst): |
223 """ |
229 """ |
224 Copies a file or folder. Wildcards allowed. Existing files are overwitten. |
230 Private method to copy a file or folder. |
|
231 |
|
232 Wildcards allowed. Existing files are overwitten. |
225 |
233 |
226 @param src source file or folder to copy. Wildcards allowed. (str) |
234 @param src source file or folder to copy. Wildcards allowed. (str) |
227 @param dst destination (str) |
235 @param dst destination (str) |
228 """ |
236 @exception OSError raised if there is an issue writing the package |
|
237 @exception IOError raised if the given source does not exist |
|
238 """ # __IGNORE_WARNING__ |
229 def src2dst(srcname, base, dst): |
239 def src2dst(srcname, base, dst): |
230 """ |
240 """ |
231 Combines the relativ path of the source (srcname) with the |
241 Combines the relativ path of the source (srcname) with the |
232 destination folder. |
242 destination folder. |
233 |
243 |
269 shutil.copy2(fn, newFile) |
280 shutil.copy2(fn, newFile) |
270 copied = True |
281 copied = True |
271 |
282 |
272 # check if file was found and copied |
283 # check if file was found and copied |
273 if len(files) and not copied: |
284 if len(files) and not copied: |
274 raise IOError(errno.ENOENT, |
285 raise IOError( |
275 self.trUtf8("No such file or directory: '{0}'").format(src)) |
286 errno.ENOENT, |
|
287 self.trUtf8("No such file or directory: '{0}'") |
|
288 .format(src)) |
276 |
289 |
277 initDone = True |
290 initDone = True |
278 |
291 |
279 def run(self): |
292 def run(self): |
280 """ |
293 """ |
281 QThread entry point to copy the selected additional files and folders. |
294 QThread entry point to copy the selected additional files and folders. |
|
295 |
|
296 @exception OSError raised if there is an issue writing the package |
282 """ |
297 """ |
283 self.insertPlainText.emit('----\n') |
298 self.insertPlainText.emit('----\n') |
284 os.chdir(self.ppath) |
299 os.chdir(self.ppath) |
285 for fn in self.additionalFiles: |
300 for fn in self.additionalFiles: |
286 self.insertPlainText.emit( |
301 self.insertPlainText.emit( |
294 dirname = fn.split(self.ppath + os.sep)[1] |
309 dirname = fn.split(self.ppath + os.sep)[1] |
295 dst = os.path.join(dst, os.path.dirname(dirname)) |
310 dst = os.path.join(dst, os.path.dirname(dirname)) |
296 try: |
311 try: |
297 os.makedirs(dst) |
312 os.makedirs(dst) |
298 except OSError as err: |
313 except OSError as err: |
299 if err.errno != errno.EEXIST: # it's ok if directory already exists |
314 if err.errno != errno.EEXIST: # it's ok if directory |
|
315 # already exists |
300 raise err |
316 raise err |
301 |
317 |
302 try: |
318 try: |
303 self.__copytree(fn, dst) |
319 self.__copytree(fn, dst) |
304 self.insertPlainText.emit(self.trUtf8('ok')) |
320 self.insertPlainText.emit(self.trUtf8('ok')) |
305 except IOError as err: |
321 except IOError as err: |
306 self.insertPlainText.emit(self.trUtf8('failed: {0}').format(err.strerror)) |
322 self.insertPlainText.emit( |
|
323 self.trUtf8('failed: {0}').format(err.strerror)) |