def put(self, plugin): if not self.data: self.httperror(409, "No data given") self.log.debug('Updating plugin %s config: %s' % (plugin, self.data)) alfred.config.get('plugins').get(plugin).update(self.data) alfred.db.config.update({'name': alfred.getHost()}, {'$set': { 'config': alfred.config }})
def uninstallPlugin(pluginName): if pluginName in activePlugins: stopPlugin(pluginName) log.info('Uninstalling plugin %s' % pluginName) del alfred.config['plugins'][pluginName] alfred.db.config.update({'name': alfred.getHost()}, {'$set': { 'config': alfred.config }})
def put(self): if not self.data: self.httperror(412, "No config data found") res = alfred.db.config.update({'name': alfred.getHost()}, {'$set': {'config': self.data.get('config')}}) if res['err']: self.write(dict(error=res['err'])) else: # alfred.webserver.bus.publish('config/config', dumps({'action': 'edit', 'data': self.data})) self.log.info("Caught a config modification, restarting...") self.finish() alfred.stop()
def get(self, plugin): if not plugin: res = {'available': alfred.manager.find_plugins().keys(), 'installed': copy.deepcopy(alfred.config.get('plugins'))} for k in res['installed']: if k in alfred.manager.activePlugins: res['installed'][k]['active'] = True # if k in res['available']: # res['available'].remove(k) self.write(dumps(res)) # default=json_util.default)) else: res = alfred.db.config.find({'name': alfred.getHost()})[0].get('config').get('plugins').get(plugin) self.write(dumps(res)) if res else self.httperror(404, 'No plugin %s installed' % plugin)
def put(self): if not self.data: self.httperror(412, "No config data found") res = alfred.db.config.update( {'name': alfred.getHost()}, {'$set': { 'config': self.data.get('config') }}) if res['err']: self.write(dict(error=res['err'])) else: # alfred.webserver.bus.publish('config/config', dumps({'action': 'edit', 'data': self.data})) self.log.info("Caught a config modification, restarting...") self.finish() alfred.stop()
def get(self, plugin): if not plugin: res = { 'available': alfred.manager.find_plugins().keys(), 'installed': copy.deepcopy(alfred.config.get('plugins')) } for k in res['installed']: if k in alfred.manager.activePlugins: res['installed'][k]['active'] = True # if k in res['available']: # res['available'].remove(k) self.write(dumps(res)) # default=json_util.default)) else: res = alfred.db.config.find( {'name': alfred.getHost()})[0].get('config').get('plugins').get(plugin) self.write(dumps(res)) if res else self.httperror( 404, 'No plugin %s installed' % plugin)
def put(self, plugin): if not self.data: self.httperror(409, "No data given") self.log.debug('Updating plugin %s config: %s' %(plugin, self.data)) alfred.config.get('plugins').get(plugin).update(self.data) alfred.db.config.update({'name': alfred.getHost()}, {'$set': {'config': alfred.config}})
def get(self): self.write(dumps(alfred.db.config.find({'name': alfred.getHost()})[0]))
def test_gethost(): assert '.' not in alfred.getHost() assert alfred.getHost()
def test_load_config(): alfred.db = mock.Mock() alfred.db.config = mock.Mock() alfred.db.config.find_one.return_value = dict(name=alfred.getHost(), config={'ok':'ok'}) assert alfred.load_config()
pip.main('install -r {0}/plugins/{1}/requirements.txt'.format( os.path.dirname(__file__), pluginName).split()) mod = __import__('alfred.plugins.%s' % pluginName, fromlist='alfred') except: res = 'Cannot install plugin: %s' % E.message log.error(res) return res if not pluginName in alfred.config.get('plugins'): log.info('Installing plugin %s' % pluginName) alfred.config['plugins'][pluginName] = dict(autoStart=False, config=getattr( mod, 'defaultConfig', {})) alfred.db.config.update({'name': alfred.getHost()}, {'$set': { 'config': alfred.config }}) def uninstallPlugin(pluginName): if pluginName in activePlugins: stopPlugin(pluginName) log.info('Uninstalling plugin %s' % pluginName) del alfred.config['plugins'][pluginName] alfred.db.config.update({'name': alfred.getHost()}, {'$set': { 'config': alfred.config }})
def uninstallPlugin(pluginName): if pluginName in activePlugins: stopPlugin(pluginName) log.info('Uninstalling plugin %s' % pluginName) del alfred.config['plugins'][pluginName] alfred.db.config.update({'name': alfred.getHost()}, {'$set': {'config': alfred.config}})
try: import pip pip.main('install -r {0}/plugins/{1}/requirements.txt'.format(os.path.dirname(__file__), pluginName).split()) mod = __import__('alfred.plugins.%s' % pluginName, fromlist='alfred') except: res = 'Cannot install plugin: %s' % E.message log.error(res) return res if not pluginName in alfred.config.get('plugins'): log.info('Installing plugin %s' % pluginName) alfred.config['plugins'][pluginName] = dict( autoStart=False, config=getattr(mod, 'defaultConfig', {}) ) alfred.db.config.update({'name': alfred.getHost()}, {'$set': {'config': alfred.config}}) def uninstallPlugin(pluginName): if pluginName in activePlugins: stopPlugin(pluginName) log.info('Uninstalling plugin %s' % pluginName) del alfred.config['plugins'][pluginName] alfred.db.config.update({'name': alfred.getHost()}, {'$set': {'config': alfred.config}}) def startPlugin(pluginName): if not pluginName in alfred.config.get('plugins'): res = 'Plugin %s not installed' % pluginName log.error(res) return res