2022-09-22 20:40:44 +00:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import configparser
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
def parse_config() -> configparser.SectionProxy:
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read("cli.ini")
|
|
|
|
|
|
|
|
if "frogress" not in config.sections():
|
|
|
|
raise Exception("Missing [frogress] section in cli.ini")
|
|
|
|
|
|
|
|
if "domain" not in config["frogress"]:
|
|
|
|
raise Exception("Missing domain in cli.ini")
|
|
|
|
|
|
|
|
if "api_key" not in config["frogress"]:
|
|
|
|
raise Exception("Missing api_key in cli.ini")
|
|
|
|
|
|
|
|
if "debug" not in config["frogress"]:
|
|
|
|
config["frogress"]["debug"] = "false"
|
|
|
|
|
|
|
|
return config["frogress"]
|
|
|
|
|
|
|
|
|
|
|
|
def debug(msg: str) -> None:
|
|
|
|
if dbg:
|
|
|
|
print(msg)
|
|
|
|
|
|
|
|
|
|
|
|
def create_version(args: argparse.Namespace) -> None:
|
|
|
|
url = f"{domain}/projects/{args.project}/{args.slug}/"
|
|
|
|
|
|
|
|
name = args.name or args.slug
|
|
|
|
|
|
|
|
data = {
|
|
|
|
"api_key": api_key,
|
|
|
|
"name": name,
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("POST " + url)
|
|
|
|
|
|
|
|
response = requests.post(url, json=data)
|
|
|
|
print(response.text)
|
|
|
|
|
|
|
|
|
|
|
|
def delete_version(args: argparse.Namespace) -> None:
|
|
|
|
url = f"{domain}/projects/{args.project}/{args.slug}/"
|
|
|
|
|
|
|
|
data = {"api_key": api_key}
|
|
|
|
|
|
|
|
debug("DELETE " + url)
|
|
|
|
|
|
|
|
response = requests.delete(url, json=data)
|
|
|
|
print(response.text)
|
|
|
|
|
|
|
|
|
2022-11-23 17:01:13 +00:00
|
|
|
def create_category(args: argparse.Namespace) -> None:
|
|
|
|
url = f"{domain}/projects/{args.project}/{args.version}/{args.slug}/"
|
|
|
|
|
|
|
|
name = args.name or args.slug
|
|
|
|
|
|
|
|
data = {
|
|
|
|
"api_key": api_key,
|
|
|
|
"name": name,
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("POST " + url)
|
|
|
|
|
|
|
|
response = requests.post(url, json=data)
|
|
|
|
print(response.text)
|
|
|
|
|
|
|
|
|
|
|
|
def delete_category(args: argparse.Namespace) -> None:
|
|
|
|
url = f"{domain}/projects/{args.project}/{args.version}/{args.slug}/"
|
|
|
|
|
|
|
|
data = {"api_key": api_key}
|
|
|
|
|
|
|
|
debug("DELETE " + url)
|
|
|
|
|
|
|
|
response = requests.delete(url, json=data)
|
|
|
|
print(response.text)
|
|
|
|
|
|
|
|
|
2022-09-23 19:20:56 +00:00
|
|
|
def main() -> None:
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
|
|
|
subparsers = parser.add_subparsers(help="the action to perform", required=True)
|
|
|
|
|
|
|
|
# Create
|
|
|
|
create_parser = subparsers.add_parser("create", help="create a new db object")
|
|
|
|
create_subparsers = create_parser.add_subparsers(
|
|
|
|
help="the db layer on which to operate", required=True
|
|
|
|
)
|
2022-11-23 17:01:13 +00:00
|
|
|
|
|
|
|
# Create version
|
2022-09-23 19:20:56 +00:00
|
|
|
create_version_parser = create_subparsers.add_parser(
|
|
|
|
"version",
|
|
|
|
help="create a new version",
|
|
|
|
)
|
|
|
|
create_version_parser.add_argument(
|
|
|
|
"project", help="the project for which to create the version"
|
|
|
|
)
|
|
|
|
create_version_parser.add_argument("slug", help="the slug for the version")
|
|
|
|
create_version_parser.add_argument("--name", help="the name for the version")
|
|
|
|
create_version_parser.set_defaults(func=create_version)
|
|
|
|
|
2022-11-23 17:01:13 +00:00
|
|
|
# Create category
|
|
|
|
create_category_parser = create_subparsers.add_parser(
|
|
|
|
"category",
|
|
|
|
help="create a new category",
|
|
|
|
)
|
|
|
|
create_category_parser.add_argument(
|
|
|
|
"project", help="the project for which to create the version"
|
|
|
|
)
|
|
|
|
create_category_parser.add_argument("version", help="the slug for the version")
|
|
|
|
create_category_parser.add_argument("slug", help="the slug for the category")
|
|
|
|
create_category_parser.add_argument("--name", help="the name for the category")
|
|
|
|
create_category_parser.set_defaults(func=create_category)
|
|
|
|
|
2022-09-23 19:20:56 +00:00
|
|
|
# Delete
|
|
|
|
delete_parser = subparsers.add_parser("delete", help="delete a db object")
|
|
|
|
delete_subparsers = delete_parser.add_subparsers(
|
|
|
|
help="the db layer on which to operate", required=True
|
|
|
|
)
|
2022-11-23 17:01:13 +00:00
|
|
|
|
|
|
|
# Delete version
|
2022-09-23 19:20:56 +00:00
|
|
|
delete_version_parser = delete_subparsers.add_parser(
|
|
|
|
"version",
|
|
|
|
help="delete a version",
|
|
|
|
)
|
|
|
|
delete_version_parser.add_argument(
|
|
|
|
"project", help="the project for which to delete the version"
|
|
|
|
)
|
|
|
|
delete_version_parser.add_argument("slug", help="the slug for the version")
|
|
|
|
delete_version_parser.set_defaults(func=delete_version)
|
|
|
|
|
2022-11-23 17:01:13 +00:00
|
|
|
# Delete category
|
|
|
|
delete_category_parser = delete_subparsers.add_parser(
|
|
|
|
"category",
|
|
|
|
help="delete a category",
|
|
|
|
)
|
|
|
|
delete_category_parser.add_argument(
|
|
|
|
"project", help="the project for which to delete the version"
|
|
|
|
)
|
|
|
|
delete_category_parser.add_argument("version", help="the slug for the version")
|
|
|
|
delete_category_parser.add_argument("slug", help="the slug for the category")
|
|
|
|
delete_category_parser.set_defaults(func=delete_category)
|
|
|
|
|
2022-09-23 19:20:56 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
args.func(args)
|
|
|
|
|
|
|
|
|
2022-09-22 20:40:44 +00:00
|
|
|
config = parse_config()
|
|
|
|
|
2022-09-23 19:20:56 +00:00
|
|
|
dbg = bool(config["debug"])
|
2022-09-22 20:40:44 +00:00
|
|
|
domain = config["domain"]
|
|
|
|
api_key = config["api_key"]
|
|
|
|
|
2022-09-23 19:20:56 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|