Skip to content

Commit

Permalink
Return 0/1/2 in plugin installer
Browse files Browse the repository at this point in the history
cc @felixfontein

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 14, 2015
1 parent 1d17171 commit 5261df2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion nikola/plugins/command/import_wordpress.py
Expand Up @@ -75,7 +75,7 @@ def install_plugin(site, plugin_name, output_dir=None, show_install_notes=False)
options['install'] = plugin_name
options['output_dir'] = output_dir
options['show_install_notes'] = show_install_notes
if not plugin_installer.execute(options=options):
if plugin_installer.execute(options=options) > 0:
return False
# Let the plugin manager find newly installed plugins
site.plugin_manager.collectPlugins()
Expand Down
21 changes: 11 additions & 10 deletions nikola/plugins/command/plugin.py
Expand Up @@ -128,7 +128,7 @@ def _execute(self, options, args):
list_installed)].count(True)
if command_count > 1 or command_count == 0:
print(self.help())
return
return 2

if options.get('output_dir') is not None:
self.output_dir = options.get('output_dir')
Expand Down Expand Up @@ -159,7 +159,7 @@ def list_available(self, url):
print("------------------")
for plugin in sorted(data.keys()):
print(plugin)
return True
return 0

def list_installed(self):
plugins = []
Expand All @@ -174,7 +174,7 @@ def list_installed(self):
plugins.sort()
for name, path in plugins:
print('{0} at {1}'.format(name, path))
return True
return 0

def do_upgrade(self, url):
LOGGER.warning('This is not very smart, it just reinstalls some plugins and hopes for the best')
Expand All @@ -199,11 +199,11 @@ def do_upgrade(self, url):
break
elif tail == '':
LOGGER.error("Can't find the plugins folder for path: {0}".format(p))
return False
return 1
else:
path = tail
self.do_install(url, name)
return True
return 0

def do_install(self, url, name, show_install_notes=True):
data = self.get_json(url)
Expand All @@ -220,13 +220,13 @@ def do_install(self, url, name, show_install_notes=True):
plugin_path = utils.get_plugin_path(name)
except:
LOGGER.error("Can't find plugin " + name)
return False
return 1

utils.makedirs(self.output_dir)
dest_path = os.path.join(self.output_dir, name)
if os.path.exists(dest_path):
LOGGER.error("{0} is already installed".format(name))
return False
return 1

LOGGER.info('Copying {0} into plugins'.format(plugin_path))
shutil.copytree(plugin_path, dest_path)
Expand Down Expand Up @@ -272,7 +272,7 @@ def do_install(self, url, name, show_install_notes=True):
4 * ' '))
else:
print(utils.indent(fh.read(), 4 * ' '))
return True
return 0

def do_uninstall(self, name):
for plugin in self.site.plugin_manager.getAllPlugins(): # FIXME: this is repeated thrice
Expand All @@ -289,9 +289,10 @@ def do_uninstall(self, name):
if sure.lower().startswith('y'):
LOGGER.warning('Removing {0}'.format(p))
shutil.rmtree(p)
return True
return 0
return 1
LOGGER.error('Unknown plugin: {0}'.format(name))
return False
return 1

def get_json(self, url):
if self.json is None:
Expand Down

0 comments on commit 5261df2

Please sign in to comment.