Move the argument parsing code into a separate `parse_args` function to
make the `main` function a little bit smaller.
The `IndexError` on accessing `args.packages` cannot happen.
The current version is not working
```
$ ubuntu-build librsync resolute retry
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 354, in __getattr__
return self.lp_get_parameter(attr)
~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py", line 249, in lp_get_parameter
raise KeyError("No such parameter: %s" % param_name)
KeyError: 'No such parameter: getComponent'
```
The way launchpadlib is used was changed in 010af53 but non batch mode
was not correctly updated.
Also tweak the way the release is computed for distroseries to be able
to retry a package in e.g "resolute-proposed".
This results in a major refactor of the code to use launchpadlib directly
instead of the ubuntutools.lp.lpapicache module in ubuntu-dev-tools which is
idiosyncratic and does not expose the full launchpad API. Easier to rewrite
to use the standard library.
Do it at the begin instead of replicating the same code inside the tool itself.
This fixes e.g. this failure:
./ubuntu-build --batch --retry morsmall
Traceback (most recent call last):
File "/tmp/ubuntu-dev-tools/ubuntu-build", line 317, in <module>
main()
File "/tmp/ubuntu-dev-tools/ubuntu-build", line 289, in main
can_retry = args.retry and me.canUploadPackage(
AttributeError: 'NoneType' object has no attribute 'canUploadPackage'
pylint complains about C0209: Formatting a regular string which could be
a f-string (consider-using-f-string)
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
pylint complains about W1201: Use lazy % formatting in logging functions
(logging-not-lazy) and W1203: Use lazy % formatting in logging functions
(logging-fstring-interpolation).
Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
Python logging by default sends all output to stderr, but that's not what
normal programs usually do and is not expected for these scripts.
Change the ubuntutools.getLogger() method to return a logger with handlers
correctly set up to send INFO level (or lower) logs to stdout and WARNING
level (or higher; technically INFO+1 level or higher) logs to stderr.
This results in normally logged output going to stdout and warnings/errors
going to stderr, as expected.