PluginManager/PluginInstallDialog.py

branch
Py2 comp.
changeset 2911
ce77f0b1ee67
parent 2847
1843ef6e2656
parent 2856
a07f9346e209
child 3056
9986ec0e559a
equal deleted inserted replaced
2847:1843ef6e2656 2911:ce77f0b1ee67
12 import os 12 import os
13 import sys 13 import sys
14 import shutil 14 import shutil
15 import zipfile 15 import zipfile
16 import compileall 16 import compileall
17 import glob
17 try: # Py3 18 try: # Py3
18 import urllib.parse as parse 19 import urllib.parse as parse
19 except (ImportError): 20 except (ImportError):
20 import urlparse as parse 21 import urlparse as parse
21 22
297 pluginSource = Utilities.decode(zip.read(pluginFileName))[0] 298 pluginSource = Utilities.decode(zip.read(pluginFileName))[0]
298 packageName = "" 299 packageName = ""
299 internalPackages = [] 300 internalPackages = []
300 needsRestart = False 301 needsRestart = False
301 pyqtApi = 0 302 pyqtApi = 0
303 doCompile = True
302 for line in pluginSource.splitlines(): 304 for line in pluginSource.splitlines():
303 if line.startswith("packageName"): 305 if line.startswith("packageName"):
304 tokens = line.split("=") 306 tokens = line.split("=")
305 if tokens[0].strip() == "packageName" and \ 307 if tokens[0].strip() == "packageName" and \
306 tokens[1].strip()[1:-1] != "__core__": 308 tokens[1].strip()[1:-1] != "__core__":
320 tokens = line.split("=") 322 tokens = line.split("=")
321 try: 323 try:
322 pyqtApi = int(tokens[1].strip()) 324 pyqtApi = int(tokens[1].strip())
323 except ValueError: 325 except ValueError:
324 pass 326 pass
327 elif line.startswith("doNotCompile"):
328 tokens = line.split("=")
329 if tokens[1].strip() == "True":
330 doCompile = False
325 elif line.startswith("# End-Of-Header"): 331 elif line.startswith("# End-Of-Header"):
326 break 332 break
327 333
328 if not packageName: 334 if not packageName:
329 return False, \ 335 return False, \
437 return False, \ 443 return False, \
438 self.trUtf8("Unspecific exception installing plugin."), \ 444 self.trUtf8("Unspecific exception installing plugin."), \
439 False 445 False
440 446
441 # now compile the plugins 447 # now compile the plugins
442 compileall.compile_dir(destination, quiet=True) 448 if doCompile:
449 compileall.compile_dir(os.path.join(destination, packageName), quiet=True)
450 compileall.compile_file(os.path.join(destination, pluginFileName), quiet=True)
443 451
444 if not self.__external: 452 if not self.__external:
445 # now load and activate the plugin 453 # now load and activate the plugin
446 self.__pluginManager.loadPlugin(installedPluginName, destination, reload_) 454 self.__pluginManager.loadPlugin(installedPluginName, destination, reload_)
447 if activatePlugin: 455 if activatePlugin:
505 513
506 fnamec = "{0}c".format(pluginFile) 514 fnamec = "{0}c".format(pluginFile)
507 if os.path.exists(fnamec): 515 if os.path.exists(fnamec):
508 os.remove(fnamec) 516 os.remove(fnamec)
509 517
518 pluginDirCache = os.path.join(os.path.dirname(pluginFile), "__pycache__")
519 if os.path.exists(pluginDirCache):
520 pluginFileName = os.path.splitext(os.path.basename(pluginFile))[0]
521 for fnameo in glob.glob(
522 os.path.join(pluginDirCache, "{0}*.pyo".format(pluginFileName))):
523 os.remove(fnameo)
524 for fnamec in glob.glob(
525 os.path.join(pluginDirCache, "{0}*.pyc".format(pluginFileName))):
526 os.remove(fnamec)
527
510 os.remove(pluginFile) 528 os.remove(pluginFile)
511 except (IOError, OSError, os.error): 529 except (IOError, OSError, os.error):
512 # ignore some exceptions 530 # ignore some exceptions
513 pass 531 pass
514 532

eric ide

mercurial