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

Added "put --profile" and fixed bugs with --meta and --acl

parent 0ed8356c
"""
Upload files to an archive.
Create or modify an archive.
You can also create new archives and set ACL entries or metadata attributes with this
command. It works a bit as a swiss army knife for simple archive creation or
manipulation. For everything not covered here, there are more specialized commands
available.
Upload files and change other aspects of an archive, optionally creating it first.
Existing remote files are not overwritten by default to prevent accidental data
loss. The command will fail if there are any file name conflicts. To change that,
......@@ -85,14 +82,10 @@ def register(subparsers):
" files. (e.g. ./path/to/file.txt would be uploaded as /file.txt)",
)
# parser.add_argument("--tus", action="store_true",
# help="Upload large files via tus.io and retry on connection"
# " errors (needs server support)")
parser.add_argument(
"--meta",
metavar="KEY=VAL",
type=KvArgType,
type=KvArgType("="),
action="append",
help="Set archive metadata attributes. An empty value removes the attribute."
" Can be repeated to set multiple values for the same attribute.",
......@@ -100,12 +93,15 @@ def register(subparsers):
parser.add_argument(
"--acl",
metavar="SUBJECT=ALLOW",
type=KvArgType,
type=KvArgType("="),
action="append",
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.",
)
parser.add_argument(
"--profile", metavar="NAME", help="Change archive profile.",
)
parser.add_argument(
"-n",
......@@ -118,7 +114,7 @@ def register(subparsers):
)
parser.add_argument("ARCHIVE", help="Archive ID, or 'new' to create a new archive")
parser.add_argument("PATH", nargs="+", help="Files or directories to upload")
parser.add_argument("PATH", nargs="*", help="Files or directories to upload.")
parser.set_defaults(main=command)
......@@ -199,7 +195,7 @@ def command(ctx, args): # noqa: C901
if archive == "new":
if not dryrun:
archive = client.create_archive(vault)["id"]
ctx.print("{}Created new archive: ", dryrun, archive)
ctx.print("{}Created new archive: {}", dryrun, archive)
created = True
elif not client.exists(vault, archive):
raise CliError("Archive does not exist: {}".format(archive))
......@@ -225,7 +221,6 @@ def command(ctx, args): # noqa: C901
msg += "Enable --force, --update or --skip and try again."
raise CliError(msg)
# Update archive metadata
if meta:
ctx.print("{}Updating archive metadata ...", dryrun)
form = FormUpdate()
......@@ -234,7 +229,6 @@ def command(ctx, args): # noqa: C901
if not dryrun:
client.update_archive(vault, archive, form=form)
# Update archive ACLs
if acl:
ctx.print("{}Updating archive ACL ...", dryrun)
form = FormUpdate()
......@@ -243,6 +237,13 @@ def command(ctx, args): # noqa: C901
if not dryrun:
client.update_archive(vault, archive, form=form)
if args.profile:
ctx.print("{}Updating archive profile ...", dryrun)
form = FormUpdate()
form.profile(args.profile or "default")
if not dryrun:
client.update_archive(vault, archive, form=form)
# Early exit if we do not have any files to upload
if not uploads:
ctx.print("{}Done!", dryrun)
......
......@@ -180,6 +180,19 @@ class FormUpdate:
return self
def profile(self, name):
"""
Set archive profile to a new value.
:param name: Profile name.
:return: self
"""
self._rm("profile")
self.fields.append(("profile", name))
return self
class ApiError(Exception):
def __init__(self, rs):
......
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