[python-bugzilla] Using history from the CLI (per https://lists.fedorahosted.org/pipermail/python-bugzilla/2013-February/000040.html)

Cole Robinson crobinso at redhat.com
Mon Mar 25 20:37:14 UTC 2013


On 03/22/2013 03:38 PM, Don Zickus wrote:
> On Mon, Mar 18, 2013 at 10:37:01PM +0200, Yaniv Kaul wrote:
>> Is the history exposed from the CLI? Looks like I need to use python
>> to access it?
> 
> Hi,
> 
> I implemented this privately awhile ago.  Took some time to port to 0.8.0,
> but you can try this patch to see if it is what you are looking for.  The
> output could use suggestions.
> 


Cool, thanks for this Don! Though this patch doesn't apply to 0.8.0 for me...
did you send the wrong one? Or did I misunderstand and this patch still needs
to be ported to 0.8.0?

Thanks,
Cole

> ---------------8<----------------------
> From: Don Zickus <dzickus at redhat.com>
> Date: Wed, 14 Mar 2012 17:25:59 -0400
> Subject: [PATCH] Add history command
> 
> Something came up and I started hacking up the interface for the 'history'
> command.  I decided to cleanup what I wrote and add it officially to the
> python-bugzilla project.
> 
> What it does is simple, just display the change history of the bug id.
> 
> This might not sound terribly useful, but it is just another little
> tool that the bugzilla app can use to extract yet more info from the
> bugzilla database.
> 
> Signed-off-by: Don Zickus <dzickus at redhat.com>
> ---
>  bin/bugzilla          |   37 ++++++++++++++++++++++++++++++++++++-
>  bugzilla/base.py      |    8 ++++++++
>  bugzilla/bugzilla3.py |    6 ++++++
>  3 files changed, 50 insertions(+), 1 deletions(-)
> 
> diff --git a/bin/bugzilla b/bin/bugzilla
> index 95fd747..670758c 100755
> --- a/bin/bugzilla
> +++ b/bin/bugzilla
> @@ -32,7 +32,7 @@ if '--debug' in sys.argv:
>  elif '--verbose' in sys.argv:
>      log.setLevel(logging.INFO)
>  
> -cmdlist = ['login','new','query','modify','attach','info']
> +cmdlist = ['login','new','query','modify','attach','info','history']
>  
>  def to_encoding(ustring):
>      if isinstance(ustring, basestring):
> @@ -230,6 +230,9 @@ def setup_action_parser(action):
>      elif action == 'login':
>          p.set_usage('%prog login [username [password]]')
>          p.set_description("Log into bugzilla and save a login cookie.")
> +    elif action == 'history':
> +        p.set_usage('%prog history BUGID [BUGID...]')
> +        p.set_description("Prints out the change history of the bugzillas")
>  
>      if action in ['new','query']:
>          # output modifiers
> @@ -697,6 +700,23 @@ def main():
>              if opt.fixed_in:
>                  data['fixed_in'] = opt.fixed_in
>              bz._update_bugs(bugid_list, data)
> +    elif action == 'history':
> +        bugid_list = []
> +        for a in args:
> +            if ',' in a:
> +                for b in a.split(','):
> +                    bugid_list.append(b)
> +            else:
> +                bugid_list.append(a)
> +        # surely there's a simpler way to do that..
> +        # bail out if no bugs were given
> +        if not bugid_list:
> +            parser.error('no bug ids given (maybe you forgot an argument somewhere?)')
> +        # iterate over a list of bug objects
> +        buglist = bz.history(bugid_list)
> +        if not buglist:
> +            parser.error('no bugs were found. check your bug ids.')
> +
>      else:
>          print "Sorry - '%s' not implemented yet." % action
>  
> @@ -793,6 +813,21 @@ def main():
>          else:
>              parser.error("opt.output was set to something weird.")
>  
> +    elif action == 'history':
> +        #mimic the bugzilla webpage output
> +        for bug in buglist:
> +            print "Bugzilla %s" % bug.bug_id
> +            print "%-20s %-20s %-20s %-20s %-20s" % ("Who", "When", "What", "Removed", "Added")
> +            for h in bug.history:
> +                who=h['who']
> +                when=h['when']
> +                changes = h['changes']
> +                for c in changes:
> +                    print "%-20s %-20s %-20s %-20s %-20s" %(who, when, c['field_name'], c['removed'], c['added'])
> +                    who=""
> +                    when=""
> +                print
> +
>  if __name__ == '__main__':
>      try:
>          if '--generate-man' in sys.argv:
> diff --git a/bugzilla/base.py b/bugzilla/base.py
> index f4707e0..7adb175 100644
> --- a/bugzilla/base.py
> +++ b/bugzilla/base.py
> @@ -499,6 +499,10 @@ class BugzillaBase(object):
>      def _query(self,query):
>          '''IMPLEMENT ME: Query bugzilla and return a list of matching bugs.'''
>          raise NotImplementedError
> +    def _history(self,idlist):
> +        '''IMPLEMENT ME: Return a list of full bug dicts, one for each of the
> +        given bug ids'''
> +        raise NotImplementedError
>  
>      # these return Bug objects
>      def getbug(self,id):
> @@ -543,6 +547,10 @@ class BugzillaBase(object):
>               'long_desc':string,'long_desc_type':matchtype}
>          return self.query(q)
>  
> +    def history(self,idlist):
> +        '''Return a list of Bug objects with the history of changes for those
> +        Bug objects'''
> +        return [(b and _Bug(bugzilla=self,dict=b)) or None for b in self._history(idlist)]
>      #---- Methods for modifying existing bugs.
>  
>      # Most of these will probably also be available as Bug methods, e.g.:
> diff --git a/bugzilla/bugzilla3.py b/bugzilla/bugzilla3.py
> index ef25278..4a0272b 100644
> --- a/bugzilla/bugzilla3.py
> +++ b/bugzilla/bugzilla3.py
> @@ -176,6 +176,12 @@ class Bugzilla34(Bugzilla32):
>          '''
>          return self._proxy.Bug.search(query)
>  
> +    def _history(self,idlist):
> +        '''Get the change history of a list of bugs
> +        '''
> +        buglist = self._proxy.Bug.history({'ids':idlist})
> +        return buglist['bugs']
> +
>  # Bugzilla 3.6 was released April 13, 2010
>  # XXX TODO probably more new methods from Bugzilla 3.6 we could use
>  class Bugzilla36(Bugzilla34):
> 



More information about the python-bugzilla mailing list