mirror of
https://github.com/flatpak/flatpak.git
synced 2026-01-26 06:07:56 +00:00
tests/oci-registry-client.py: Convert to argparse
This commit is contained in:
parent
34acb5799e
commit
05e2b083ed
57
tests/oci-registry-client.py
Normal file → Executable file
57
tests/oci-registry-client.py
Normal file → Executable file
@ -1,45 +1,62 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import http.client
|
||||
import urllib.parse
|
||||
|
||||
|
||||
def get_conn(url):
|
||||
parsed = urllib.parse.urlparse(url)
|
||||
def get_conn(args):
|
||||
parsed = urllib.parse.urlparse(args.url)
|
||||
return http.client.HTTPConnection(host=parsed.hostname, port=parsed.port)
|
||||
|
||||
|
||||
if sys.argv[2] == 'add':
|
||||
detach_icons = '--detach-icons' in sys.argv
|
||||
if detach_icons:
|
||||
sys.argv.remove('--detach-icons')
|
||||
params = {'d': sys.argv[5]}
|
||||
if detach_icons:
|
||||
params['detach-icons'] = 1
|
||||
def run_add(args):
|
||||
params = {"d": args.oci_dir}
|
||||
if args.detach_icons:
|
||||
params["detach-icons"] = "1"
|
||||
query = urllib.parse.urlencode(params)
|
||||
conn = get_conn(sys.argv[1])
|
||||
path = "/testing/{repo}/{tag}?{query}".format(repo=sys.argv[3],
|
||||
tag=sys.argv[4],
|
||||
query=query)
|
||||
conn = get_conn(args)
|
||||
path = "/testing/{repo}/{tag}?{query}".format(
|
||||
repo=args.repo, tag=args.tag, query=query
|
||||
)
|
||||
conn.request("POST", path)
|
||||
response = conn.getresponse()
|
||||
if response.status != 200:
|
||||
print(response.read(), file=sys.stderr)
|
||||
print("Failed: status={}".format(response.status), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
elif sys.argv[2] == 'delete':
|
||||
conn = get_conn(sys.argv[1])
|
||||
path = "/testing/{repo}/{ref}".format(repo=sys.argv[3],
|
||||
ref=sys.argv[4])
|
||||
|
||||
|
||||
def run_delete(args):
|
||||
conn = get_conn(args)
|
||||
path = "/testing/{repo}/{ref}".format(repo=args.repo, ref=args.ref)
|
||||
conn.request("DELETE", path)
|
||||
response = conn.getresponse()
|
||||
if response.status != 200:
|
||||
print(response.read(), file=sys.stderr)
|
||||
print("Failed: status={}".format(response.status), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("Usage: oci-registry-client.py [add|remove] ARGS", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--url", required=True)
|
||||
|
||||
subparsers = parser.add_subparsers()
|
||||
subparsers.required = True
|
||||
|
||||
add_parser = subparsers.add_parser("add")
|
||||
add_parser.add_argument("repo")
|
||||
add_parser.add_argument("tag")
|
||||
add_parser.add_argument("oci_dir")
|
||||
add_parser.add_argument("--detach-icons", action="store_true", default=False)
|
||||
add_parser.set_defaults(func=run_add)
|
||||
|
||||
delete_parser = subparsers.add_parser("delete")
|
||||
delete_parser.add_argument("repo")
|
||||
delete_parser.add_argument("ref")
|
||||
delete_parser.set_defaults(func=run_delete)
|
||||
|
||||
args = parser.parse_args()
|
||||
args.func(args)
|
||||
|
||||
@ -29,7 +29,7 @@ echo "1..14"
|
||||
|
||||
httpd oci-registry-server.py .
|
||||
port=$(cat httpd-port)
|
||||
client="python3 $test_srcdir/oci-registry-client.py http://127.0.0.1:$port"
|
||||
client="python3 $test_srcdir/oci-registry-client.py --url=http://127.0.0.1:$port"
|
||||
|
||||
setup_repo_no_add oci
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user