Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
3324:b57b5e42e894 | 3325:7ebda4b54170 |
---|---|
578 except Exception as e: | 578 except Exception as e: |
579 self.disp(f"error while trying to upload a file: {e}", error=True) | 579 self.disp(f"error while trying to upload a file: {e}", error=True) |
580 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 580 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
581 else: | 581 else: |
582 await self.gotId(upload_data, file_) | 582 await self.gotId(upload_data, file_) |
583 | |
584 | |
585 class ShareAffiliationsSet(base.CommandBase): | |
586 | |
587 def __init__(self, host): | |
588 super(ShareAffiliationsSet, self).__init__( | |
589 host, | |
590 "set", | |
591 use_output=C.OUTPUT_DICT, | |
592 help=_("set affiliations for a shared file/directory"), | |
593 ) | |
594 | |
595 def add_parser_options(self): | |
596 self.parser.add_argument( | |
597 "-N", | |
598 "--namespace", | |
599 default="", | |
600 help=_("namespace of the repository"), | |
601 ) | |
602 self.parser.add_argument( | |
603 "-P", | |
604 "--path", | |
605 default="", | |
606 help=_("path to the repository"), | |
607 ) | |
608 self.parser.add_argument( | |
609 "-a", | |
610 "--affiliation", | |
611 dest="affiliations", | |
612 metavar=("JID", "AFFILIATION"), | |
613 required=True, | |
614 action="append", | |
615 nargs=2, | |
616 help=_("entity/affiliation couple(s)"), | |
617 ) | |
618 self.parser.add_argument( | |
619 "jid", | |
620 help=_("jid of file sharing entity"), | |
621 ) | |
622 | |
623 async def start(self): | |
624 affiliations = dict(self.args.affiliations) | |
625 try: | |
626 affiliations = await self.host.bridge.FISAffiliationsSet( | |
627 self.args.jid, | |
628 self.args.namespace, | |
629 self.args.path, | |
630 affiliations, | |
631 self.profile, | |
632 ) | |
633 except Exception as e: | |
634 self.disp(f"can't set affiliations: {e}", error=True) | |
635 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
636 else: | |
637 self.host.quit() | |
638 | |
639 | |
640 class ShareAffiliationsGet(base.CommandBase): | |
641 def __init__(self, host): | |
642 super(ShareAffiliationsGet, self).__init__( | |
643 host, | |
644 "get", | |
645 use_output=C.OUTPUT_DICT, | |
646 help=_("retrieve affiliations of a shared file/directory"), | |
647 ) | |
648 | |
649 def add_parser_options(self): | |
650 self.parser.add_argument( | |
651 "-N", | |
652 "--namespace", | |
653 default="", | |
654 help=_("namespace of the repository"), | |
655 ) | |
656 self.parser.add_argument( | |
657 "-P", | |
658 "--path", | |
659 default="", | |
660 help=_("path to the repository"), | |
661 ) | |
662 self.parser.add_argument( | |
663 "jid", | |
664 help=_("jid of sharing entity"), | |
665 ) | |
666 | |
667 async def start(self): | |
668 try: | |
669 affiliations = await self.host.bridge.FISAffiliationsGet( | |
670 self.args.jid, | |
671 self.args.namespace, | |
672 self.args.path, | |
673 self.profile, | |
674 ) | |
675 except Exception as e: | |
676 self.disp(f"can't get affiliations: {e}", error=True) | |
677 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
678 else: | |
679 await self.output(affiliations) | |
680 self.host.quit() | |
681 | |
682 | |
683 class ShareAffiliations(base.CommandBase): | |
684 subcommands = (ShareAffiliationsGet, ShareAffiliationsSet) | |
685 | |
686 def __init__(self, host): | |
687 super(ShareAffiliations, self).__init__( | |
688 host, "affiliations", use_profile=False, help=_("affiliations management") | |
689 ) | |
690 | |
691 | |
692 class ShareConfigurationSet(base.CommandBase): | |
693 | |
694 def __init__(self, host): | |
695 super(ShareConfigurationSet, self).__init__( | |
696 host, | |
697 "set", | |
698 use_output=C.OUTPUT_DICT, | |
699 help=_("set configuration for a shared file/directory"), | |
700 ) | |
701 | |
702 def add_parser_options(self): | |
703 self.parser.add_argument( | |
704 "-N", | |
705 "--namespace", | |
706 default="", | |
707 help=_("namespace of the repository"), | |
708 ) | |
709 self.parser.add_argument( | |
710 "-P", | |
711 "--path", | |
712 default="", | |
713 help=_("path to the repository"), | |
714 ) | |
715 self.parser.add_argument( | |
716 "-f", | |
717 "--field", | |
718 action="append", | |
719 nargs=2, | |
720 dest="fields", | |
721 required=True, | |
722 metavar=("KEY", "VALUE"), | |
723 help=_("configuration field to set (required)"), | |
724 ) | |
725 self.parser.add_argument( | |
726 "jid", | |
727 help=_("jid of file sharing entity"), | |
728 ) | |
729 | |
730 async def start(self): | |
731 configuration = dict(self.args.fields) | |
732 try: | |
733 configuration = await self.host.bridge.FISConfigurationSet( | |
734 self.args.jid, | |
735 self.args.namespace, | |
736 self.args.path, | |
737 configuration, | |
738 self.profile, | |
739 ) | |
740 except Exception as e: | |
741 self.disp(f"can't set configuration: {e}", error=True) | |
742 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
743 else: | |
744 self.host.quit() | |
745 | |
746 | |
747 class ShareConfigurationGet(base.CommandBase): | |
748 def __init__(self, host): | |
749 super(ShareConfigurationGet, self).__init__( | |
750 host, | |
751 "get", | |
752 use_output=C.OUTPUT_DICT, | |
753 help=_("retrieve configuration of a shared file/directory"), | |
754 ) | |
755 | |
756 def add_parser_options(self): | |
757 self.parser.add_argument( | |
758 "-N", | |
759 "--namespace", | |
760 default="", | |
761 help=_("namespace of the repository"), | |
762 ) | |
763 self.parser.add_argument( | |
764 "-P", | |
765 "--path", | |
766 default="", | |
767 help=_("path to the repository"), | |
768 ) | |
769 self.parser.add_argument( | |
770 "jid", | |
771 help=_("jid of sharing entity"), | |
772 ) | |
773 | |
774 async def start(self): | |
775 try: | |
776 configuration = await self.host.bridge.FISConfigurationGet( | |
777 self.args.jid, | |
778 self.args.namespace, | |
779 self.args.path, | |
780 self.profile, | |
781 ) | |
782 except Exception as e: | |
783 self.disp(f"can't get configuration: {e}", error=True) | |
784 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
785 else: | |
786 await self.output(configuration) | |
787 self.host.quit() | |
788 | |
789 | |
790 class ShareConfiguration(base.CommandBase): | |
791 subcommands = (ShareConfigurationGet, ShareConfigurationSet) | |
792 | |
793 def __init__(self, host): | |
794 super(ShareConfiguration, self).__init__( | |
795 host, "configuration", use_profile=False, | |
796 help=_("file sharing node configuration") | |
797 ) | |
583 | 798 |
584 | 799 |
585 class ShareList(base.CommandBase): | 800 class ShareList(base.CommandBase): |
586 def __init__(self, host): | 801 def __init__(self, host): |
587 extra_outputs = {"default": self.default_output} | 802 extra_outputs = {"default": self.default_output} |
802 ) | 1017 ) |
803 self.host.quit() | 1018 self.host.quit() |
804 | 1019 |
805 | 1020 |
806 class Share(base.CommandBase): | 1021 class Share(base.CommandBase): |
807 subcommands = (ShareList, SharePath, ShareInvite) | 1022 subcommands = ( |
1023 ShareList, SharePath, ShareInvite, ShareAffiliations, ShareConfiguration) | |
808 | 1024 |
809 def __init__(self, host): | 1025 def __init__(self, host): |
810 super(Share, self).__init__( | 1026 super(Share, self).__init__( |
811 host, "share", use_profile=False, help=_("files sharing management") | 1027 host, "share", use_profile=False, help=_("files sharing management") |
812 ) | 1028 ) |