CxFreeze/CxfreezeExecDialog.py

changeset 102
78d1632d4b83
parent 97
72426624feb0
child 106
3bd158b161f1
equal deleted inserted replaced
101:20f85736a29f 102:78d1632d4b83
17 import errno 17 import errno
18 import fnmatch 18 import fnmatch
19 import os.path 19 import os.path
20 20
21 from PyQt5.QtCore import pyqtSlot, QProcess, QTimer, QThread, pyqtSignal 21 from PyQt5.QtCore import pyqtSlot, QProcess, QTimer, QThread, pyqtSignal
22 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton 22 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton
23 23
24 from E5Gui import E5MessageBox 24 from E5Gui import E5MessageBox
25 25
26 from .Ui_CxfreezeExecDialog import Ui_CxfreezeExecDialog 26 from .Ui_CxfreezeExecDialog import Ui_CxfreezeExecDialog
27 27
204 self.errors.ensureCursorVisible() 204 self.errors.ensureCursorVisible()
205 205
206 206
207 class CopyAdditionalFiles(QThread): 207 class CopyAdditionalFiles(QThread):
208 """ 208 """
209 Thread to copy the distribution dependend files. 209 Thread to copy the distribution dependent files.
210 210
211 @signal insertPlainText(text) emitted to inform user about the copy 211 @signal insertPlainText(text) emitted to inform user about the copy
212 progress 212 progress
213 """ 213 """
214 insertPlainText = pyqtSignal(str) 214 insertPlainText = pyqtSignal(str)
215 215
216 def __init__(self, main): 216 def __init__(self, main):
217 """ 217 """
218 Constructor, which stores the needed variables. 218 Constructor
219 219
220 @param main self-object of the caller 220 @param main self-object of the caller
221 """ 221 """
222 super(CopyAdditionalFiles, self).__init__() 222 super(CopyAdditionalFiles, self).__init__()
223 223
252 base, fileOrFolderName = os.path.split(src) 252 base, fileOrFolderName = os.path.split(src)
253 initDone = False 253 initDone = False
254 for root, dirs, files in os.walk(base): 254 for root, dirs, files in os.walk(base):
255 copied = False 255 copied = False
256 # remove all none matching directorynames, create all others 256 # remove all none matching directorynames, create all others
257 for dir in dirs[:]: 257 for directory in dirs[:]:
258 pathname = os.path.join(root, dir) 258 pathname = os.path.join(root, directory)
259 if initDone or fnmatch.fnmatch(pathname, src): 259 if initDone or fnmatch.fnmatch(pathname, src):
260 newDir = src2dst(pathname, base, dst) 260 newDir = src2dst(pathname, base, dst)
261 # avoid infinit loop 261 # avoid infinite loop
262 if fnmatch.fnmatch(newDir, src): 262 if fnmatch.fnmatch(newDir, src):
263 dirs.remove(dir) 263 dirs.remove(directory)
264 continue 264 continue
265 try: 265 try:
266 copied = True 266 copied = True
267 os.makedirs(newDir) 267 os.makedirs(newDir)
268 except OSError as err: 268 except OSError as err:
269 if err.errno != errno.EEXIST: 269 if err.errno != errno.EEXIST:
270 # it's ok if directory already exists 270 # it's ok if directory already exists
271 raise err 271 raise err
272 else: 272 else:
273 dirs.remove(dir) 273 dirs.remove(directory)
274 274
275 for file in files: 275 for file in files:
276 fn = os.path.join(root, file) 276 fn = os.path.join(root, file)
277 if initDone or fnmatch.fnmatch(fn, src): 277 if initDone or fnmatch.fnmatch(fn, src):
278 newFile = src2dst(fn, base, dst) 278 newFile = src2dst(fn, base, dst)
289 289
290 initDone = True 290 initDone = True
291 291
292 def run(self): 292 def run(self):
293 """ 293 """
294 Public method to run the thread.
295
294 QThread entry point to copy the selected additional files and folders. 296 QThread entry point to copy the selected additional files and folders.
295 297
296 @exception OSError raised if there is an issue writing the package 298 @exception OSError raised if there is an issue writing the package
297 """ 299 """
298 self.insertPlainText.emit('----\n') 300 self.insertPlainText.emit('----\n')
309 dirname = fn.split(self.ppath + os.sep)[1] 311 dirname = fn.split(self.ppath + os.sep)[1]
310 dst = os.path.join(dst, os.path.dirname(dirname)) 312 dst = os.path.join(dst, os.path.dirname(dirname))
311 try: 313 try:
312 os.makedirs(dst) 314 os.makedirs(dst)
313 except OSError as err: 315 except OSError as err:
314 if err.errno != errno.EEXIST: # it's ok if directory 316 if err.errno != errno.EEXIST: # it's ok if directory
315 # already exists 317 # already exists
316 raise err 318 raise err
317 319
318 try: 320 try:
319 self.__copytree(fn, dst) 321 self.__copytree(fn, dst)
320 self.insertPlainText.emit(self.tr('ok')) 322 self.insertPlainText.emit(self.tr('ok'))

eric ide

mercurial