| 1 |
#!/usr/bin/python3 |
| 2 |
import logging |
| 3 |
|
| 4 |
import argcomplete.completers |
| 5 |
|
| 6 |
from mini_buildd import changes, cli, client, events, net, util |
| 7 |
|
| 8 |
LOG = logging.getLogger("mini_buildd") |
| 9 |
|
| 10 |
#: Needed for man page hack in setup.py |
| 11 |
DESCRIPTION = "Upload it like mini-buildd (unlike dput/dput-ng, supports ftps)" |
| 12 |
|
| 13 |
|
| 14 |
class CLI(cli.CLI): |
| 15 |
def __init__(self): |
| 16 |
self.default_dputcf = cli.DputCf() # Helper to get completion for the default config path |
| 17 |
|
| 18 |
super().__init__("mini-buildd-dput", DESCRIPTION) |
| 19 |
self.parser.add_argument("-c", "--config", action="store", default=cli.DputCf.DEFAULT_PATH, help="Configuration file to parse") |
| 20 |
self.parser.add_argument("-f", "--force", action="store_true", help="Disable check for unique upload") |
| 21 |
self.parser.add_argument("-C", "--check-result", action="store_true", help="Wait for and check packaging results (fails if package is not installed)") |
| 22 |
self.parser.add_argument("target", action="store", metavar="TARGET", |
| 23 |
help="dput target (configuration section id in .dput.cf)").completer = self.default_dputcf.target_completer |
| 24 |
self.parser.add_argument("changes", action="store", metavar="CHANGES", |
| 25 |
help="changes file").completer = argcomplete.completers.FilesCompleter([".changes"]) |
| 26 |
|
| 27 |
def runcli(self): |
| 28 |
dputcf = cli.DputCf(self.args.config) |
| 29 |
upload = changes.Base(self.args.changes) |
| 30 |
endpoint = net.ClientEndpoint(dputcf.get_target_ftp_url(self.args.target)) |
| 31 |
pre_upload_timestamp = upload.upload(endpoint, force=self.args.force) |
| 32 |
if self.args.check_result: |
| 33 |
event = client.Client(dputcf.get_target_http_url(self.args.target)).event(types=[events.Type.INSTALLED, events.Type.FAILED], |
| 34 |
source=upload["Source"], version=upload["Version"], distribution=upload["Distribution"], |
| 35 |
after=pre_upload_timestamp) |
| 36 |
if event.type == events.Type.FAILED: |
| 37 |
raise util.HTTPBadRequest(event) |
| 38 |
print(event) |
| 39 |
|
| 40 |
|
| 41 |
if __name__ == "__main__": |
| 42 |
CLI().run() |