Add pagination helpers to API ListResources

Review Request #7181 — Created April 7, 2015 and submitted

Information

RBTools
master

Reviewers

Instances of API ListResource classes can easily iterate through all
pages or through all items of all pages easily via new helper methods.
These methods hide the pagination logic that was being used elsewhere
to manually go through all pages of ListResources.

All instances of this have been replaced with the new helpers to make
the logic cleaner.

Ran unit tests.

Description From Last Updated

Can we call this get_pages()?

daviddavid

Because this is a generator function, you don't need to catch StopIteration--you can just let it percolate up and whatever …

daviddavid

Can we call this get_all()?

daviddavid

Missing a trailing period.

chipx86chipx86

"of the same"

chipx86chipx86

Generally speaking, a list comprehension would be better here. Avoids the function call to the lambda and the ones to …

chipx86chipx86

getattr() requires the default parameter if the attribute may not be on the object (which is why we have this …

chipx86chipx86
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        rbtools/commands/status.py
        rbtools/utils/review_request.py
        rbtools/api/resource.py
        rbtools/commands/setup_repo.py
        rbtools/clients/clearcase.py
        rbtools/commands/post.py
        rbtools/utils/repository.py
        rbtools/clients/svn.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        rbtools/commands/status.py
        rbtools/utils/review_request.py
        rbtools/api/resource.py
        rbtools/commands/setup_repo.py
        rbtools/clients/clearcase.py
        rbtools/commands/post.py
        rbtools/utils/repository.py
        rbtools/clients/svn.py
    
    
  2. 
      
david
  1. 
      
  2. rbtools/api/resource.py (Diff revision 1)
     
     
    Show all issues

    Can we call this get_pages()?

  3. rbtools/api/resource.py (Diff revision 1)
     
     
     
     
     
     
     
    Show all issues

    Because this is a generator function, you don't need to catch StopIteration--you can just let it percolate up and whatever is iterating it will stop.

  4. rbtools/api/resource.py (Diff revision 1)
     
     
    Show all issues

    Can we call this get_all()?

  5. 
      
brennie
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        rbtools/commands/status.py
        rbtools/utils/review_request.py
        rbtools/api/resource.py
        rbtools/commands/setup_repo.py
        rbtools/clients/clearcase.py
        rbtools/commands/post.py
        rbtools/utils/repository.py
        rbtools/clients/svn.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        rbtools/commands/status.py
        rbtools/utils/review_request.py
        rbtools/api/resource.py
        rbtools/commands/setup_repo.py
        rbtools/clients/clearcase.py
        rbtools/commands/post.py
        rbtools/utils/repository.py
        rbtools/clients/svn.py
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
  1. 
      
  2. rbtools/api/resource.py (Diff revision 2)
     
     
    Show all issues

    Missing a trailing period.

  3. rbtools/api/resource.py (Diff revision 2)
     
     
    Show all issues

    "of the same"

  4. rbtools/clients/svn.py (Diff revision 2)
     
     
     
    Show all issues

    Generally speaking, a list comprehension would be better here. Avoids the function call to the lambda and the ones to list() and filter(), and is a little more readable:

    repositories = [
        repo
        for repo in server.get_repositories().all_items
        if repo['tool'] == 'Subversion'
    ]
    
  5. rbtools/utils/repository.py (Diff revision 2)
     
     
    Show all issues

    getattr() requires the default parameter if the attribute may not be on the object (which is why we have this getattr() in the first place).

  6. 
      
brennie
reviewbot
  1. Tool: Pyflakes
    Processed Files:
        rbtools/commands/status.py
        rbtools/utils/review_request.py
        rbtools/api/resource.py
        rbtools/commands/setup_repo.py
        rbtools/clients/clearcase.py
        rbtools/commands/post.py
        rbtools/utils/repository.py
        rbtools/clients/svn.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        rbtools/commands/status.py
        rbtools/utils/review_request.py
        rbtools/api/resource.py
        rbtools/commands/setup_repo.py
        rbtools/clients/clearcase.py
        rbtools/commands/post.py
        rbtools/utils/repository.py
        rbtools/clients/svn.py
    
    
  2. 
      
chipx86
  1. Ship It!
  2. 
      
brennie
Review request changed
Status:
Completed
Change Summary:
Pushed to master (90d36d9)