Skip to content

Commit

Permalink
Adding dev mode for install and uninstall cli. Use "lisa-cli plugin l…
Browse files Browse the repository at this point in the history
…ocalplugin --install --dev" to install it (and uninstall to uninstall it without removing your plugin)
  • Loading branch information
Seraf committed May 19, 2014
1 parent e696484 commit d32a307
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
22 changes: 12 additions & 10 deletions lisa/server/plugins/PluginManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import inspect
from lisa.server.web.manageplugins.models import Plugin, Description, Rule, Cron, Intent
import json
import os
from twisted.python.reflect import namedAny
from django.template.loader import render_to_string
import datetime
Expand Down Expand Up @@ -43,15 +42,16 @@ def getPluginByName(self, plugin_name):
"""
return None

def installPlugin(self, plugin_name=None, test_mode=False):
def installPlugin(self, plugin_name=None, test_mode=False, dev_mode=False):
if Plugin.objects(name=plugin_name):
return {'status': 'fail', 'log': 'Plugin already installed'}

if test_mode:
pip.main(['install', '--quiet', '--install-option=--install-platlib=' + os.getcwd() + '/../',
'--install-option=--install-purelib=' + os.getcwd() + '/../', 'lisa-plugin-' + plugin_name])
else:
pip.main(['install', 'lisa-plugin-' + plugin_name])
if not dev_mode:
if test_mode:
pip.main(['install', '--quiet', '--install-option=--install-platlib=' + os.getcwd() + '/../',
'--install-option=--install-purelib=' + os.getcwd() + '/../', 'lisa-plugin-' + plugin_name])
else:
pip.main(['install', 'lisa-plugin-' + plugin_name])
jsonfile = self.pkgpath + '/' + plugin_name + '/' + plugin_name.lower() + '.json'
metadata = json.load(open(jsonfile))

Expand Down Expand Up @@ -112,7 +112,8 @@ def installPlugin(self, plugin_name=None, test_mode=False):
oIntent.enabled = True
oIntent.plugin = plugin
oIntent.save()
os.remove(jsonfile)
if not dev_mode:
os.remove(jsonfile)
return {'status': 'success', 'log': 'Plugin installed'}

def enablePlugin(self, plugin_name=None, plugin_pk=None):
Expand Down Expand Up @@ -164,7 +165,7 @@ def disablePlugin(self, plugin_name=None, plugin_pk=None):

return {'status': 'success', 'log': 'Plugin disabled'}

def uninstallPlugin(self, plugin_name=None, plugin_pk=None):
def uninstallPlugin(self, plugin_name=None, plugin_pk=None, dev_mode=False):
if plugin_pk:
plugin_list = Plugin.objects(pk=plugin_pk)
else:
Expand All @@ -173,7 +174,8 @@ def uninstallPlugin(self, plugin_name=None, plugin_pk=None):
return {'status': 'fail', 'log': 'Plugin not installed'}
else:
for plugin in plugin_list:
pip.main(['uninstall', '--quiet', 'lisa-plugin-' + plugin_name])
if not dev_mode:
pip.main(['uninstall', '--quiet', 'lisa-plugin-' + plugin_name])
plugin.delete()
for cron in Cron.objects(plugin=plugin):
cron.delete()
Expand Down
18 changes: 13 additions & 5 deletions lisa/server/web/manageplugins/management/commands/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def __init__(self):
make_option('--install',
action = 'store_true',
help = 'Install a plugin'),
make_option('--dev',
action = 'store_true',
help = 'Dev mode'),
make_option('--uninstall',
action = 'store_true',
help = 'Uninstall a plugin'),
Expand All @@ -51,12 +54,17 @@ def handle(self, *args, **options):
if args:
self.arg_pluginName = args[0]

if options.get('dev'):
dev_mode = True
else:
dev_mode = False

if options.get('list'):
self.plugin_list()
elif options.get('install'):
self.manage(name=self.arg_pluginName, action="install")
self.manage(name=self.arg_pluginName, action="install", dev_mode=dev_mode)
elif options.get('uninstall'):
self.manage(name=self.arg_pluginName, action="uninstall")
self.manage(name=self.arg_pluginName, action="uninstall", dev_mode=dev_mode)
elif options.get('enable'):
self.manage(name=self.arg_pluginName, action="enable")
elif options.get('disable'):
Expand Down Expand Up @@ -113,13 +121,13 @@ def plugin_list(self):

self.stdout.write("%s => %s %s" % (pluginDict['name'], installed, enabled))

def manage(self, name, action, author_email=None, author_name=None):
def manage(self, name, action, author_email=None, author_name=None, dev_mode=False):
if action == "install":
status = PluginManagerSingleton.get().installPlugin(plugin_name=name)
status = PluginManagerSingleton.get().installPlugin(plugin_name=name, dev_mode=dev_mode)
elif action == "disable":
status = PluginManagerSingleton.get().disablePlugin(plugin_name=name)
elif action == "uninstall":
status = PluginManagerSingleton.get().uninstallPlugin(plugin_name=name)
status = PluginManagerSingleton.get().uninstallPlugin(plugin_name=name, dev_mode=dev_mode)
elif action == "enable":
status = PluginManagerSingleton.get().enablePlugin(plugin_name=name)
elif action == "create":
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pytz>=2014.2
pyOpenSSL==0.13
lisa-plugin-ChatterBot
PyWit>=0.2.0
service_identity
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup
import os

VERSION = '0.1.2.0'
VERSION = '0.1.2.1'

# When pip installs anything from packages, py_modules, or ext_modules that
# includes a twistd plugin (which are installed to twisted/plugins/),
Expand Down

0 comments on commit d32a307

Please sign in to comment.