~abentley/lp-dev-utils/ab-logging

« back to all changes in this revision

Viewing changes to lpscripts.py

  • Committer: Curtis Hovey
  • Date: 2010-06-02 21:13:52 UTC
  • mfrom: (84.1.15 trunk)
  • Revision ID: sinzui.is@verizon.net-20100602211352-udf9fsseugabhnvy
Merged tip.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
                     )
34
34
 
35
35
 
36
 
def lp_factory(system_name, app_name=None):
 
36
def lp_factory(system_name, app_name):
37
37
    """Get a launchpad API instance for ``system_name``."""
38
38
    try:
39
 
        assert app_name is not None, "You must provide an app_name"
40
39
        service_root = SERVICE_ROOTS[system_name.lower()]
41
40
        return Launchpad.login_with(app_name, service_root)
42
41
    except KeyError:
268
267
            type='string', default=None,
269
268
            dest='rtm_address',
270
269
            help="""\
271
 
Provide your RememberTheMilk.com address for emailing tasks.  It can be found under
272
 
the 'Settings->Info' tab in RTM.  The default is to use the Launchpad group account.""")
 
270
Provide your RememberTheMilk.com address for emailing tasks.
 
271
It can be found under the 'Settings->Info' tab in RTM.
 
272
The default is to use the Launchpad group account.""")
273
273
 
274
274
        self.parser.add_option(
275
275
            '--edit-msg',
277
277
            help="""\
278
278
Open outgoing message in your EDITOR for customization.""")
279
279
 
280
 
    def parseArgs(self):
 
280
    def parseArgs(self, args=None):
281
281
        """Parse the arguments.
282
282
 
283
283
        Sets self.opts and self.args.
284
284
        """
285
 
        self.parser = optparse.OptionParser(self.USAGE, conflict_handler="resolve")
 
285
        self.parser = optparse.OptionParser(self.USAGE,
 
286
                                            conflict_handler="resolve")
286
287
 
287
288
        self.addParserOptions()
288
289
 
289
 
        self.opts, self.args = self.parser.parse_args()
 
290
        if args is None:
 
291
            args = sys.argv[1:]
 
292
        self.opts, self.args = self.parser.parse_args(args)
290
293
        if len(self.args) < 1:
291
294
            self.parser.error('Missing projects')
292
295
 
293
296
    def normalizeProjectName(self, project_name):
294
 
        """Project names may be passed as the full URL.  Return just the name."""
 
297
        """Project names may be passed as the full URL.
 
298
 
 
299
        Return just the name.
 
300
        """
295
301
        project_name = project_name.strip()
296
302
        if project_name.endswith("/+review"):
297
303
            project_name = "/".join(project_name.split("/")[0:-1])
309
315
        print "Connecting..."
310
316
        sys.stdout.flush()
311
317
        try:
312
 
            self.lp = lp_factory(self.opts.lpsystem, self.name)
 
318
            if self.lp is None:
 
319
                self.lp = lp_factory(self.opts.lpsystem, self.name)
313
320
        except launchpadlib.errors.HTTPError, e:
314
321
            print "An error has occured contacting Launchpad."
315
322
            print e
331
338
 
332
339
            self.process_project(proj)
333
340
 
334
 
    def __init__(self, name=None):
 
341
    def __init__(self, name=None, lp=None, args=None):
335
342
        if name is None:
336
343
            name = os.path.split(sys.argv[0])[-1]
337
344
        self.name = name
338
 
        self.parseArgs()
 
345
        self.lp = lp
 
346
        self.parseArgs(args)
339
347
 
340
348
 
341
349
if __name__ == "__main__":