summaryrefslogtreecommitdiffstats
path: root/python/fatcat_util.py
blob: 08224dce0c15eb1a404b5b3e73ec9c92c340c17d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3

"""
TODO:
- roll 'shell' stuff into this command
- create, submit, accept editgroups
- create entity from JSON (?)
"""

import sys
import json
import argparse

import fatcat_openapi_client
from fatcat_openapi_client.rest import ApiException
from fatcat_openapi_client import ReleaseEntity, ContainerEntity, ChangelogEntry
from fatcat_tools import uuid2fcid, fcid2uuid, entity_from_json, \
    entity_to_dict, public_api, authenticated_api


def run_uuid2fcid(args):
    print(uuid2fcid(args.uuid))

def run_fcid2uuid(args):
    print(fcid2uuid(args.fcid))

def run_editgroup_accept(args):
    args.api.accept_editgroup(args.editgroup_id)

def run_editgroup_submit(args):
    eg = args.api.get_editgroup(args.editgroup_id)
    args.api.update_editgroup(args.editgroup_id, eg, submit=True)

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--debug',
        action='store_true',
        help="enable debugging interface")
    parser.add_argument('--host-url',
        default="http://localhost:9411/v0",
        help="connect to this host/port")
    subparsers = parser.add_subparsers()

    sub_uuid2fcid = subparsers.add_parser('uuid2fcid')
    sub_uuid2fcid.set_defaults(func=run_uuid2fcid)
    sub_uuid2fcid.add_argument('uuid',
        help="UUID to transform")

    sub_fcid2uuid = subparsers.add_parser('fcid2uuid')
    sub_fcid2uuid.set_defaults(func=run_fcid2uuid)
    sub_fcid2uuid.add_argument('fcid',
        help="FCID to transform (into UUID)")

    sub_editgroup_accept = subparsers.add_parser('editgroup-accept')
    sub_editgroup_accept.set_defaults(func=run_editgroup_accept)
    sub_editgroup_accept.add_argument('editgroup_id',
        help="editgroup to accept")

    sub_editgroup_submit = subparsers.add_parser('editgroup-submit')
    sub_editgroup_submit.set_defaults(func=run_editgroup_submit)
    sub_editgroup_submit.add_argument('editgroup_id',
        help="editgroup to submit")

    args = parser.parse_args()
    if not args.__dict__.get("func"):
        print("tell me what to do!")
        sys.exit(-1)

    args.api = authenticated_api(args.host_url)
    args.func(args)

if __name__ == '__main__':
    main()