85 lines
2.4 KiB
Python
85 lines
2.4 KiB
Python
import argparse
|
|
import json
|
|
from pprint import pprint
|
|
|
|
from ActiveCollabAPI.ActiveCollab import ActiveCollab
|
|
|
|
|
|
def run(args, config):
|
|
# run the command
|
|
ac = ActiveCollab(config["base_url"])
|
|
ac.login_to_first_account(config["username"], config["password"])
|
|
output = None
|
|
if args.object == "info":
|
|
output = run_info(ac, args)
|
|
if args.object == "account":
|
|
output = run_account(ac, args)
|
|
if args.object == "project":
|
|
output = run_project(ac, args, output)
|
|
return output
|
|
|
|
|
|
def run_account(ac, args):
|
|
if args.command == "list":
|
|
return ac.session.to_dict()
|
|
|
|
|
|
def run_project(ac, args, output):
|
|
if args.command == "list":
|
|
output = list(map(lambda p: p.to_dict(), ac.get_projects()))
|
|
return output
|
|
|
|
|
|
def run_info(ac, args):
|
|
output = ac.get_info()
|
|
return output
|
|
|
|
|
|
def serialize_output(output):
|
|
# serialize the output
|
|
return json.dumps(output)
|
|
|
|
|
|
def load_config(args):
|
|
with open(args.config, "r", encoding="utf8") as fh:
|
|
config = json.load(fh)
|
|
return config
|
|
|
|
|
|
def main():
|
|
# parse arguments
|
|
parser = argparse.ArgumentParser(
|
|
prog='activecollab',
|
|
description='This is a CLI Client to Active-Collab Service',
|
|
epilog='This is not a offical tool provided by the AC Guys!')
|
|
parser.add_argument('-c', '--config', required=True,
|
|
help="use the named config file")
|
|
parser.add_argument('-v', '--version', action='store_true',
|
|
help="show version information for this tool")
|
|
|
|
subparsers = parser.add_subparsers(help='sub-command help')
|
|
|
|
# info list
|
|
parser_account = subparsers.add_parser('info', help='info help')
|
|
parser_account.set_defaults(object='info')
|
|
|
|
# account list
|
|
parser_account = subparsers.add_parser('account', help='account help')
|
|
parser_account.set_defaults(object='account')
|
|
parser_account.add_argument('command', choices=["list"], help='list all accessible accounts')
|
|
|
|
# project list get
|
|
parser_project = subparsers.add_parser('project', help='project help')
|
|
parser_project.set_defaults(object='project')
|
|
parser_project.add_argument('command', choices=["list"], help='what to do with the account help')
|
|
|
|
args = parser.parse_args()
|
|
|
|
config = load_config(args)
|
|
output = run(args, config)
|
|
print(serialize_output(output))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|