Beispiel #1
0
 def update(self):
     xdm.common.addState(3)
     common.SM.setNewMessage("Initialising core update")
     if self.updater.update():
         actionManager.executeAction('reboot', 'Updater')
     xdm.common.removeState(3)
     return True
Beispiel #2
0
    def saveSettings(self, **kwargs):
        redirect_to = '/settings/'
        if 'saveOn' in kwargs:
            redirect_to += "#%s" % kwargs['saveOn']
            del kwargs['saveOn']
        self.ajax.save(**kwargs)
        self.redirect(redirect_to)

        # actions = list(set(actions))
        common.PM.cache()
        final_actions = {}
        for cur_class_name, cur_actions in actions.items():
            for cur_action in cur_actions:
                if not cur_action in final_actions:
                    final_actions[cur_action] = []
                final_actions[cur_action].append(cur_class_name)
        for action, plugins_that_called_it in final_actions.items():
            actionManager.executeAction(action, plugins_that_called_it)
        common.SYSTEM = common.PM.getSystem('Default')[
            0]  # yeah SYSTEM is a plugin
        return json.dumps({
            'result': True,
            'data': {},
            'msg': 'Configuration saved.'
        })
Beispiel #3
0
def main():
    app = App()
    if not app.options.noWebServer:
        try:
            app.startWebServer()
        except IOError:
            log.error("Unable to start web server, is something else running on port %d?" % app.port)
            os._exit(1)
    else:
        log.info('Not starting webserver because of the command line option --noWebServer')
    if not app.options.noApi and common.SYSTEM.c.api_active:
        try:
            api = JSONRPCapi(app.port_api)
        except:
            log.error('could not init jsonrpc api')
            os._exit(1)
        else:
            log('Starting api thread')
            api.start()
    else:
        log.info('Api is OFF')

    try:
        while True:
            time.sleep(1)

    except KeyboardInterrupt:
        actionManager.executeAction('shutdown', 'KeyboardInterrupt')
    os._exit()
Beispiel #4
0
def main():
    app = App()
    if not app.options.noWebServer:
        try:
            app.startWebServer()
        except IOError:
            log.error(
                "Unable to start web server, is something else running on port %d?"
                % app.port)
            os._exit(1)
    else:
        log.info(
            'Not starting webserver because of the command line option --noWebServer'
        )
    if not app.options.noApi and common.SYSTEM.c.api_active:
        try:
            api = JSONRPCapi(app.port_api)
        except:
            log.error('could not init jsonrpc api')
            os._exit(1)
        else:
            log('Starting api thread')
            api.start()
    else:
        log.info('Api is OFF')

    try:
        while True:
            time.sleep(1)

    except KeyboardInterrupt:
        actionManager.executeAction('shutdown', 'KeyboardInterrupt')
    os._exit()
Beispiel #5
0
 def update(self):
     xdm.common.addState(3)
     common.SM.setNewMessage("Initialising core update")
     if self.updater.update():
         actionManager.executeAction('reboot', 'Updater')
     xdm.common.removeState(3)
     return True
Beispiel #6
0
 def doCleanUp(self):
     self.setNewMessage('info', 'Recaching plugins...')
     actionManager.executeAction('recachePlugins', ['RepoManager'])
     self.setNewMessage('info', 'Recaching pugins done.')
     self.setNewMessage('info', 'Setting new static dirs.')
     helper.updateCherrypyPluginDirs()
     self.setNewMessage('info', 'Recaching repos...')
     self.cache()
     self.lastDownload = ''
     self.setNewMessage('info', 'Done!')
Beispiel #7
0
 def doCleanUp(self):
     self.setNewMessage("info", "Recaching plugins...")
     actionManager.executeAction("recachePlugins", ["RepoManager"])
     self.setNewMessage("info", "Recaching pugins done.")
     self.setNewMessage("info", "Setting new static dirs.")
     helper.updateCherrypyPluginDirs()
     self.setNewMessage("info", "Recaching repos...")
     self.cache()
     self.lastDownload = ""
     self.setNewMessage("info", "Done!")
Beispiel #8
0
 def doCleanUp(self):
     self.setNewMessage('info', 'Recaching plugins...')
     actionManager.executeAction('recachePlugins', ['RepoManager'])
     self.setNewMessage('info', 'Recaching pugins done.')
     self.setNewMessage('info', 'Setting new static dirs.')
     helper.updateCherrypyPluginDirs()
     self.setNewMessage('info', 'Recaching repos...')
     self.cache()
     self.lastDownload = ''
     self.setNewMessage('info', 'Done!')
Beispiel #9
0
 def migrate(self):
     xdm.common.addState(1)
     # common.SM.reset()
     try:
         self._migrate()
     except:
         log.error("Error during migration")
         log.info("Shutting down because migration did not work sorry")
         actionManager.executeAction('shutdown', 'failed migration')
     # common.SM.reset()
     xdm.common.removeState(1)
Beispiel #10
0
 def migrate(self):
     xdm.common.addState(1)
     #common.SM.reset()
     try:
         self._migrate()
     except:
         log.error("Error during migration")
         log.info("Shutting down because migration did not work sorry")
         actionManager.executeAction('shutdown', 'failed migration')
     #common.SM.reset()
     xdm.common.removeState(1)
Beispiel #11
0
    def update(self):
        xdm.common.addState(3)
        common.SM.setNewMessage("Initialising core update")

        try:
            result = self.updater.update()
        except:
            msg = "Error while trying to update. Please see log"
            log.error(msg)
            common.SM.setNewMessage(msg, lvl='error')
            return False
        if result:
            actionManager.executeAction('reboot', 'Updater')
        xdm.common.removeState(3)
        return True
Beispiel #12
0
    def update(self):
        xdm.common.addState(3)
        common.SM.setNewMessage("Initialising core update")

        try:
            result = self.updater.update()
        except:
            msg = "Error while trying to update. Please see log"
            log.error(msg)
            common.SM.setNewMessage(msg, lvl='error')
            return False
        if result:
            actionManager.executeAction('reboot', 'Updater')
        xdm.common.removeState(3)
        return True
Beispiel #13
0
    def deinstall(self, identifier):
        """Deinstall a plugin
        by simply deleting the install folder
        recaches all plugins at the end
        """
        self._read_messages = []
        self.install_messages = [('info', 'deinstall.py -i %s' % identifier)]
        if not identifier:
            self.setNewMessage(
                'error', 'The identifier is empty this should not happen !!')
            self.setNewMessage('error', 'Deinstallation unsuccessful')
            self.setNewMessage('info', 'Done!')
            return

        old_instalation = None
        for plugin in common.PM.getAll(returnAll=True, instance='Default'):
            if plugin.identifier == identifier:
                self.setNewMessage('info', 'Deinstalling %s' % plugin.type)
                old_instalation = plugin
                break
        else:
            self.setNewMessage(
                'error',
                'Could not find a plugin with identifier %s' % identifier)
            self.setNewMessage('error', 'Deinstallation unsuccessful')
            self.setNewMessage('info', 'Done!')
            return
        install_path = os.path.abspath(
            old_instalation.get_plugin_isntall_path()['path'])
        self.setNewMessage('info', 'Deleting plugin folder')
        self.setNewMessage('info', install_path)
        try:
            shutil.rmtree(install_path)
        except Exception as ex:
            log.error('Something went wrong while deleting %s' % install_path)
            self.setNewMessage('error', 'Error during deletion')
            self.setNewMessage('error', '%s' % ex)
        else:
            self.setNewMessage('info', 'Recaching plugins...')
            actionManager.executeAction('recachePlugins', ['RepoManager'])
            self.setNewMessage('info', 'Recaching pugins done.')
            self.setNewMessage('info', 'Recaching repos...')
            self.cache()
            self.setNewMessage('info',
                               'Recaching repos done. (please refresh page)')
        self.setNewMessage('info', 'Done!')
Beispiel #14
0
def main():
    try:
        signal.signal(signal.SIGTERM, shutdown_handler)
        signal.signal(signal.SIGHUP, reboot_handler)
    except AttributeError:
        log.debug("Could not connect signal handler")

    app = App()
    if not app.options.noWebServer:
        try:
            app.startWebServer()
        except IOError:
            log.error(
                "Unable to start web server, is something else running on port %d?"
                % app.port)
            os._exit(1)
    else:
        log.info(
            'Not starting webserver because of the command line option --noWebServer'
        )
    if (not app.options.noApi) and common.SYSTEM.c.api_active:
        try:
            api = JSONRPCapi(app.port_api)
        except:
            log.error('could not init jsonrpc api')
            os._exit(1)
        else:
            log('Starting api thread')
            api.start()
    else:
        log.info('Api is OFF')

    common.addState(2)
    common.removeState(0)

    common.SM.setNewMessage("Up and running.")
    common.SM.setNewMessage("Done!")

    try:
        while True:
            time.sleep(1)

    except KeyboardInterrupt:
        actionManager.executeAction('shutdown', 'KeyboardInterrupt')
    os._exit()
Beispiel #15
0
    def deinstall(self, identifier):
        """Deinstall a plugin
        by simply deleting the install folder
        recaches all plugins at the end
        """
        self._read_messages = []
        self.install_messages = [('info', 'deinstall.py -i %s' % identifier)]
        if not identifier:
            self.setNewMessage('error', 'The identifier is empty this should not happen !!')
            self.setNewMessage('error', 'Deinstallation unsuccessful')
            self.setNewMessage('info', 'Done!')
            return

        old_instalation = None
        for plugin in common.PM.getAll(returnAll=True, instance='Default'):
            if plugin.identifier == identifier:
                self.setNewMessage('info', 'Deinstalling %s' % plugin.type)
                old_instalation = plugin
                break
        else:
            self.setNewMessage('error', 'Could not find a plugin with identifier %s' % identifier)
            self.setNewMessage('error', 'Deinstallation unsuccessful')
            self.setNewMessage('info', 'Done!')
            return
        install_path = os.path.abspath(old_instalation.get_plugin_isntall_path()['path'])
        self.setNewMessage('info', 'Deleting plugin folder')
        self.setNewMessage('info', install_path)
        try:
            shutil.rmtree(install_path)
        except Exception as ex:
            log.error('Something went wrong while deleting %s' % install_path)
            self.setNewMessage('error', 'Error during deletion')
            self.setNewMessage('error', '%s' % ex)
        else:
            self.setNewMessage('info', 'Recaching plugins...')
            actionManager.executeAction('recachePlugins', ['RepoManager'])
            self.setNewMessage('info', 'Recaching pugins done.')
            self.setNewMessage('info', 'Recaching repos...')
            self.cache()
            self.setNewMessage('info', 'Recaching repos done. (please refresh page)')
        self.setNewMessage('info', 'Done!')
Beispiel #16
0
Datei: XDM.py Projekt: Torf/XDM
def main():
    try:
        signal.signal(signal.SIGTERM, shutdown_handler)
        signal.signal(signal.SIGHUP, reboot_handler)
    except AttributeError:
        log.debug("Could not connect signal handler")

    app = App()
    if not app.options.noWebServer:
        try:
            app.startWebServer()
        except IOError:
            log.error("Unable to start web server, is something else running on port %d?" % app.port)
            os._exit(1)
    else:
        log.info('Not starting webserver because of the command line option --noWebServer')
    if (not app.options.noApi) and common.SYSTEM.c.api_active:
        try:
            api = JSONRPCapi(app.port_api)
        except:
            log.error('could not init jsonrpc api')
            os._exit(1)
        else:
            log('Starting api thread')
            api.start()
    else:
        log.info('Api is OFF')

    common.addState(2)
    common.removeState(0)

    common.SM.setNewMessage("Up and running.")
    common.SM.setNewMessage("Done!")

    try:
        while True:
            time.sleep(1)

    except KeyboardInterrupt:
        actionManager.executeAction('shutdown', 'KeyboardInterrupt')
    os._exit()
Beispiel #17
0
    def deinstall(self, identifier):
        """Deinstall a plugin
        by simply deleting the install folder
        recaches all plugins at the end
        """
        self._read_messages = []
        self.install_messages = [("info", "deinstall.py -i %s" % identifier)]
        if not identifier:
            self.setNewMessage("error", "The identifier is empty this should not happen !!")
            self.setNewMessage("error", "Deinstallation unsuccessful")
            self.setNewMessage("info", "Done!")
            return

        old_instalation = None
        for plugin in common.PM.getAll(returnAll=True, instance="Default"):
            if plugin.identifier == identifier:
                self.setNewMessage("info", "Deinstalling %s" % plugin.type)
                old_instalation = plugin
                break
        else:
            self.setNewMessage("error", "Could not find a plugin with identifier %s" % identifier)
            self.setNewMessage("error", "Deinstallation unsuccessful")
            self.setNewMessage("info", "Done!")
            return
        install_path = os.path.abspath(old_instalation.get_plugin_isntall_path()["path"])
        self.setNewMessage("info", "Deleting plugin folder")
        self.setNewMessage("info", install_path)
        try:
            shutil.rmtree(install_path)
        except Exception as ex:
            log.error("Something went wrong while deleting %s" % install_path)
            self.setNewMessage("error", "Error during deletion")
            self.setNewMessage("error", "%s" % ex)
        else:
            self.setNewMessage("info", "Recaching plugins...")
            actionManager.executeAction("recachePlugins", ["RepoManager"])
            self.setNewMessage("info", "Recaching pugins done.")
            self.setNewMessage("info", "Recaching repos...")
            self.cache()
            self.setNewMessage("info", "Recaching repos done. (please refresh page)")
        self.setNewMessage("info", "Done!")
Beispiel #18
0
    def saveSettings(self, **kwargs):
        redirect_to = '/settings/'
        if 'saveOn' in kwargs:
            redirect_to += "#%s" % kwargs['saveOn']
            del kwargs['saveOn']
        self.ajax.save(**kwargs)
        self.redirect(redirect_to)


        #actions = list(set(actions))
        common.PM.cache()
        final_actions = {}
        for cur_class_name, cur_actions in actions.items():
            for cur_action in cur_actions:
                if not cur_action in final_actions:
                    final_actions[cur_action] = []
                final_actions[cur_action].append(cur_class_name)
        for action, plugins_that_called_it  in final_actions.items():
            actionManager.executeAction(action, plugins_that_called_it)
        common.SYSTEM = common.PM.getSystem('Default')[0] # yeah SYSTEM is a plugin
        return json.dumps({'result': True, 'data': {}, 'msg': 'Configuration saved.'})
Beispiel #19
0
def reboot_handler(signum, frame):
    log.info("reboot handler invoked with signal: %d " % signum)
    actionManager.executeAction('reboot', 'SIGHUP')
Beispiel #20
0
Datei: XDM.py Projekt: Torf/XDM
def reboot_handler(signum, frame):
    log.info("reboot handler invoked with signal: %d " % signum)
    actionManager.executeAction('reboot', 'SIGHUP')
Beispiel #21
0
Datei: XDM.py Projekt: Torf/XDM
def shutdown_handler(signum, frame):
    log.info("Shutdown handler invoked with signal: %d " % signum)
    actionManager.executeAction('shutdown', 'SIGTERM')
    os._exit()
Beispiel #22
0
    def _save(self, **kwargs):
        actions = {}
        if 'saveOn' in kwargs:
            del kwargs['saveOn']

        def convertV(cur_v):
            try:
                return float(cur_v)
            except TypeError: # its a list for bools / checkboxes "on" and "off"... "on" is only send when checked "off" is always send
                return True
            except ValueError:
                if cur_v in ('None', 'off'):
                    cur_v = False
                return cur_v

        element = None
        if 'element_id' in kwargs:
            element = Element.get(Element.id == kwargs['element_id'])
            del kwargs['element_id']

        # this is slow !!
        # because i create each plugin for each config value that is for that plugin
        # because i need the config_meta from the class to create the action list
        # but i can use the plugins own c obj for saving the value
        _plugin_cache = {} # first try to make it faster is by using a cache for each plugin instance
        for k, v in kwargs.items():
            try:
                k = k.decode('utf-8')
            except UnicodeDecodeError:
                k = k.decode('latin-1') # for some obscure reason cherrypy (i think) encodes param key into latin-1 some times
                k = k.encode('utf-8') # but i like utf-8
            #print k, repr(k)
            #print v, repr(v)

            log(u"config K:%s V:%s" % (k, v))
            parts = k.split('-')
            #print parts
            # parts[0] plugin class name
            # parts[1] plugin instance name
            # parts[2] config name
            # v value for config -> parts[2]
            class_name = parts[0]
            instance_name = parts[1]
            config_name = parts[2]
            _cacheName = "%s %s" % (class_name, instance_name)
            if _cacheName in _plugin_cache:
                plugin = _plugin_cache[_cacheName]
            else:
                plugin = common.PM.getInstanceByName(class_name, instance_name)
                _plugin_cache[_cacheName] = plugin
            if plugin:
                log(u"We have a plugin: %s (%s)" % (class_name, instance_name))
                if element is not None: # we got an element id so its an element config
                    old_value = getattr(plugin.e, config_name)
                else: # normal settings page
                    old_value = getattr(plugin.c, config_name)
                new_value = convertV(v)
                if old_value == new_value:
                    continue
                if element is not None: # we got an element id so its an element config
                    cur_c = plugin.e.getConfig(config_name, element)
                    cur_c.element = element
                    cur_c.value = new_value
                    cur_c.save()
                else: # normal settings page
                    setattr(plugin.c, config_name, convertV(v)) # saving value

                if plugin.config_meta[config_name] and element is None: # this returns none
                    if 'on_change_actions' in plugin.config_meta[config_name] and old_value != new_value:
                        actions[plugin] = plugin.config_meta[config_name]['on_change_actions'] # this is a list of actions
                    if 'actions' in plugin.config_meta[config_name]:
                        actions[plugin] = plugin.config_meta[config_name]['actions'] # this is a list of actions
                    if 'on_enable' in plugin.config_meta[config_name] and new_value:
                        actions[plugin] = plugin.config_meta[config_name]['on_enable'] # this is a list of actions
                elif plugin.elementConfig_meta[config_name] and element is not None:
                    pass
                continue
            else: # no plugin with that class_name or instance found
                log(u"We don't have a plugin: %s (%s)" % (class_name, instance_name))
                continue

        common.PM.cache()
        final_actions = {}
        for cur_class_name, cur_actions in actions.items():
            for cur_action in cur_actions:
                if not cur_action in final_actions:
                    final_actions[cur_action] = []
                final_actions[cur_action].append(cur_class_name)
        for action, plugins_that_called_it  in final_actions.items():
            actionManager.executeAction(action, plugins_that_called_it)
        common.SYSTEM = common.PM.getSystem('Default')[0] # yeah SYSTEM is a plugin
        return json.dumps({'result': True, 'data': {}, 'msg': 'Configuration saved.'})
Beispiel #23
0
 def update(self):
     common.SM.setNewMessage("Initialising core update")
     if self.updater.update():
         actionManager.executeAction('reboot', 'Updater')
     return True
Beispiel #24
0
    def install(self, identifier):
        self._prepareIntall()
        self.install_messages = [('info', 'install.py -i %s' % identifier)]
        self.setNewMessage('info', 'Getting download URL')

        plugin_to_update = None
        for repo in self.repos:
            for repo_plugin in repo.getPlugins():
                if repo_plugin.identifier == identifier:
                    plugin_to_update = repo_plugin
                    break

        if plugin_to_update is None:
            self.setNewMessage(
                'error',
                'Could not find a plugin with identifier %s' % identifier)
            self.setNewMessage('info', 'Done!')
            return

        self.setNewMessage(
            'info', 'Installing %s(%s)' %
            (plugin_to_update.name, plugin_to_update.versionHuman()))
        old_instalation = None
        for plugin in common.PM.getAll(returnAll=True, instance='Default'):
            if plugin.identifier == plugin_to_update.identifier:
                if not self._updateable(plugin_to_update, plugin):
                    self.setNewMessage(
                        'error',
                        '%s is already installed and does not need an update' %
                        plugin_to_update.name)
                    self.setNewMessage('info', 'Done!')
                    return
                else:
                    self.setNewMessage(
                        'info', '%s is already installed but has an update' %
                        plugin_to_update.name)
                    old_instalation = plugin
                    break
        else:
            self.setNewMessage(
                'info', '%s is not yet installed' % plugin_to_update.name)

        if old_instalation is not None:
            old_plugin_path = os.path.abspath(
                old_instalation.get_plugin_isntall_path())
            old_plugin_path_parent = os.path.abspath(
                os.path.join(old_plugin_path, os.pardir))
            self.setNewMessage(
                'info', 'Renaming old install path %s' % old_plugin_path)
            new_dir = '__old__%s%s' % (plugin.type, plugin.version)
            new_dir = new_dir.replace(' ', '-').replace('.', '_')
            new_path = os.path.join(old_plugin_path_parent, new_dir)
            self.setNewMessage('info', 'to %s' % new_path)
            os.rename(old_plugin_path, new_path)

        if repo_plugin.format == 'zip':
            downloader = ZipPluginInstaller()
        else:
            self.setNewMessage(
                'error',
                'Format %s is not supported. sorry' % plugin_to_update.format)
            self.setNewMessage('info', 'Done!')
            return

        install_path = common.SYSTEM.c.extra_plugin_path

        self.setNewMessage('info', 'Installing into %s' % install_path)
        self.setNewMessage('info', 'Starting download. please wait...')
        install_result = False
        try:
            install_result = downloader.install(self, plugin_to_update,
                                                install_path)
        except Exception as ex:
            log.error('Something went wrong during download')
            self.setNewMessage('error', 'Error during download')
            self.setNewMessage('error', '%s' % ex)

        if install_result:
            self.setNewMessage('info', 'Installation successful')
            self.setNewMessage('info', 'Recaching plugins...')
            actionManager.executeAction('recachePlugins', ['RepoManager'])
            self.setNewMessage('info', 'Recaching pugins done.')
            self.setNewMessage('info', 'Recaching repos...')
            self.cache()
            self.setNewMessage('info',
                               'Recaching repos done. (please refresh page)')
        else:
            self.setNewMessage('error', 'Installation unsuccessful')

        self.setNewMessage('info', 'Done!')
Beispiel #25
0
    def _save(self, **kwargs):
        actions = {}
        # print kwargs
        if 'saveOn' in kwargs:
            del kwargs['saveOn']

        element = None
        if 'element_id' in kwargs:
            element = Element.get(Element.id == kwargs['element_id'])
            del kwargs['element_id']

        # this is slow !!
        # because i create each plugin for each config value that is for that plugin
        # because i need the config_meta from the class to create the action list
        # but i can use the plugins own c obj for saving the value
        _plugin_cache = {} # first try to make it faster is by using a cache for each plugin instance
        for k, v in kwargs.items():
            try:
                k = k.decode('utf-8')
            except UnicodeDecodeError:
                k = k.decode('latin-1') # for some obscure reason cherrypy (i think) encodes param key into latin-1 some times
                k = k.encode('utf-8') # but i like utf-8

            log(u"config K:%s V:%s" % (k, v))
            parts = k.split('-')
            # print parts
            # parts[0] plugin class name
            # parts[1] plugin instance name
            # parts[2] config name
            # v value for config -> parts[2]
            class_name = parts[0]
            instance_name = parts[1]
            config_name = parts[2]
            config_type = parts[3] if len(parts) > 3 else None
            _cacheName = "%s %s" % (class_name, instance_name)
            if _cacheName in _plugin_cache:
                plugin = _plugin_cache[_cacheName]
            else:
                plugin = common.PM.getInstanceByName(class_name, instance_name)
                _plugin_cache[_cacheName] = plugin
            if plugin:
                log(u"We have a plugin: %s (%s)" % (class_name, instance_name))
                new_value = helper.convertV(v, config_type)
                if element is None: # normal settings page
                    old_value = getattr(plugin.c, config_name)
                    new_value = helper.convertV(v, config_type)
                    if old_value == new_value:
                        continue
                if element is not None: # we got an element id so its an element config
                    cur_c = plugin.e.getConfig(config_name, element)
                    if cur_c.value == new_value:
                        continue
                    log.debug("setting element config. %s K:%s, V:%s" % (element, config_name, new_value))
                    cur_c.element = element
                    cur_c.value = new_value
                    cur_c.save()
                else: # normal settings page
                    setattr(plugin.c, config_name, convertV(v, config_type)) # saving value

                if plugin.config_meta[config_name] and element is None: # this returns none
                    if 'on_change_actions' in plugin.config_meta[config_name] and old_value != new_value:
                        actions[plugin] = plugin.config_meta[config_name]['on_change_actions'] # this is a list of actions
                    if 'actions' in plugin.config_meta[config_name]:
                        actions[plugin] = plugin.config_meta[config_name]['actions'] # this is a list of actions
                    if 'on_enable' in plugin.config_meta[config_name] and new_value:
                        actions[plugin] = plugin.config_meta[config_name]['on_enable'] # this is a list of actions
                elif plugin.elementConfig_meta[config_name] and element is not None:
                    pass
                continue
            else: # no plugin with that class_name or instance found
                log(u"We don't have a plugin: %s (%s)" % (class_name, instance_name))
                continue

        if element is None:
            common.PM.reinstanceiate()
            # This is provate find a better place to the cache
            common._provider_tags_cache = []
        final_actions = {}
        for cur_class_name, cur_actions in actions.items():
            for cur_action in cur_actions:
                if not cur_action in final_actions:
                    final_actions[cur_action] = []
                final_actions[cur_action].append(cur_class_name)
        for action, plugins_that_called_it  in final_actions.items():
            actionManager.executeAction(action, plugins_that_called_it)

        return json.dumps({'result': True, 'data': {}, 'msg': 'Configuration saved.'})
Beispiel #26
0
    def _save(self, **kwargs):
        actions = {}
        if 'saveOn' in kwargs:
            del kwargs['saveOn']

        def convertV(cur_v):
            try:
                return float(cur_v)
            except TypeError:  # its a list for bools / checkboxes "on" and "off"... "on" is only send when checked "off" is always send
                return True
            except ValueError:
                if cur_v in ('None', 'off'):
                    cur_v = False
                return cur_v

        element = None
        if 'element_id' in kwargs:
            element = Element.get(Element.id == kwargs['element_id'])
            del kwargs['element_id']

        # this is slow !!
        # because i create each plugin for each config value that is for that plugin
        # because i need the config_meta from the class to create the action list
        # but i can use the plugins own c obj for saving the value
        _plugin_cache = {
        }  # first try to make it faster is by using a cache for each plugin instance
        for k, v in kwargs.items():
            log("config K:%s V:%s" % (k, v))
            parts = k.split('-')
            #print parts
            # parts[0] plugin class name
            # parts[1] plugin instance name
            # parts[2] config name
            # v value for config -> parts[2]
            class_name = parts[0]
            instance_name = parts[1]
            config_name = parts[2]
            _cacheName = "%s %s" % (class_name, instance_name)
            if _cacheName in _plugin_cache:
                plugin = _plugin_cache[_cacheName]
            else:
                plugin = common.PM.getInstanceByName(class_name, instance_name)
                _plugin_cache[_cacheName] = plugin
            if plugin:
                log("We have a plugin: %s (%s)" % (class_name, instance_name))
                if element is not None:  # we got an element id so its an element config
                    old_value = getattr(plugin.e, config_name)
                else:  # normal settings page
                    old_value = getattr(plugin.c, config_name)
                new_value = convertV(v)
                if old_value == new_value:
                    continue
                if element is not None:  # we got an element id so its an element config
                    cur_c = plugin.e.getConfig(config_name, element)
                    cur_c.element = element
                    cur_c.value = new_value
                    cur_c.save()
                else:  # normal settings page
                    setattr(plugin.c, config_name, convertV(v))  # saving value

                if plugin.config_meta[
                        config_name] and element is None:  # this returns none
                    if 'on_change_actions' in plugin.config_meta[
                            config_name] and old_value != new_value:
                        actions[plugin] = plugin.config_meta[config_name][
                            'on_change_actions']  # this is a list of actions
                    if 'actions' in plugin.config_meta[config_name]:
                        actions[plugin] = plugin.config_meta[config_name][
                            'actions']  # this is a list of actions
                    if 'on_enable' in plugin.config_meta[
                            config_name] and new_value:
                        actions[plugin] = plugin.config_meta[config_name][
                            'on_enable']  # this is a list of actions
                elif plugin.elementConfig_meta[
                        config_name] and element is not None:
                    pass
                continue
            else:  # no plugin with that class_name or instance found
                log("We don't have a plugin: %s (%s)" %
                    (class_name, instance_name))
                continue

        common.PM.cache()
        final_actions = {}
        for cur_class_name, cur_actions in actions.items():
            for cur_action in cur_actions:
                if not cur_action in final_actions:
                    final_actions[cur_action] = []
                final_actions[cur_action].append(cur_class_name)
        for action, plugins_that_called_it in final_actions.items():
            actionManager.executeAction(action, plugins_that_called_it)
        common.SYSTEM = common.PM.getSystems('Default')[
            0]  # yeah SYSTEM is a plugin
        return json.dumps({
            'result': True,
            'data': {},
            'msg': 'Configuration saved.'
        })
Beispiel #27
0
def shutdown_handler(signum, frame):
    log.info("Shutdown handler invoked with signal: %d " % signum)
    actionManager.executeAction('shutdown', 'SIGTERM')
    os._exit()
Beispiel #28
0
    def _save(self, **kwargs):
        actions = {}
        # print kwargs
        if "saveOn" in kwargs:
            del kwargs["saveOn"]

        element = None
        if "element_id" in kwargs:
            element = Element.get(Element.id == kwargs["element_id"])
            del kwargs["element_id"]

        # this is slow !!
        # because i create each plugin for each config value that is for that plugin
        # because i need the config_meta from the class to create the action list
        # but i can use the plugins own c obj for saving the value
        _plugin_cache = {}  # first try to make it faster is by using a cache for each plugin instance
        for k, v in kwargs.items():
            try:
                k = k.decode("utf-8")
            except UnicodeDecodeError:
                k = k.decode(
                    "latin-1"
                )  # for some obscure reason cherrypy (i think) encodes param key into latin-1 some times
                k = k.encode("utf-8")  # but i like utf-8
            # print k, repr(k)
            # print v, repr(v)

            log(u"config K:%s V:%s" % (k, v))
            parts = k.split("-")
            # print parts
            # parts[0] plugin class name
            # parts[1] plugin instance name
            # parts[2] config name
            # v value for config -> parts[2]
            class_name = parts[0]
            instance_name = parts[1]
            config_name = parts[2]
            _cacheName = "%s %s" % (class_name, instance_name)
            if _cacheName in _plugin_cache:
                plugin = _plugin_cache[_cacheName]
            else:
                plugin = common.PM.getInstanceByName(class_name, instance_name)
                _plugin_cache[_cacheName] = plugin
            if plugin:
                log(u"We have a plugin: %s (%s)" % (class_name, instance_name))
                new_value = convertV(v)
                if element is None:  # normal settings page
                    old_value = getattr(plugin.c, config_name)
                    new_value = convertV(v)
                    if old_value == new_value:
                        continue
                if element is not None:  # we got an element id so its an element config
                    cur_c = plugin.e.getConfig(config_name, element)
                    if cur_c.value == new_value:
                        continue
                    log.debug("setting element config. %s K:%s, V:%s" % (element, config_name, new_value))
                    cur_c.element = element
                    cur_c.value = new_value
                    cur_c.save()
                else:  # normal settings page
                    setattr(plugin.c, config_name, convertV(v))  # saving value

                if plugin.config_meta[config_name] and element is None:  # this returns none
                    if "on_change_actions" in plugin.config_meta[config_name] and old_value != new_value:
                        actions[plugin] = plugin.config_meta[config_name][
                            "on_change_actions"
                        ]  # this is a list of actions
                    if "actions" in plugin.config_meta[config_name]:
                        actions[plugin] = plugin.config_meta[config_name]["actions"]  # this is a list of actions
                    if "on_enable" in plugin.config_meta[config_name] and new_value:
                        actions[plugin] = plugin.config_meta[config_name]["on_enable"]  # this is a list of actions
                elif plugin.elementConfig_meta[config_name] and element is not None:
                    pass
                continue
            else:  # no plugin with that class_name or instance found
                log(u"We don't have a plugin: %s (%s)" % (class_name, instance_name))
                continue

        if element is None:
            common.PM.cache()
        final_actions = {}
        for cur_class_name, cur_actions in actions.items():
            for cur_action in cur_actions:
                if not cur_action in final_actions:
                    final_actions[cur_action] = []
                final_actions[cur_action].append(cur_class_name)
        for action, plugins_that_called_it in final_actions.items():
            actionManager.executeAction(action, plugins_that_called_it)
        common.SYSTEM = common.PM.getSystem("Default")[0]  # yeah SYSTEM is a plugin
        return json.dumps({"result": True, "data": {}, "msg": "Configuration saved."})
Beispiel #29
0
 def update(self):
     common.SM.setNewMessage("Initialising core update")
     if self.updater.update():
         actionManager.executeAction('reboot', 'Updater')
     return True
Beispiel #30
0
    def _save(self, **kwargs):
        actions = {}
        # print kwargs
        if 'saveOn' in kwargs:
            del kwargs['saveOn']

        element = None
        if 'element_id' in kwargs:
            element = Element.get(Element.id == kwargs['element_id'])
            del kwargs['element_id']

        # this is slow !!
        # because i create each plugin for each config value that is for that plugin
        # because i need the config_meta from the class to create the action list
        # but i can use the plugins own c obj for saving the value
        _plugin_cache = {
        }  # first try to make it faster is by using a cache for each plugin instance
        for k, v in kwargs.items():
            try:
                k = k.decode('utf-8')
            except UnicodeDecodeError:
                k = k.decode(
                    'latin-1'
                )  # for some obscure reason cherrypy (i think) encodes param key into latin-1 some times
                k = k.encode('utf-8')  # but i like utf-8
            # print k, repr(k)
            # print v, repr(v)

            log(u"config K:%s V:%s" % (k, v))
            parts = k.split('-')
            # print parts
            # parts[0] plugin class name
            # parts[1] plugin instance name
            # parts[2] config name
            # v value for config -> parts[2]
            class_name = parts[0]
            instance_name = parts[1]
            config_name = parts[2]
            _cacheName = "%s %s" % (class_name, instance_name)
            if _cacheName in _plugin_cache:
                plugin = _plugin_cache[_cacheName]
            else:
                plugin = common.PM.getInstanceByName(class_name, instance_name)
                _plugin_cache[_cacheName] = plugin
            if plugin:
                log(u"We have a plugin: %s (%s)" % (class_name, instance_name))
                new_value = helper.convertV(v)
                if element is None:  # normal settings page
                    old_value = getattr(plugin.c, config_name)
                    new_value = helper.convertV(v)
                    if old_value == new_value:
                        continue
                if element is not None:  # we got an element id so its an element config
                    cur_c = plugin.e.getConfig(config_name, element)
                    if cur_c.value == new_value:
                        continue
                    log.debug("setting element config. %s K:%s, V:%s" %
                              (element, config_name, new_value))
                    cur_c.element = element
                    cur_c.value = new_value
                    cur_c.save()
                else:  # normal settings page
                    setattr(plugin.c, config_name, convertV(v))  # saving value

                if plugin.config_meta[
                        config_name] and element is None:  # this returns none
                    if 'on_change_actions' in plugin.config_meta[
                            config_name] and old_value != new_value:
                        actions[plugin] = plugin.config_meta[config_name][
                            'on_change_actions']  # this is a list of actions
                    if 'actions' in plugin.config_meta[config_name]:
                        actions[plugin] = plugin.config_meta[config_name][
                            'actions']  # this is a list of actions
                    if 'on_enable' in plugin.config_meta[
                            config_name] and new_value:
                        actions[plugin] = plugin.config_meta[config_name][
                            'on_enable']  # this is a list of actions
                elif plugin.elementConfig_meta[
                        config_name] and element is not None:
                    pass
                continue
            else:  # no plugin with that class_name or instance found
                log(u"We don't have a plugin: %s (%s)" %
                    (class_name, instance_name))
                continue

        if element is None:
            common.PM.reinstanceiate()
            # This is provate find a better place to the cache
            common._provider_tags_cache = []
        final_actions = {}
        for cur_class_name, cur_actions in actions.items():
            for cur_action in cur_actions:
                if not cur_action in final_actions:
                    final_actions[cur_action] = []
                final_actions[cur_action].append(cur_class_name)
        for action, plugins_that_called_it in final_actions.items():
            actionManager.executeAction(action, plugins_that_called_it)

        return json.dumps({
            'result': True,
            'data': {},
            'msg': 'Configuration saved.'
        })
Beispiel #31
0
    def install(self, identifier):
        self._prepareIntall()
        self.install_messages = [('info', 'install.py -i %s' % identifier)]
        self.setNewMessage('info', 'Getting download URL')

        plugin_to_update = None
        for repo in self.repos:
            for repo_plugin in repo.getPlugins():
                if repo_plugin.identifier == identifier:
                    plugin_to_update = repo_plugin
                    break

        if plugin_to_update is None:
            self.setNewMessage('error', 'Could not find a plugin with identifier %s' % identifier)
            self.setNewMessage('info', 'Done!')
            return

        if not plugin_to_update.xdmMeetsVersionRequirement():
            self.setNewMessage('error', 'The plugin requires XDM version %s or higher you have %s' % (common.makeVersionHuman(*plugin_to_update.xdm_version)), common.getVersionHuman())
            self.setNewMessage('info', 'by the way how did you even get here ? the GUI should not have allowed this to begin with!')
            self.setNewMessage('info', 'Done!')
            return

        self.setNewMessage('info', 'Installing %s(%s)' % (plugin_to_update.name, plugin_to_update.versionHuman()))
        old_instalation = None
        for plugin in common.PM.getAll(returnAll=True, instance='Default'):
            if plugin.identifier == plugin_to_update.identifier:
                if not self._updateable(plugin_to_update, plugin):
                    self.setNewMessage('error', '%s is already installed and does not need an update' % plugin_to_update.name)
                    self.setNewMessage('info', 'Done!')
                    return
                else:
                    self.setNewMessage('info', '%s is already installed but has an update' % plugin_to_update.name)
                    old_instalation = plugin
                    break
        else:
            self.setNewMessage('info', '%s is not yet installed' % plugin_to_update.name)

        if old_instalation is not None:
            old_plugin_path = os.path.abspath(old_instalation.get_plugin_isntall_path())
            old_plugin_path_parent = os.path.abspath(os.path.join(old_plugin_path, os.pardir))
            self.setNewMessage('info', 'Renaming old install path %s' % old_plugin_path)
            new_dir = '__old__%s%s' % (plugin.type, plugin.version)
            new_dir = new_dir.replace(' ', '-').replace('.', '_')
            new_path = os.path.join(old_plugin_path_parent, new_dir)
            self.setNewMessage('info', 'to %s' % new_path)
            os.rename(old_plugin_path, new_path)

        if repo_plugin.format == 'zip':
            downloader = ZipPluginInstaller()
        else:
            self.setNewMessage('error', 'Format %s is not supported. sorry' % plugin_to_update.format)
            self.setNewMessage('info', 'Done!')
            return

        install_path = common.SYSTEM.c.extra_plugin_path

        self.setNewMessage('info', 'Installing into %s' % install_path)
        self.setNewMessage('info', 'Starting download. please wait...')
        install_result = False
        try:
            install_result = downloader.install(self, plugin_to_update, install_path)
        except Exception as ex:
            log.error('Something went wrong during download')
            self.setNewMessage('error', 'Error during download')
            self.setNewMessage('error', '%s' % ex)

        if install_result:
            self.setNewMessage('info', 'Installation successful')
            self.setNewMessage('info', 'Recaching plugins...')
            actionManager.executeAction('recachePlugins', ['RepoManager'])
            self.setNewMessage('info', 'Recaching pugins done.')
            self.setNewMessage('info', 'Recaching repos...')
            self.cache()
            self.setNewMessage('info', 'Recaching repos done. (please refresh page)')
        else:
            self.setNewMessage('error', 'Installation unsuccessful')

        self.setNewMessage('info', 'Done!')