Exemplo n.º 1
0
 def makePermanent(self, id):
     element = Element.get(Element.id == id)
     element.manager.makeReal(element)
     time.sleep(1)
     t = tasks.TaskThread(tasks.searchElement, element)
     t.start()
     self.redirect('/')
Exemplo n.º 2
0
 def addElement(self, id):
     element = Element.get(Element.id == id)
     status = common.getStatusByID(element.manager.c.default_new_status_select)
     element.manager.makeReal(element, status)
     if status == common.WANTED:
         t = tasks.TaskThread(tasks.searchElement, element)
         t.start()
     return json.dumps({'result': True, 'data': {}, 'msg': '%s added.' % element.getName()})
Exemplo n.º 3
0
 def makePermanent(self, id):
     element = Element.get(Element.id == id)
     status = common.getStatusByID(
         element.manager.c.default_new_status_select)
     element.manager.makeReal(element, status)
     if status == common.WANTED:
         t = tasks.TaskThread(tasks.searchElement, element)
         t.start()
     self.redirect('/')
Exemplo n.º 4
0
 def removeRepo(self, url):
     try:
         repo = Repo.get(Repo.url == url)
     except Repo.DoesNotExist:
         return ''
     repo.delete_instance()
     common.REPOMANAGER = RepoManager(Repo.select())
     t = tasks.TaskThread(tasks.cacheRepos)
     t.start()
     return ''
Exemplo n.º 5
0
 def addElement(self, id):
     element = Element.get(Element.id == id)
     element.manager.makeReal(element)
     t = tasks.TaskThread(tasks.searchElement, element)
     t.start()
     return json.dumps({
         'result': True,
         'data': {},
         'msg': '%s added.' % element.getName()
     })
Exemplo n.º 6
0
 def addRepo(self, url):
     r = Repo()
     r.name = 'unknown'
     r.info_url = ''
     r.url = url
     r.save()
     common.REPOMANAGER = RepoManager(Repo.select())
     t = tasks.TaskThread(tasks.cacheRepos)
     t.start()
     return ''
Exemplo n.º 7
0
def postDB():
    """mostly plugin and common init"""
    common.PM = PluginManager()
    common.PM.cache(
        debug=common.STARTOPTIONS.pluginImportDebug,
        systemOnly=True,
    )
    # load system config !
    common.SYSTEM = common.PM.getPluginByIdentifier(
        common.STARTOPTIONS.systemIdentifer, 'Default'
    )  # yeah SYSTEM is a plugin, identifier permits to be sure to get the right plugin.
    # system config loaded

    # init i18n
    common.SYSTEM._switchLanguage()

    # init updater
    common.UPDATER = CoreUpdater()
    common.REPOMANAGER = RepoManager(Repo.select())

    if not os.path.isabs(common.SYSTEM.c.https_cert_filepath):
        common.SYSTEM.c.https_cert_filepath = os.path.join(
            xdm.DATADIR, common.SYSTEM.c.https_cert_filepath)

    if not os.path.isabs(common.SYSTEM.c.https_key_filepath):
        common.SYSTEM.c.https_key_filepath = os.path.join(
            xdm.DATADIR, common.SYSTEM.c.https_key_filepath)

    # prepare to load other plugins
    if not common.SYSTEM.c.extra_plugin_path or common.STARTOPTIONS.datadir is not None:
        log.info('Setting extra plugin path to %s' % xdm.PLUGININSTALLPATH)
        common.SYSTEM.c.extra_plugin_path = xdm.PLUGININSTALLPATH

    if os.path.isdir(common.SYSTEM.c.extra_plugin_path):
        log('Adding eyternal plugin path %s to the python path' %
            common.SYSTEM.c.extra_plugin_path)
        sys.path.append(common.SYSTEM.c.extra_plugin_path)
    common.PM.cache(debug=common.STARTOPTIONS.pluginImportDebug)
    common.SYSTEM = common.PM.getPluginByIdentifier(
        common.STARTOPTIONS.systemIdentifer, 'Default'
    )  # yeah SYSTEM is a plugin, identifier permits to be sure to get the right plugin.

    # generate api key if api is aktive
    if common.SYSTEM.c.api_active and not common.SYSTEM.c.api_key:
        log.info('Generating your first API key for XDM')
        common.SYSTEM.c.api_key = helper.generateApiKey()

    # lets init all plugins once
    for plugin in common.PM.getAll():
        log("Plugin %s loaded successfully" % plugin.name)

    # migrate core
    t = tasks.TaskThread(common.UPDATER.migrate)
    t.start()
Exemplo n.º 8
0
    def setStatus(self, status_id, element_id):
        status = common.getStatusByID(int(status_id))
        try:
            ele = Element.get(Element.id == element_id)
            ele.status = status
            ele.save()
        except:
            return json.dumps({'result': False, 'data': {}, 'msg': 'Could not set status.'})

        if status == common.WANTED:
            t = tasks.TaskThread(tasks.searchElement, ele)
            t.start()

        return json.dumps({'result': True, 'data': {'status_id': status.id}, 'msg': u'%s set to %s' % (ele.getName(), status)})
Exemplo n.º 9
0
    def installPlugins(self, **kwargs):
        _keys = sorted([int(x) for x in kwargs.keys()])
        _identifiers = [kwargs[str(key)] for key in _keys]

        log("Batch plugin install identifiers: %s" % _identifiers)

        def installAllPlugins(identifiers):
            for identifier in identifiers:
                common.REPOMANAGER.install(identifier, doCleanUp=False)
            common.REPOMANAGER.doCleanUp()

        t = tasks.TaskThread(installAllPlugins, _identifiers)
        t.start()
        return '<ul id="install-shell" class="shell"></ul>'
Exemplo n.º 10
0
    def plugins(self, recache=''):
        now = datetime.datetime.now()
        if common.REPOMANAGER.last_cache is not None:
            last_cache = common.REPOMANAGER.last_cache
        else:
            last_cache = now - datetime.timedelta(hours=25)
        delta = datetime.timedelta(hours=24)
        if not common.REPOMANAGER.cached or recache or (now - last_cache >
                                                        delta):
            t = tasks.TaskThread(tasks.cacheRepos)
            t.start()
        if recache:
            return ''

        template = env.get_template('plugins.html')
        return template.render(**self._globals())
Exemplo n.º 11
0
 def coreUpdate(self):
     common.SM.reset()
     common.SM.setNewMessage('update.py -t NOW')
     t = tasks.TaskThread(common.UPDATER.update)
     t.start()
     return '<ul id="install-shell" class="shell"></ul>'
Exemplo n.º 12
0
 def shutdown(self):
     common.SM.reset()
     common.SM.setNewMessage('shutdown.py -t NOW')
     t = tasks.TaskThread(actionManager.executeAction, 'shutdown', 'Webgui')
     threading.Timer(1, t.start).start()
     return '<ul id="install-shell" class="shell"></ul>'
Exemplo n.º 13
0
 def reboot(self):
     common.SM.reset()
     common.SM.setNewMessage('reboot.py -t NOW')
     t = tasks.TaskThread(actionManager.executeAction, 'reboot', 'Webgui')
     t.start()
     return '<ul id="install-shell" class="shell"></ul>'
Exemplo n.º 14
0
 def deinstallPlugin(self, identifier=''):
     t = tasks.TaskThread(tasks.deinstallPlugin, identifier)
     t.start()
     return '<ul id="install-shell" class="shell"></ul>'
Exemplo n.º 15
0
def runTasks():
    """tasks to run on boot"""
    t = tasks.TaskThread(tasks.removeTempElements)
    t.start()
    t = tasks.TaskThread(common.REPOMANAGER.cache)
    t.start()
Exemplo n.º 16
0
def reboot():
    """just return True and starts a thread to reboot XDM"""
    common.SM.reset()
    t = tasks.TaskThread(actionManager.executeAction, 'reboot', 'JSONRPCapi')
    t.start()
    return True
Exemplo n.º 17
0
def shutdown():
    """just return True and starts a thread to shutdown XDM"""
    common.SM.reset()
    t = tasks.TaskThread(actionManager.executeAction, 'shutdown', 'JSONRPCapi')
    t.start()
    return True
Exemplo n.º 18
0
def runTasks():
    """tasks to run on boot"""
    t = tasks.TaskThread(tasks.removeTempElements)
    t.start()