Commits

Ian Bicking committed e616ccf

Refactor for a install-plugin command

  • Participants
  • Parent commits 1f4c1ae

Comments (0)

Files changed (3)

File silverhudson/command.py

     nargs='*',
     help="Variable to set")
 
+parser_install_plugin = subcommands.add_parser(
+    'install-plugin',
+    help="Install a plugin into a running Hudson instance")
+
+parser_install_plugin.add_argument(
+    '--no-restart', action='store_true',
+    help="Don't restart the server after installing the plugin(s)")
+
+parser_install_plugin.add_argument(
+    '--list', action='store_true',
+    help="List available plugins")
+
+parser_install_plugin.add_argument(
+    '--search',
+    help="Search the listed plugins for the given (case-insensitive) regex")
+
+parser_install_plugin.add_argument(
+    'plugins', nargs='*', metavar='PLUGIN...',
+    help="Plugin ID to install")
+
+
 for subparser in [parser] + subcommands._name_parser_map.values():
     subparser.add_argument(
         '--config', metavar="FILENAME",

File silverhudson/command_install_plugin.py

+def command_install_plugin(args):
+    api = args.config.get_api(args)
+    if args.list:
+        api.command_list_plugins(args.search)
+        return
+    api.install_plugins(args.plugins)
+    print 'Installed: %s' % ', '.join(args.plugins)
+    if not args.no_restart:
+        api.command_restart()

File silverhudson/request.py

         if 'list' in kw:
             kw.pop('list')
             return self.command_list_plugins(**kw)
-        params = [
-            (name, 'on') for name in kw if name != 'restart']
-        page = self.req_app.post('/pluginManager/install', params)
+        self.install_plugins([name for name in kw if name != 'restart'])
         print 'Installed:'
         for name in sorted(kw):
             if name == 'restart':
         if 'restart' in kw:
             self.command_restart()
 
+    def install_plugins(self, plugins):
+        params = [
+            (name, 'on') for name in plugins]
+        page = self.req_app.post('/pluginManager/install', params)
+        return page
+
     def command_list_plugins(self, search=None):
         """
         List all plugins available.  You may indicate search=regex as well.