PluginManager/PluginInstallDialog.py

changeset 2854
2de1955c6391
parent 2824
858412c29c34
child 2856
a07f9346e209
equal deleted inserted replaced
2853:0866c3aac79f 2854:2de1955c6391
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 urllib.parse 15 import urllib.parse
16 import glob
16 17
17 from PyQt4.QtCore import pyqtSlot, Qt, QDir, QFileInfo 18 from PyQt4.QtCore import pyqtSlot, Qt, QDir, QFileInfo
18 from PyQt4.QtGui import QWidget, QDialogButtonBox, QAbstractButton, QApplication, \ 19 from PyQt4.QtGui import QWidget, QDialogButtonBox, QAbstractButton, QApplication, \
19 QDialog, QVBoxLayout 20 QDialog, QVBoxLayout
20 21
292 pluginSource = Utilities.decode(zip.read(pluginFileName))[0] 293 pluginSource = Utilities.decode(zip.read(pluginFileName))[0]
293 packageName = "" 294 packageName = ""
294 internalPackages = [] 295 internalPackages = []
295 needsRestart = False 296 needsRestart = False
296 pyqtApi = 0 297 pyqtApi = 0
298 doCompile = True
297 for line in pluginSource.splitlines(): 299 for line in pluginSource.splitlines():
298 if line.startswith("packageName"): 300 if line.startswith("packageName"):
299 tokens = line.split("=") 301 tokens = line.split("=")
300 if tokens[0].strip() == "packageName" and \ 302 if tokens[0].strip() == "packageName" and \
301 tokens[1].strip()[1:-1] != "__core__": 303 tokens[1].strip()[1:-1] != "__core__":
315 tokens = line.split("=") 317 tokens = line.split("=")
316 try: 318 try:
317 pyqtApi = int(tokens[1].strip()) 319 pyqtApi = int(tokens[1].strip())
318 except ValueError: 320 except ValueError:
319 pass 321 pass
322 elif line.startswith("doNotCompile"):
323 tokens = line.split("=")
324 if tokens[1].strip() == "True":
325 doCompile = False
320 elif line.startswith("# End-Of-Header"): 326 elif line.startswith("# End-Of-Header"):
321 break 327 break
322 328
323 if not packageName: 329 if not packageName:
324 return False, \ 330 return False, \
432 return False, \ 438 return False, \
433 self.trUtf8("Unspecific exception installing plugin."), \ 439 self.trUtf8("Unspecific exception installing plugin."), \
434 False 440 False
435 441
436 # now compile the plugins 442 # now compile the plugins
437 compileall.compile_dir(destination, quiet=True) 443 if doCompile:
444 compileall.compile_dir(destination, quiet=True)
438 445
439 if not self.__external: 446 if not self.__external:
440 # now load and activate the plugin 447 # now load and activate the plugin
441 self.__pluginManager.loadPlugin(installedPluginName, destination, reload_) 448 self.__pluginManager.loadPlugin(installedPluginName, destination, reload_)
442 if activatePlugin: 449 if activatePlugin:
500 507
501 fnamec = "{0}c".format(pluginFile) 508 fnamec = "{0}c".format(pluginFile)
502 if os.path.exists(fnamec): 509 if os.path.exists(fnamec):
503 os.remove(fnamec) 510 os.remove(fnamec)
504 511
512 pluginDirCache = os.path.join(os.path.dirname(pluginFile), "__pycache__")
513 if os.path.exists(pluginDirCache):
514 pluginFileName = os.path.splitext(os.path.basename(pluginFile))[0]
515 for fnameo in glob.glob(
516 os.path.join(pluginDirCache, "{0}*.pyo".format(pluginFileName))):
517 os.remove(fnameo)
518 for fnamec in glob.glob(
519 os.path.join(pluginDirCache, "{0}*.pyc".format(pluginFileName))):
520 os.remove(fnamec)
521
505 os.remove(pluginFile) 522 os.remove(pluginFile)
506 except (IOError, OSError, os.error): 523 except (IOError, OSError, os.error):
507 # ignore some exceptions 524 # ignore some exceptions
508 pass 525 pass
509 526

eric ide

mercurial