2726dbf0457bcf289b056213431c21a625a862f5
[utils.git] / src / budget_sync / main.py
1 from bugzilla import Bugzilla
2 import logging
3 import argparse
4 from pathlib import Path
5 from budget_sync.util import all_bugs
6 from budget_sync.config import Config, ConfigParseError
7 from budget_sync.budget_graph import BudgetGraph, BudgetGraphBaseError
8 from budget_sync.write_budget_markdown import write_budget_markdown
9
10
11 def main():
12 parser = argparse.ArgumentParser(
13 description="Check for errors in "
14 "Libre-SOC's style of budget tracking in Bugzilla.")
15 parser.add_argument(
16 "-c", "--config", type=argparse.FileType('r'),
17 required=True, help="The path to the configuration TOML file",
18 dest="config", metavar="<path/to/budget-sync-config.toml>")
19 parser.add_argument(
20 "-o", "--output-dir", type=Path, default=None,
21 help="The path to the output directory, will be created if it "
22 "doesn't exist",
23 dest="output_dir", metavar="<path/to/output/dir>")
24 args = parser.parse_args()
25 try:
26 with args.config as config_file:
27 config = Config.from_file(config_file)
28 except (IOError, ConfigParseError) as e:
29 logging.error("Failed to parse config file: %s", e)
30 return
31 logging.info("Using Bugzilla instance at %s", config.bugzilla_url)
32 bz = Bugzilla(config.bugzilla_url)
33 logging.debug("Connected to Bugzilla")
34 budget_graph = BudgetGraph(all_bugs(bz), config)
35 for error in budget_graph.get_errors():
36 logging.error("%s", error)
37 if args.output_dir is not None:
38 write_budget_markdown(budget_graph, args.output_dir)
39
40
41 if __name__ == "__main__":
42 main()