Gitlab Community Edition Instance

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 Upload files and change other aspects of an archive, optionally creating it first.
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.
Existing remote files are not overwritten by default to prevent accidental data 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, loss. The command will fail if there are any file name conflicts. To change that,
...@@ -85,14 +82,10 @@ def register(subparsers): ...@@ -85,14 +82,10 @@ def register(subparsers):
" files. (e.g. ./path/to/file.txt would be uploaded as /file.txt)", " 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( parser.add_argument(
"--meta", "--meta",
metavar="KEY=VAL", metavar="KEY=VAL",
type=KvArgType, type=KvArgType("="),
action="append", action="append",
help="Set archive metadata attributes. An empty value removes the attribute." help="Set archive metadata attributes. An empty value removes the attribute."
" Can be repeated to set multiple values for the same attribute.", " Can be repeated to set multiple values for the same attribute.",
...@@ -100,12 +93,15 @@ def register(subparsers): ...@@ -100,12 +93,15 @@ def register(subparsers):
parser.add_argument( parser.add_argument(
"--acl", "--acl",
metavar="SUBJECT=ALLOW", metavar="SUBJECT=ALLOW",
type=KvArgType, type=KvArgType("="),
action="append", action="append",
help="Set archive level permissions for a subject. ALLOW can be a " help="Set archive level permissions for a subject. ALLOW can be a "
"comma-separated list of permission or permission-set names. " "comma-separated list of permission or permission-set names. "
"Leave the ALLOW part empty to revoke all permissions for a subject.", "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( parser.add_argument(
"-n", "-n",
...@@ -118,7 +114,7 @@ def register(subparsers): ...@@ -118,7 +114,7 @@ def register(subparsers):
) )
parser.add_argument("ARCHIVE", help="Archive ID, or 'new' to create a new archive") 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) parser.set_defaults(main=command)
...@@ -199,7 +195,7 @@ def command(ctx, args): # noqa: C901 ...@@ -199,7 +195,7 @@ def command(ctx, args): # noqa: C901
if archive == "new": if archive == "new":
if not dryrun: if not dryrun:
archive = client.create_archive(vault)["id"] archive = client.create_archive(vault)["id"]
ctx.print("{}Created new archive: ", dryrun, archive) ctx.print("{}Created new archive: {}", dryrun, archive)
created = True created = True
elif not client.exists(vault, archive): elif not client.exists(vault, archive):
raise CliError("Archive does not exist: {}".format(archive)) raise CliError("Archive does not exist: {}".format(archive))
...@@ -225,7 +221,6 @@ def command(ctx, args): # noqa: C901 ...@@ -225,7 +221,6 @@ def command(ctx, args): # noqa: C901
msg += "Enable --force, --update or --skip and try again." msg += "Enable --force, --update or --skip and try again."
raise CliError(msg) raise CliError(msg)
# Update archive metadata
if meta: if meta:
ctx.print("{}Updating archive metadata ...", dryrun) ctx.print("{}Updating archive metadata ...", dryrun)
form = FormUpdate() form = FormUpdate()
...@@ -234,7 +229,6 @@ def command(ctx, args): # noqa: C901 ...@@ -234,7 +229,6 @@ def command(ctx, args): # noqa: C901
if not dryrun: if not dryrun:
client.update_archive(vault, archive, form=form) client.update_archive(vault, archive, form=form)
# Update archive ACLs
if acl: if acl:
ctx.print("{}Updating archive ACL ...", dryrun) ctx.print("{}Updating archive ACL ...", dryrun)
form = FormUpdate() form = FormUpdate()
...@@ -243,6 +237,13 @@ def command(ctx, args): # noqa: C901 ...@@ -243,6 +237,13 @@ def command(ctx, args): # noqa: C901
if not dryrun: if not dryrun:
client.update_archive(vault, archive, form=form) 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 # Early exit if we do not have any files to upload
if not uploads: if not uploads:
ctx.print("{}Done!", dryrun) ctx.print("{}Done!", dryrun)
......
...@@ -180,6 +180,19 @@ class FormUpdate: ...@@ -180,6 +180,19 @@ class FormUpdate:
return self 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): class ApiError(Exception):
def __init__(self, rs): def __init__(self, rs):
......
Supports Markdown
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