Debian Codegraph @

src/mini-buildd-events

raw
1 #!/usr/bin/python3
2 import logging
3
4 from mini_buildd import cli, client, events, util
5
6 LOG = logging.getLogger("mini_buildd")
7
8 #: Needed for man page hack in setup.py
9 DESCRIPTION = "Monitor events. Optionally exit when criteria is met."
10
11
12 class CLI(cli.CLI):
13 TYPE_CHOICES = [t.name for t in list(events.Type)]
14
15 def __init__(self):
16 super().__init__("mini-buildd-events", DESCRIPTION)
17
18 self._add_endpoint(self.parser)
19 self.parser.add_argument("-A", "--after", type=util.Datetime.parse, action="store", help=f"Also show past events after this date. {util.Datetime.parse.__doc__}.")
20 self.parser.add_argument("-T", "--types", choices=self.TYPE_CHOICES, action="store", nargs="+", help="Types filter")
21 self.parser.add_argument("-D", "--distribution", action="store", help="Distribution filter")
22 self.parser.add_argument("-S", "--source", action="store", help="Source package name filter")
23 self.parser.add_argument("-V", "--source-version", action="store", help="Version filter")
24 self.parser.add_argument("-M", "--minimal-version", action="store", help="Minimal version filter")
25 self.parser.add_argument("-E", "--exit-on", choices=self.TYPE_CHOICES, action="store", nargs="+", help="Types to exit on")
26 self.parser.add_argument("-F", "--fail-on", choices=self.TYPE_CHOICES, action="store", nargs="+", help="Types to (return and) fail on")
27
28 def runcli(self):
29 def n2t(names):
30 return [events.Type[t] for t in names] if names else None
31
32 clnt = client.Client(self.args.endpoint)
33 for event in clnt.ievents(after=self.args.after,
34 types=n2t(self.args.types),
35 distribution=self.args.distribution,
36 source=self.args.source,
37 version=self.args.source_version,
38 minimal_version=self.args.minimal_version,
39 exit_on=n2t(self.args.exit_on),
40 fail_on=n2t(self.args.fail_on)):
41 print(util.json_pretty(event.to_json()))
42
43
44 if __name__ == "__main__":
45 CLI().run()