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.
mypy complains:
```
ubuntutools/lp/lpapicache.py:143: error: Incompatible types in assignment (expression has type "None", variable has type "str") [assignment]
ubuntutools/lp/lpapicache.py:1328: error: Incompatible types in assignment (expression has type "tuple[str, str]", base class "BaseWrapper" defined the type as "str") [assignment]
```
pylint complains:
```
syncpackage:459:4: W0603: Using the global statement (global-statement)
```
Replace the `global` statement by `functools.lru_cache`.
pylint complains:
```
ubuntutools/archive.py:343:8: R1737: Use 'yield from' directly instead of yielding each element one by one (use-yield-from)
ubuntutools/archive.py:346:8: R1737: Use 'yield from' directly instead of yielding each element one by one (use-yield-from)
ubuntutools/archive.py:638:8: R1737: Use 'yield from' directly instead of yielding each element one by one (use-yield-from)
```
pylint complains:
```
requestsync:156:34: E0606: Possibly using variable 'bug_mail_domain' before assignment (possibly-used-before-assignment)
requestsync:217:27: E0606: Possibly using variable 'Distribution' before assignment (possibly-used-before-assignment)
requestsync:380:8: E0606: Possibly using variable 'post_bug' before assignment (possibly-used-before-assignment)
```
These errors are false positives. So silence them. The perfect solution
would be to restructure the code.
pylint complains:
```
ubuntutools/sponsor_patch/sponsor_patch.py:243:45: E0606: Possibly using variable 'task' before assignment (possibly-used-before-assignment)
```
Drop the `len(ubuntu_tasks) > 1` check and rely on being the else case.
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".
flake8 complains:
```
./syncpackage:465:9: E722 do not use bare 'except'
```
The function `urllib.request.urlopen` might throw
`urllib.error.URLError`, `urllib.error.HTTPError`, `socket.gaierror`,
`ssl.SSLError` which are all subclasses of `OSError`.
Various methods in `ubuntutools.lp.lpapicache` iterated over collections
in a pessimal way: they fetched the collection and then fetched each
individual entry in it, when the same information was already available
in the collection response. Use more idiomatic launchpadlib code for
this instead, which is also much faster.
mk-sbuild installs pkgbinarymangler into the schroot. Of of the
provided tools in pkgbinarymangler is pkgmaintainermangler.
pkgmaintainermangler is disabled by default, and enabled with
configuration.
A difference between launchpad builds of a synced package and an sbuild
is that the maintainer information will be different.
Enable pkgmaintainermangler to close this difference.