#!/usr/bin/env python
#
# Tutorial:
#    The difference between this tutorial/example and tut.01 is that this shows
#    how to point at one of the other Launchpad services.
#
#    The staging service, exists for testing various things. This is running
#    against a snapshot of the database. Changes made on the staging server are
#    not permanent changes and will disapear when the database is reloaded (once
#    each day).
#

from lpltk.service                   import LaunchpadService
from datetime                        import datetime

# LpltkTutorial
#
class LpltkTutorial():
    # main
    #
    def main(self):
        configuration = {}

        # By passing in the configuration dictionary, we've instructed the class
        # to connect to the Launchpad staging server.
        #
        lp = LaunchpadService(configuration)

        # The service.distributions property is a collection of distributions. We
        # pretty much only care about one, 'ubuntu'.
        #
        distro         = lp.distributions['ubuntu']

        # Within a distribution are many source packages. We actually care about
        # several, but _mostly_ the 'linux' source package.
        #
        source_package = distro.get_source_package('linux')

        # Searching for bug tasks, the search can be quite complicated and made up
        # of several components. The following can be combined in many ways to get
        # the search you want. The search happens on the server and returns a
        # collection of bug tasks that match the search criteria.
        #
        # tasks = pkg.search_tasks(tags=search_tags, tags_combinator=search_tags_combinator,
        #                          status=self.cfg['task_search_status'], modified_since=since)
        #
        search_tags            = [] # A list of the tags we care about
        search_tags_combinator = "All"
        search_status          = ["New"] # A list of the bug statuses that we care about
        search_since           = datetime(year=2010, month=11, day=29)
        tasks = source_package.search_tasks(status=search_status, modified_since=search_since)

        for task in tasks:
            bug = task.bug
            print(bug.id)

if __name__ == '__main__':
    app = LpltkTutorial()
    app.main()

# vi:set ts=4 sw=4 expandtab:

