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
)
16 parser
= argparse
.ArgumentParser(
17 description
="Check for errors in "
18 "Libre-SOC's style of budget tracking in Bugzilla.")
20 "-c", "--config", type=argparse
.FileType('r'),
21 required
=True, help="The path to the configuration TOML file",
22 dest
="config", metavar
="<path/to/budget-sync-config.toml>")
24 "-o", "--output-dir", type=Path
, default
=None,
25 help="The path to the output directory, will be created if it "
27 dest
="output_dir", metavar
="<path/to/output/dir>")
28 parser
.add_argument('--username', help="Log in with this username")
29 parser
.add_argument('--password', help="Log in with this password")
30 parser
.add_argument('--bug', help="bug number")
31 parser
.add_argument('--user', help="set payee user")
32 parser
.add_argument('--paid', help="set paid date")
33 parser
.add_argument('--submitted', help="set submitted date")
34 args
= parser
.parse_args()
36 with args
.config
as config_file
:
37 config
= Config
.from_file(config_file
)
38 except (IOError, ConfigParseError
) as e
:
39 logging
.error("Failed to parse config file: %s", e
)
41 logging
.info("Using Bugzilla instance at %s", config
.bugzilla_url
)
42 bz
= Bugzilla(config
.bugzilla_url
)
44 logging
.debug("logging in...")
45 bz
.interactive_login(args
.username
, args
.password
)
46 logging
.debug("Connected to Bugzilla")
47 bugs
= str(args
.bug
).split(",")
48 buglist
= bz
.getbugs(bugs
)
49 logging
.info("got bugs %s" % args
.bug
)
51 print ("payees", bug
.id)
52 print (" "+"\n ".join(bug
.cf_payees_list
.split('\n')))
54 parsed_toml
= toml
.loads(bug
.cf_payees_list
)
56 payee
= parsed_toml
[args
.user
]
57 if isinstance(payee
, int):
58 payee
= {'amount': payee
}
62 if args
.submitted
and 'submitted' not in payee
:
64 d
= datetime
.strptime(args
.submitted
, "%Y-%m-%d")
65 payee
['submitted'] = date(d
.year
, d
.month
, d
.day
)
67 if args
.paid
and 'paid' not in payee
:
69 d
= datetime
.strptime(args
.paid
, "%Y-%m-%d")
70 payee
['paid'] = date(d
.year
, d
.month
, d
.day
)
72 # skip over not modified
76 parsed_toml
[args
.user
] = payee
78 encoder
= toml
.encoder
.TomlPreserveInlineDictEncoder()
79 ttxt
= toml
.dumps(parsed_toml
, encoder
=encoder
)
82 #update = bz.build_update(cf_payees_list=ttxt)
83 bz
.update_bugs([bug
.id], {'cf_payees_list': ttxt
})
85 if __name__
== "__main__":