Ejemplo n.º 1
0
def autostart(reason, *args, **kwargs):
    if reason == 0:
        if hasattr(PluginComponent, 'pluginSort_baseAddPlugin'):
            print(
                "[PluginSort] Something went wrong as our autostart handler was called multiple times for startup, printing traceback and ignoring."
            )
            import traceback, sys
            traceback.print_stack(limit=5, file=sys.stdout)
        else:
            PluginComponent.pluginSort_baseAddPlugin = PluginComponent.addPlugin
            PluginComponent.addPlugin = PluginComponent_addPlugin

            # we use a copy for installed plugins because we might change the 'where'-lists
            plugins.installedPluginList = plugins.pluginList[:]

            def PluginComponent__setattr__(self, key, value):
                if key == 'installedPluginList': return
                else: self.__dict__[key] = value

            PluginComponent.__setattr__ = PluginComponent__setattr__

            if hasattr(plugins, 'PluginComponent.pluginHider_baseGetPlugins'):
                pluginlist = plugins.pluginHider_baseGetPlugins([
                    PluginDescriptor.WHERE_PLUGINMENU,
                    PluginDescriptor.WHERE_EXTENSIONSMENU,
                    PluginDescriptor.WHERE_MOVIELIST,
                    PluginDescriptor.WHERE_EVENTINFO
                ])
            else:
                pluginlist = plugins.getPlugins([
                    PluginDescriptor.WHERE_PLUGINMENU,
                    PluginDescriptor.WHERE_EXTENSIONSMENU,
                    PluginDescriptor.WHERE_MOVIELIST,
                    PluginDescriptor.WHERE_EVENTINFO
                ])

            # "fix" weight of plugins already added to list, future ones will be fixed automatically
            fixed = []
            for plugin in pluginlist:
                if plugin in fixed: continue  # skip double entries

                # create individual entries for multiple wheres, this is potentially harmful!
                if len(plugin.where) > 1:
                    # remove all entries except for a potential autostart one (highly unlikely to mix autostart with one of the above, but you never know :D)
                    if PluginDescriptor.WHERE_AUTOSTART in plugin.where:
                        plugin.where.remove(PluginDescriptor.WHERE_AUTOSTART)
                        hadAutostart = True
                    else:
                        hadAutostart = False
                    plugins.removePlugin(plugin)
                    plugins.addPlugin(
                        plugin
                    )  # this is our own addPlugin now, which automatically creates copies

                    # HACK: re-add autostart entry to internal list inside PluginComponent
                    if hadAutostart:
                        plugin.where = [PluginDescriptor.WHERE_AUTOSTART]
                        plugins.pluginList.append(plugin)

                # we're keeping the entry, just fix the weight
                else:
                    newWeight = pluginWeights.get(plugin)
                    print(
                        "[PluginSort] Fixing weight for %s (was %d, now %d)" %
                        (plugin.name, plugin.weight, newWeight))
                    plugin.weight = newWeight

                fixed.append(plugin)

            # let movieepg fix extensions list sorting if installed, else do this ourselves
            if not fileExists(
                    resolveFilename(SCOPE_PLUGINS,
                                    "Extensions/MovieEPG/plugin.py")):

                def InfoBarPlugins_getPluginList(self, *args, **kwargs):
                    l = InfoBarPlugins.pluginSort_baseGetPluginList(
                        self, *args, **kwargs)
                    try:
                        l.sort(key=lambda e: (e[0][1].args[0].weight, e[2]))
                    except Exception as e:
                        print("[PluginSort] Failed to sort extensions", e)
                    return l

                InfoBarPlugins.pluginSort_baseGetPluginList = InfoBarPlugins.getPluginList
                InfoBarPlugins.getPluginList = InfoBarPlugins_getPluginList

            PluginBrowser.PluginBrowser = SortingPluginBrowser
    else:
        if hasattr(PluginComponent, 'pluginSort_baseAddPlugin'):
            PluginComponent.addPlugin = PluginComponent.pluginSort_baseAddPlugin
            del PluginComponent.pluginSort_baseAddPlugin
        if hasattr(InfoBarPlugins, 'pluginSort_baseGetPluginList'):
            InfoBarPlugins.getPluginList = InfoBarPlugins.pluginSort_baseGetPluginList
            del InfoBarPlugins.pluginSort_baseGetPluginList
        PluginBrowser.PluginBrowser = OriginalPluginBrowser
Ejemplo n.º 2
0
def autostart(reason, *args, **kwargs):
	if reason == 0:
		if hasattr(PluginComponent, 'pluginSort_baseAddPlugin'):
			print("[PluginSort] Something went wrong as our autostart handler was called multiple times for startup, printing traceback and ignoring.")
			import traceback, sys
			traceback.print_stack(limit=5, file=sys.stdout)
		else:
			PluginComponent.pluginSort_baseAddPlugin = PluginComponent.addPlugin
			PluginComponent.addPlugin = PluginComponent_addPlugin

			# we use a copy for installed plugins because we might change the 'where'-lists
			plugins.installedPluginList = plugins.pluginList[:]
			def PluginComponent__setattr__(self, key, value):
				if key == 'installedPluginList': return
				else: self.__dict__[key] = value
			PluginComponent.__setattr__ = PluginComponent__setattr__

			if hasattr(plugins, 'pluginHider_baseGetPlugins'):
				pluginlist = plugins.pluginHider_baseGetPlugins([PluginDescriptor.WHERE_PLUGINMENU, PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_MOVIELIST, PluginDescriptor.WHERE_EVENTINFO])
			else:
				pluginlist = plugins.getPlugins([PluginDescriptor.WHERE_PLUGINMENU, PluginDescriptor.WHERE_EXTENSIONSMENU, PluginDescriptor.WHERE_MOVIELIST, PluginDescriptor.WHERE_EVENTINFO])

			# "fix" weight of plugins already added to list, future ones will be fixed automatically
			fixed = []
			for plugin in pluginlist:
				if plugin in fixed: continue # skip double entries

				# create individual entries for multiple wheres, this is potentially harmful!
				if len(plugin.where) > 1:
					# remove all entries except for a potential autostart one (highly unlikely to mix autostart with one of the above, but you never know :D)
					if PluginDescriptor.WHERE_AUTOSTART in plugin.where:
						plugin.where.remove(PluginDescriptor.WHERE_AUTOSTART)
						hadAutostart = True
					else:
						hadAutostart = False
					plugins.removePlugin(plugin)
					plugins.addPlugin(plugin) # this is our own addPlugin now, which automatically creates copies

					# HACK: re-add autostart entry to internal list inside PluginComponent
					if hadAutostart:
						plugin.where = [ PluginDescriptor.WHERE_AUTOSTART ]
						plugins.pluginList.append(plugin)

				# we're keeping the entry, just fix the weight
				else:
					newWeight = pluginWeights.get(plugin)
					print("[PluginSort] Fixing weight for %s (was %d, now %d)" % (plugin.name, plugin.weight, newWeight))
					plugin.weight = newWeight

				fixed.append(plugin)

			# let movieepg fix extensions list sorting if installed, else do this ourselves
			if not fileExists(resolveFilename(SCOPE_PLUGINS, "Extensions/MovieEPG/plugin.py")):
				def InfoBarPlugins_getPluginList(self, *args, **kwargs):
					l = InfoBarPlugins.pluginSort_baseGetPluginList(self, *args, **kwargs)
					try:
						l.sort(key=lambda e: (e[0][1].args[0].weight, e[2]))
					except Exception as e:
						print("[PluginSort] Failed to sort extensions", e)
					return l

				InfoBarPlugins.pluginSort_baseGetPluginList = InfoBarPlugins.getPluginList
				InfoBarPlugins.getPluginList = InfoBarPlugins_getPluginList


			PluginBrowser.PluginBrowser = SortingPluginBrowser
	else:
		if hasattr(PluginComponent, 'pluginSort_baseAddPlugin'):
			PluginComponent.addPlugin = PluginComponent.pluginSort_baseAddPlugin
			del PluginComponent.pluginSort_baseAddPlugin
		if hasattr(InfoBarPlugins, 'pluginSort_baseGetPluginList'):
			InfoBarPlugins.getPluginList = InfoBarPlugins.pluginSort_baseGetPluginList
			del InfoBarPlugins.pluginSort_baseGetPluginList
		PluginBrowser.PluginBrowser = OriginalPluginBrowser