Gitlab Community Edition Instance

Commit a0e0fd5e authored by Marcel Hellkamp's avatar Marcel Hellkamp
Browse files

Added 'meta' command.

parent ae066abd
......@@ -367,6 +367,12 @@ class CDStar:
""" Set (replace) the access control list (ACL) for an archive """
return"PUT", vault, archive, params={"acl": ""}, json=acl_info)
def meta_info(self, vault, archive, file=None) -> JsonObject:
""" Get the metadata of an archvie or file. """
if file:
return"GET", vault, archive, file, params={"meta": ""})
return"GET", vault, archive, params={"meta": ""})
def scroll(self, vault, start="", limit=1024) -> JsonObject:
return"GET", vault, params={"scroll": start, "limit": limit})
Show or modify archive or file meta attributes
import json
from tabulate import tabulate
from pycdstar3 import FormUpdate
from pycdstar3.cli._utils import KvArgType
def register(subparsers):
parser = subparsers.add_parser(
"meta", help=__doc__.strip().splitlines()[0], description=__doc__
sub = parser.add_subparsers()
pset = sub.add_parser("set")
pset.add_argument("ARCHIVE", help="Archive ID")
"--file", help="Set metadata of a file instead of the archive.",
help="Set archive level permissions for a subject. ALLOW can be a "
"comma-separated list of permission or permission-set names. Leave the "
"ALLOW part empty to revoke all permissions for a subject.",
pshow = sub.add_parser("show")
pshow.add_argument("ARCHIVE", help="Archive ID")
"--file", help="Get metadata from a file instead of the archive.",
help="Explode permission sets into individual permissions",
pshow.add_argument("--json", action="store_true", help="Print as JSON")
def meta_set(ctx, args):
client = ctx.client
vault = ctx.vault
archive = args.ARCHIVE
file = args.file or None
changes = {}
for name, split, value in args.ATTR:
# TODO: Support += and -= and @ to load from files
if value:
changes.setdefault(name, []).append(value)
update = FormUpdate()
for name, values in changes.items():
update.meta(name, *values, file=file)
ctx.print("Updating meta attribute {}: {}", name, values)
client.update_archive(vault, archive, form=update)
def meta_show(ctx, args):
client = ctx.client
vault = ctx.vault
archive = args.ARCHIVE
file = args.file or None
meta = client.meta_info(vault, archive, file)
if args.json:
print(json.dumps(meta, indent=4))
elif meta:
sorted((k, v) for (k, vs) in meta.items() for v in vs),
headers=["Name", "Value"],
ctx.print("No meta attributes found")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment