diff sat_frontends/jp/cmd_file.py @ 3325:7ebda4b54170

jp (file/share): added commands to manage affiliations and configuration + documentation
author Goffi <goffi@goffi.org>
date Sat, 01 Aug 2020 16:25:50 +0200
parents 559a625a236b
children 19bc03743aeb
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_file.py	Sat Aug 01 16:24:03 2020 +0200
+++ b/sat_frontends/jp/cmd_file.py	Sat Aug 01 16:25:50 2020 +0200
@@ -582,6 +582,221 @@
             await self.gotId(upload_data, file_)
 
 
+class ShareAffiliationsSet(base.CommandBase):
+
+    def __init__(self, host):
+        super(ShareAffiliationsSet, self).__init__(
+            host,
+            "set",
+            use_output=C.OUTPUT_DICT,
+            help=_("set affiliations for a shared file/directory"),
+        )
+
+    def add_parser_options(self):
+        self.parser.add_argument(
+            "-N",
+            "--namespace",
+            default="",
+            help=_("namespace of the repository"),
+        )
+        self.parser.add_argument(
+            "-P",
+            "--path",
+            default="",
+            help=_("path to the repository"),
+        )
+        self.parser.add_argument(
+            "-a",
+            "--affiliation",
+            dest="affiliations",
+            metavar=("JID", "AFFILIATION"),
+            required=True,
+            action="append",
+            nargs=2,
+            help=_("entity/affiliation couple(s)"),
+        )
+        self.parser.add_argument(
+            "jid",
+            help=_("jid of file sharing entity"),
+        )
+
+    async def start(self):
+        affiliations = dict(self.args.affiliations)
+        try:
+            affiliations = await self.host.bridge.FISAffiliationsSet(
+                self.args.jid,
+                self.args.namespace,
+                self.args.path,
+                affiliations,
+                self.profile,
+            )
+        except Exception as e:
+            self.disp(f"can't set affiliations: {e}", error=True)
+            self.host.quit(C.EXIT_BRIDGE_ERRBACK)
+        else:
+            self.host.quit()
+
+
+class ShareAffiliationsGet(base.CommandBase):
+    def __init__(self, host):
+        super(ShareAffiliationsGet, self).__init__(
+            host,
+            "get",
+            use_output=C.OUTPUT_DICT,
+            help=_("retrieve affiliations of a shared file/directory"),
+        )
+
+    def add_parser_options(self):
+        self.parser.add_argument(
+            "-N",
+            "--namespace",
+            default="",
+            help=_("namespace of the repository"),
+        )
+        self.parser.add_argument(
+            "-P",
+            "--path",
+            default="",
+            help=_("path to the repository"),
+        )
+        self.parser.add_argument(
+            "jid",
+            help=_("jid of sharing entity"),
+        )
+
+    async def start(self):
+        try:
+            affiliations = await self.host.bridge.FISAffiliationsGet(
+                self.args.jid,
+                self.args.namespace,
+                self.args.path,
+                self.profile,
+            )
+        except Exception as e:
+            self.disp(f"can't get affiliations: {e}", error=True)
+            self.host.quit(C.EXIT_BRIDGE_ERRBACK)
+        else:
+            await self.output(affiliations)
+            self.host.quit()
+
+
+class ShareAffiliations(base.CommandBase):
+    subcommands = (ShareAffiliationsGet, ShareAffiliationsSet)
+
+    def __init__(self, host):
+        super(ShareAffiliations, self).__init__(
+            host, "affiliations", use_profile=False, help=_("affiliations management")
+        )
+
+
+class ShareConfigurationSet(base.CommandBase):
+
+    def __init__(self, host):
+        super(ShareConfigurationSet, self).__init__(
+            host,
+            "set",
+            use_output=C.OUTPUT_DICT,
+            help=_("set configuration for a shared file/directory"),
+        )
+
+    def add_parser_options(self):
+        self.parser.add_argument(
+            "-N",
+            "--namespace",
+            default="",
+            help=_("namespace of the repository"),
+        )
+        self.parser.add_argument(
+            "-P",
+            "--path",
+            default="",
+            help=_("path to the repository"),
+        )
+        self.parser.add_argument(
+            "-f",
+            "--field",
+            action="append",
+            nargs=2,
+            dest="fields",
+            required=True,
+            metavar=("KEY", "VALUE"),
+            help=_("configuration field to set (required)"),
+        )
+        self.parser.add_argument(
+            "jid",
+            help=_("jid of file sharing entity"),
+        )
+
+    async def start(self):
+        configuration = dict(self.args.fields)
+        try:
+            configuration = await self.host.bridge.FISConfigurationSet(
+                self.args.jid,
+                self.args.namespace,
+                self.args.path,
+                configuration,
+                self.profile,
+            )
+        except Exception as e:
+            self.disp(f"can't set configuration: {e}", error=True)
+            self.host.quit(C.EXIT_BRIDGE_ERRBACK)
+        else:
+            self.host.quit()
+
+
+class ShareConfigurationGet(base.CommandBase):
+    def __init__(self, host):
+        super(ShareConfigurationGet, self).__init__(
+            host,
+            "get",
+            use_output=C.OUTPUT_DICT,
+            help=_("retrieve configuration of a shared file/directory"),
+        )
+
+    def add_parser_options(self):
+        self.parser.add_argument(
+            "-N",
+            "--namespace",
+            default="",
+            help=_("namespace of the repository"),
+        )
+        self.parser.add_argument(
+            "-P",
+            "--path",
+            default="",
+            help=_("path to the repository"),
+        )
+        self.parser.add_argument(
+            "jid",
+            help=_("jid of sharing entity"),
+        )
+
+    async def start(self):
+        try:
+            configuration = await self.host.bridge.FISConfigurationGet(
+                self.args.jid,
+                self.args.namespace,
+                self.args.path,
+                self.profile,
+            )
+        except Exception as e:
+            self.disp(f"can't get configuration: {e}", error=True)
+            self.host.quit(C.EXIT_BRIDGE_ERRBACK)
+        else:
+            await self.output(configuration)
+            self.host.quit()
+
+
+class ShareConfiguration(base.CommandBase):
+    subcommands = (ShareConfigurationGet, ShareConfigurationSet)
+
+    def __init__(self, host):
+        super(ShareConfiguration, self).__init__(
+            host, "configuration", use_profile=False,
+            help=_("file sharing node configuration")
+        )
+
+
 class ShareList(base.CommandBase):
     def __init__(self, host):
         extra_outputs = {"default": self.default_output}
@@ -804,7 +1019,8 @@
 
 
 class Share(base.CommandBase):
-    subcommands = (ShareList, SharePath, ShareInvite)
+    subcommands = (
+        ShareList, SharePath, ShareInvite, ShareAffiliations, ShareConfiguration)
 
     def __init__(self, host):
         super(Share, self).__init__(