Description: Add support for unpacked Eggs Origin: Debian Forwarded: https://bugs.launchpad.net/jokosher/+bug/385930 Index: jokosher-0.11.3/Jokosher/ExtensionManager.py =================================================================== --- jokosher-0.11.3.orig/Jokosher/ExtensionManager.py 2009-11-11 22:18:03.640628491 +0100 +++ jokosher-0.11.3/Jokosher/ExtensionManager.py 2009-11-11 22:17:57.032635666 +0100 @@ -223,6 +223,46 @@ #_____________________________________________________________________ + def LoadExtensionsFromEggs(self, directory): + """ + Tries to load Extensions fron a given directory. + + Parameters: + directory -- full path to the directory containing Eggs. + + Returns: + True -- the Extension was successfully loaded. + False -- an error ocurred while trying to load the Extension, + or the Extension has been disabled via the ExtensionManagerDialog. + """ + Globals.debug("\timporting extensions from directory", directory) + pkg_resources.working_set.add_entry(directory) + dist_generator = pkg_resources.find_distributions(directory) + for dist in dist_generator: + try: + extension_class = dist.load_entry_point("jokosher.extensions", "extension") + # create an instance of the class + extension = extension_class() + filename = dist.egg_name() + except Exception, e : + Globals.debug("\t\t...failed.") + Globals.debug(e) + return False + + # try and register the extension - continue if failed + if not self.register(extension, filename, directory, False): + Globals.debug("\tcannot register extension ", filename) + continue + + # if we're still here then start the extension, if its not in the extensions_blacklist + if extension.EXTENSION_NAME not in Globals.settings.extensions['extensions_blacklist']: + if not self.StartExtension(self.loadedExtensions[len(self.loadedExtensions)-1]["filename"]): + continue + + return True + + #_____________________________________________________________________ + def StopExtension(self, filename): """ Stops the given Extension. @@ -343,11 +383,16 @@ if not os.path.isdir(exten_dir): continue for filename in os.listdir(exten_dir): - if filename.endswith(".egg") or filename.endswith(".py"): + if filename.endswith('.py'): self.LoadExtensionFromFile(filename, exten_dir) # don't block the gui when loading many extensions while gtk.events_pending(): gtk.main_iteration() + # handle Eggs (zipped or unpacked) here + self.LoadExtensionsFromEggs(exten_dir) + # don't block the gui when loading many extensions + while gtk.events_pending(): + gtk.main_iteration() #_____________________________________________________________________