Khai Do has proposed merging lp:~zaro0508/python-jenkins/plugin-info-method 
into lp:python-jenkins.

Requested reviews:
  Python Jenkins Developers (python-jenkins-developers)

For more details, see:
https://code.launchpad.net/~zaro0508/python-jenkins/plugin-info-method/+merge/196653

This patch adds a method to get jenkins plugin information.  It may be called 
without any parameters which will return a list of plugins on master.  User may 
specify the plugin name to get info about in which case it will only that 
plugin info.  if the plugin name cannot be found then it will return None.
-- 
https://code.launchpad.net/~zaro0508/python-jenkins/plugin-info-method/+merge/196653
Your team Python Jenkins Developers is requested to review the proposed merge 
of lp:~zaro0508/python-jenkins/plugin-info-method into lp:python-jenkins.
=== modified file 'jenkins/__init__.py'
--- jenkins/__init__.py	2013-09-28 20:00:43 +0000
+++ jenkins/__init__.py	2013-11-26 04:59:03 +0000
@@ -58,6 +58,7 @@
 LAUNCHER_WINDOWS_SERVICE = 'hudson.os.windows.ManagedWindowsServiceLauncher'
 
 INFO = 'api/json'
+PLUGIN_INFO = 'pluginManager/api/json?depth=2'
 CRUMB_URL = 'crumbIssuer/api/json'
 JOB_INFO = 'job/%(name)s/api/json?depth=0'
 JOB_NAME = 'job/%(name)s/api/json?tree=name'
@@ -325,6 +326,47 @@
             raise JenkinsException("Could not parse JSON info for server[%s]"
                                    % self.server)
 
+    def get_plugin_info(self, name=None):
+        """
+        Get information about installed plugins on Master.
+        If given a name this function will return the specific
+        plugin info.
+        
+        :param name: Name of plugin, ``str``
+        :returns: either a list of plugins or a specific plugin, ``[dict]``
+
+        Example::
+
+            >>> info = j.get_plugin_info("Gearman Plugin")
+            >>> print(info)
+            {u'backupVersion': None, u'version': u'0.0.4', u'deleted': False,
+            u'supportsDynamicLoad': u'MAYBE', u'hasUpdate': True, u'enabled': True,
+            u'pinned': False, u'downgradable': False, u'dependencies': [],
+            u'url': u'http://wiki.jenkins-ci.org/display/JENKINS/Gearman+Plugin',
+            u'longName': u'Gearman Plugin', u'active': True, u'shortName':
+            u'gearman-plugin', u'bundled': False}
+
+        """
+        try:
+            plugins = json.loads(self.jenkins_open(
+                urllib2.Request(self.server + PLUGIN_INFO)))['plugins']
+            if name is not None:
+                info = None
+                for plugin in plugins:
+                    if plugin['longName'] == name:
+                        info = plugin
+                return info
+            return plugins
+        except urllib2.HTTPError:
+            raise JenkinsException("Error communicating with server[%s]"
+                                   % self.server)
+        except httplib.BadStatusLine:
+            raise JenkinsException("Error communicating with server[%s]"
+                                   % self.server)
+        except ValueError:
+            raise JenkinsException("Could not parse JSON info for server[%s]"
+                                   % self.server)
+
     def get_jobs(self):
         """
         Get list of jobs running.  Each job is a dictionary with

-- 
Mailing list: https://launchpad.net/~python-jenkins-developers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~python-jenkins-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to