mirror of
https://github.com/flatpak/flatpak.git
synced 2026-01-26 14:13:26 +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
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import http.client
|
import http.client
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
|
|
||||||
def get_conn(url):
|
def get_conn(args):
|
||||||
parsed = urllib.parse.urlparse(url)
|
parsed = urllib.parse.urlparse(args.url)
|
||||||
return http.client.HTTPConnection(host=parsed.hostname, port=parsed.port)
|
return http.client.HTTPConnection(host=parsed.hostname, port=parsed.port)
|
||||||
|
|
||||||
|
|
||||||
if sys.argv[2] == 'add':
|
def run_add(args):
|
||||||
detach_icons = '--detach-icons' in sys.argv
|
params = {"d": args.oci_dir}
|
||||||
if detach_icons:
|
if args.detach_icons:
|
||||||
sys.argv.remove('--detach-icons')
|
params["detach-icons"] = "1"
|
||||||
params = {'d': sys.argv[5]}
|
|
||||||
if detach_icons:
|
|
||||||
params['detach-icons'] = 1
|
|
||||||
query = urllib.parse.urlencode(params)
|
query = urllib.parse.urlencode(params)
|
||||||
conn = get_conn(sys.argv[1])
|
conn = get_conn(args)
|
||||||
path = "/testing/{repo}/{tag}?{query}".format(repo=sys.argv[3],
|
path = "/testing/{repo}/{tag}?{query}".format(
|
||||||
tag=sys.argv[4],
|
repo=args.repo, tag=args.tag, query=query
|
||||||
query=query)
|
)
|
||||||
conn.request("POST", path)
|
conn.request("POST", path)
|
||||||
response = conn.getresponse()
|
response = conn.getresponse()
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
print(response.read(), file=sys.stderr)
|
print(response.read(), file=sys.stderr)
|
||||||
print("Failed: status={}".format(response.status), file=sys.stderr)
|
print("Failed: status={}".format(response.status), file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif sys.argv[2] == 'delete':
|
|
||||||
conn = get_conn(sys.argv[1])
|
|
||||||
path = "/testing/{repo}/{ref}".format(repo=sys.argv[3],
|
def run_delete(args):
|
||||||
ref=sys.argv[4])
|
conn = get_conn(args)
|
||||||
|
path = "/testing/{repo}/{ref}".format(repo=args.repo, ref=args.ref)
|
||||||
conn.request("DELETE", path)
|
conn.request("DELETE", path)
|
||||||
response = conn.getresponse()
|
response = conn.getresponse()
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
print(response.read(), file=sys.stderr)
|
print(response.read(), file=sys.stderr)
|
||||||
print("Failed: status={}".format(response.status), file=sys.stderr)
|
print("Failed: status={}".format(response.status), file=sys.stderr)
|
||||||
sys.exit(1)
|
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 .
|
httpd oci-registry-server.py .
|
||||||
port=$(cat httpd-port)
|
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
|
setup_repo_no_add oci
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user