412f21c297a3048c083a3ad65f739410021af485
[utils.git] / src / budget_sync / main.py
1 from bugzilla import Bugzilla
2 import logging
3 import argparse
4 from budget_sync.util import all_bugs
5 from budget_sync.config import Config, ConfigParseError
6 from budget_sync.budget_graph import BudgetGraph, BudgetGraphBaseError
7
8
9 BUGZILLA_URL = "https://bugs.libre-soc.org"
10
11
12 def main():
13 parser = argparse.ArgumentParser(
14 description="Check for errors in "
15 "Libre-SOC's style of budget tracking in Bugzilla.")
16 parser.add_argument(
17 "-c, --config", type=argparse.FileType('r'),
18 required=True, help="The path to the configuration TOML file",
19 dest="config", metavar="<path/to/budget-sync-config.toml>")
20 args = parser.parse_args()
21 try:
22 with args.config as config_file:
23 config = Config.from_file(config_file)
24 except (IOError, ConfigParseError) as e:
25 logging.error("Failed to parse config file: %s", e)
26 return
27 logging.info("Using Bugzilla instance at %s", config.bugzilla_url)
28 bz = Bugzilla(config.bugzilla_url)
29 logging.debug("Connected to Bugzilla")
30 budget_graph = BudgetGraph(all_bugs(bz), config)
31 for error in budget_graph.get_errors():
32 logging.error("%s", error)
33
34
35 if __name__ == "__main__":
36 main()