111 lines
3.3 KiB
Python
111 lines
3.3 KiB
Python
import argparse
|
|
import json
|
|
from pprint import pprint
|
|
|
|
from ActiveCollabAPI.AcSubtask import AcSubtask
|
|
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)
|
|
if args.object == "subtask":
|
|
output = run_subtask(ac, args)
|
|
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_subtask(ac, args):
|
|
pprint(args)
|
|
output = None
|
|
if args.command == "list":
|
|
output = list(map(lambda sub: sub.to_dict(), ac.get_subtasks(args.project, args.task)))
|
|
if args.command == "create":
|
|
subtask = AcSubtask(
|
|
project_id=args.project,
|
|
task_id=args.task,
|
|
body=args.body
|
|
)
|
|
output = ac.create_subtask(subtask)
|
|
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')
|
|
|
|
# subtask
|
|
parser_subtask = subparsers.add_parser('subtask', help='subtask help')
|
|
parser_subtask.set_defaults(object='subtask')
|
|
parser_subtask.add_argument('command', choices=["list", "create"], help='what to do with the account help')
|
|
parser_subtask.add_argument('--project', type=int, required=True)
|
|
parser_subtask.add_argument('--task', type=int, required=True)
|
|
parser_subtask.add_argument('--body', type=str)
|
|
|
|
args = parser.parse_args()
|
|
|
|
config = load_config(args)
|
|
output = run(args, config)
|
|
print(serialize_output(output))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|