Provide a base class for scripts to use

Bug #409741 reported by Björn Tillenius on 2009-08-06
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
launchpadlib
Low
Unassigned

Bug Description

There should be a base class to use if you want to write a script that uses launchpadlib. I would want the class to set up a Launchpad instance for me, as well as provide options for which service root to use. Basically, a script for getting the display name of some people would look something like this:

"""
  class MyScript(LaunchpadLibScript):
      consumer_name = 'my-script'
      default_service_root = 'edge'

      def add_my_options(self, parser):
          parser.add_option('--output', dest='output', metavar='FILE')

      def main(lp, args, options):
          if options.output:
              output_file = open(options.output, 'w')
          for person_name in args:
              person = lp.people[args[0]]
              person_info = '%s: %s' % (person_name, person.display_name)
              if options.output:
                  output_file.write(person_info)
              else:
                  print person_info

if __name__ == '__main__':
    script = MyScript()
    sys.exit(script.parse_and_run())
"""

Now I should be able to call it using:

    ./my-script.py some-name
    ./my-script.py --output=log-file.txt some-name
    ./my-script.py --service-root=staging some-name

An important part is the last part, which allows me to specify the service-root. It's often desired to change this to run the script against either staging or production, but usually that involves changing the source code to do it. Having a base script class would make the scripts more usable by default. There are other default options that could be desired, for example which credential db to use, and which cache directory.

Changed in launchpadlib:
importance: Undecided → Low
status: New → Triaged
Bryce Harrington (bryce) wrote :

Check out python-launchpadlib-toolkit. I think it provides essentially what you're looking for.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers