2 from budget_sync
.write_budget_csv
import write_budget_csv
3 from bugzilla
import Bugzilla
6 from pathlib
import Path
7 from budget_sync
.config
import Config
, ConfigParseError
, Milestone
8 from budget_sync
.budget_graph
import (BudgetGraph
, BudgetGraphBaseError
,
10 from budget_sync
.write_budget_markdown
import write_budget_markdown
11 from datetime
import datetime
, date
13 logging
.basicConfig(level
=logging
.INFO
)
17 parser
= argparse
.ArgumentParser(
18 description
="Check for errors in "
19 "Libre-SOC's style of budget tracking in Bugzilla.")
21 "-c", "--config", type=argparse
.FileType('r'),
22 required
=True, help="The path to the configuration TOML file",
23 dest
="config", metavar
="<path/to/budget-sync-config.toml>")
25 "-o", "--output-dir", type=Path
, default
=None,
26 help="The path to the output directory, will be created if it "
28 dest
="output_dir", metavar
="<path/to/output/dir>")
29 parser
.add_argument('--username', help="Log in with this username")
30 parser
.add_argument('--password', help="Log in with this password")
31 parser
.add_argument('--bug', help="bug number")
32 parser
.add_argument('--user', help="set payee user")
33 parser
.add_argument('--paid', help="set paid date")
34 parser
.add_argument('--submitted', help="set submitted date")
35 args
= parser
.parse_args()
37 with args
.config
as config_file
:
38 config
= Config
.from_file(config_file
)
39 except (IOError, ConfigParseError
) as e
:
40 logging
.error("Failed to parse config file: %s", e
)
42 logging
.info("Using Bugzilla instance at %s", config
.bugzilla_url
)
43 bz
= Bugzilla(config
.bugzilla_url
)
45 logging
.debug("logging in...")
46 bz
.interactive_login(args
.username
, args
.password
)
47 logging
.debug("Connected to Bugzilla")
48 bugs
= str(args
.bug
).split(",")
49 buglist
= bz
.getbugs(bugs
)
50 logging
.info("got bugs %s" % args
.bug
)
52 print("payees", bug
.id)
53 print(" "+"\n ".join(bug
.cf_payees_list
.split('\n')))
55 parsed_toml
= toml
.loads(bug
.cf_payees_list
)
57 payee
= parsed_toml
[args
.user
]
58 if isinstance(payee
, int):
59 payee
= {'amount': payee
}
63 if args
.submitted
and 'submitted' not in payee
:
65 d
= datetime
.strptime(args
.submitted
, "%Y-%m-%d")
66 payee
['submitted'] = date(d
.year
, d
.month
, d
.day
)
68 if args
.paid
and 'paid' not in payee
:
70 d
= datetime
.strptime(args
.paid
, "%Y-%m-%d")
71 payee
['paid'] = date(d
.year
, d
.month
, d
.day
)
73 # skip over not modified
77 parsed_toml
[args
.user
] = payee
79 encoder
= toml
.encoder
.TomlPreserveInlineDictEncoder()
80 ttxt
= toml
.dumps(parsed_toml
, encoder
=encoder
)
83 #update = bz.build_update(cf_payees_list=ttxt)
84 bz
.update_bugs([bug
.id], {'cf_payees_list': ttxt
})
87 if __name__
== "__main__":