PluginManager/PluginInstallDialog.py

changeset 12
1d8dd9706f46
parent 7
c679fb30c8f3
child 13
1af94a91f439
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
10 import os 10 import os
11 import sys 11 import sys
12 import shutil 12 import shutil
13 import zipfile 13 import zipfile
14 import compileall 14 import compileall
15 import urlparse 15 import urllib.parse
16 16
17 from PyQt4.QtGui import * 17 from PyQt4.QtGui import *
18 from PyQt4.QtCore import * 18 from PyQt4.QtCore import *
19 19
20 from E4Gui.E4Completers import E4FileCompleter 20 from E4Gui.E4Completers import E4FileCompleter
21 21
22 from PluginManager import PluginManager 22 from .PluginManager import PluginManager
23 from Ui_PluginInstallDialog import Ui_PluginInstallDialog 23 from .Ui_PluginInstallDialog import Ui_PluginInstallDialog
24 24
25 import Utilities 25 import Utilities
26 import Preferences 26 import Preferences
27 27
28 from Utilities.uic import compileUiFiles 28 from Utilities.uic import compileUiFiles
241 destination = \ 241 destination = \
242 self.destinationCombo.itemData(self.destinationCombo.currentIndex())\ 242 self.destinationCombo.itemData(self.destinationCombo.currentIndex())\
243 .toString() 243 .toString()
244 244
245 # check if archive is a local url 245 # check if archive is a local url
246 url = urlparse.urlparse(archive) 246 url = urllib.parse.urlparse(archive)
247 if url[0].lower() == 'file': 247 if url[0].lower() == 'file':
248 archive = url[2] 248 archive = url[2]
249 249
250 # check, if the archive exists 250 # check, if the archive exists
251 if not os.path.exists(archive): 251 if not os.path.exists(archive):
371 self.__installedDirs = [] 371 self.__installedDirs = []
372 self.__installedFiles = [] 372 self.__installedFiles = []
373 try: 373 try:
374 if packageName != "None": 374 if packageName != "None":
375 packageDirs = ["%s/" % packageName, "%s\\" % packageName] 375 packageDirs = ["%s/" % packageName, "%s\\" % packageName]
376 namelist = zip.namelist() 376 namelist = sorted(zip.namelist())
377 namelist.sort()
378 tot = len(namelist) 377 tot = len(namelist)
379 prog = 0 378 prog = 0
380 self.progress.setMaximum(tot) 379 self.progress.setMaximum(tot)
381 QApplication.processEvents() 380 QApplication.processEvents()
382 for name in namelist: 381 for name in namelist:
396 else: 395 else:
397 # it is a file 396 # it is a file
398 d = os.path.dirname(outname) 397 d = os.path.dirname(outname)
399 if not os.path.exists(d): 398 if not os.path.exists(d):
400 self.__makedirs(d) 399 self.__makedirs(d)
401 f = open(outname, "wb") 400 f = open(outname, "w")
402 f.write(zip.read(name)) 401 f.write(zip.read(name))
403 f.close() 402 f.close()
404 self.__installedFiles.append(outname) 403 self.__installedFiles.append(outname)
405 self.progress.setValue(tot) 404 self.progress.setValue(tot)
406 # now compile user interface files 405 # now compile user interface files
407 compileUiFiles(os.path.join(destination, packageName), True) 406 compileUiFiles(os.path.join(destination, packageName), True)
408 else: 407 else:
409 outname = os.path.join(destination, pluginFileName) 408 outname = os.path.join(destination, pluginFileName)
410 f = open(outname, "wb") 409 f = open(outname, "w")
411 f.write(pluginSource) 410 f.write(pluginSource)
412 f.close() 411 f.close()
413 self.__installedFiles.append(outname) 412 self.__installedFiles.append(outname)
414 except os.error, why: 413 except os.error as why:
415 self.__rollback() 414 self.__rollback()
416 return False, \ 415 return False, \
417 self.trUtf8("Error installing plugin. Reason: {0}").format(unicode(why)), \ 416 self.trUtf8("Error installing plugin. Reason: {0}").format(str(why)), \
418 False 417 False
419 except IOError, why: 418 except IOError as why:
420 self.__rollback() 419 self.__rollback()
421 return False, \ 420 return False, \
422 self.trUtf8("Error installing plugin. Reason: {0}").format(unicode(why)), \ 421 self.trUtf8("Error installing plugin. Reason: {0}").format(str(why)), \
423 False 422 False
424 except OSError, why: 423 except OSError as why:
425 self.__rollback() 424 self.__rollback()
426 return False, \ 425 return False, \
427 self.trUtf8("Error installing plugin. Reason: {0}").format(unicode(why)), \ 426 self.trUtf8("Error installing plugin. Reason: {0}").format(str(why)), \
428 False 427 False
429 except: 428 except:
430 print >>sys.stderr, "Unspecific exception installing plugin." 429 print("Unspecific exception installing plugin.", file=sys.stderr)
431 self.__rollback() 430 self.__rollback()
432 return False, \ 431 return False, \
433 self.trUtf8("Unspecific exception installing plugin."), \ 432 self.trUtf8("Unspecific exception installing plugin."), \
434 False 433 False
435 434
453 os.remove(fname) 452 os.remove(fname)
454 for dname in self.__installedDirs: 453 for dname in self.__installedDirs:
455 if os.path.exists(dname): 454 if os.path.exists(dname):
456 shutil.rmtree(dname) 455 shutil.rmtree(dname)
457 456
458 def __makedirs(self, name, mode = 0777): 457 def __makedirs(self, name, mode = 0o777):
459 """ 458 """
460 Private method to create a directory and all intermediate ones. 459 Private method to create a directory and all intermediate ones.
461 460
462 This is an extended version of the Python one in order to 461 This is an extended version of the Python one in order to
463 record the created directories. 462 record the created directories.

eric ide

mercurial