arches_extensions.management.commands.extension

  1from django.core.management.base import BaseCommand
  2
  3from arches_extensions.utils import ArchesHelpTextFormatter, ArchesCLIStyles
  4from arches_extensions.managers import ExtensionManager
  5
  6_s = ArchesCLIStyles()
  7
  8class Command(BaseCommand):
  9    """
 10Use this command to manage extensions within Arches.
 11
 12Usage:
 13
 14    python manage.py extension [operation] [extension_type] [-s/--source] [-n/--name] [--overwrite]
 15
 16Operations:
 17
 18- `list`
 19    - Use `list` for quick inspection of the database. If you need to supply a `--name` 
 20for an operation, use the value that is printed by the `list` operation.
 21- `register`
 22    - When you `register` an extension a new database object for that extension instance is 
 23created. Add `--overwrite` 
 24update an existing instance based on the primary key of the extension defined in 
 25`--source`. Note: the name of the primary key field is different for every extension, 
 26but generally is something like "widgetid".
 27- `unregister`
 28    - Running `unregister` will delete the specified instance from the database.
 29- `activate`
 30    - The `activate` and `deactivate` operations are only valid operations for a few different
 31extension types. These actions alter an instance's `config['show']` value, but do not
 32create or delete the instance. A deactivated extension will be hidden from the user
 33interface but remain in the database.
 34- `deactivate`
 35    See above.
 36
 37Extension types:
 38
 39- `card-component`
 40- `datatype`
 41- `etl-module`
 42- `function`
 43- `plugin` → use this for "workflows"
 44- `report`
 45- `search-filter`
 46- `widget`
 47
 48
 49    """
 50
 51    def __init__(self, *args, **kwargs):
 52        """ @private """
 53        self.help = self.__doc__
 54
 55    def add_arguments(self, parser):
 56        # """@private"""
 57        parser.formatter_class = ArchesHelpTextFormatter
 58        parser.add_argument(
 59            "operation",
 60            choices=[
 61                "list",
 62                "register",
 63                "unregister",
 64                "activate",
 65                "deactivate",
 66            ],
 67            help=f"""OPERATION
 68            {_s.req('list')}: List registered extensions of the specified type. The {_s.opt('name')} of each extension is printed.
 69            {_s.req('register')}: Register extension from source file (provide {_s.opt('-s/--source')}).
 70            {_s.req('unregister')}: Unregister the specified extension (provide {_s.opt('-n/--name')}).
 71            {_s.req('activate')}: Activate this extension (not available for all extension types) (provide {_s.opt('-n/--name')}).
 72            {_s.req('deactivate')}: Deactivate this extension but don't unregister it (not available for all extension types, experimental) (provide {_s.opt('-n/--name')}).
 73            """
 74        )
 75        parser.add_argument(
 76            "extension_type",
 77            choices=[
 78                "card-component",
 79                "datatype",
 80                "etl-module",
 81                "function",
 82                "plugin",
 83                "report",
 84                "search-filter",
 85                "widget",
 86            ],
 87            help="""EXTENSION TYPE
 88            Specify what type of extension you are managing.
 89            """
 90        )
 91        parser.add_argument(
 92            "-s", "--source",
 93            help=f"Use with {_s.req('register')} to provide a JSON or .py file when registering an extension.",
 94        )
 95        parser.add_argument(
 96            "-n", "--name",
 97            help=f"Use with {_s.req('unregister')} for the name of the extension to remove."
 98        )
 99        parser.add_argument(
100            "--overwrite",
101            action="store_true",
102            help=f"Use with {_s.req('register')} to overwrite an existing extension with the provided source definition.",
103        )
104
105    def handle(self, *args, **options):
106
107        ex = options["extension_type"]
108        manager = ExtensionManager(extension_type=ex)
109
110        # the list operation only makes sense in the context of the CLI,
111        # so all code sits here, not in the manager.
112        if options["operation"] == "list":
113            manager.print_list()
114
115        if options["operation"] == "register":
116            print(f"Register {ex}: {options['source']} (overwrite = {options['overwrite']}")
117            manager.register(options["source"], overwrite=options['overwrite'])
118
119        if options["operation"] == "unregister":
120            print(f"Unregister {ex}: {options['name']}")
121            manager.unregister(options["name"])
122
123        if options["operation"] == "activate":
124            print(f"Activate {ex}: {options['name']}")
125            manager.set_active(name=options["name"])
126
127        if options["operation"] == "deactivate":
128            print(_s.warn("Warning: Deactivating core Arches extensions, like the Advanced "\
129            "search filter, may cause unintended consequences."))
130            print(f"Deactivate {ex}: {options['name']}")
131            manager.set_active(name=options["name"], active=False)
class Command(django.core.management.base.BaseCommand):
  9class Command(BaseCommand):
 10    """
 11Use this command to manage extensions within Arches.
 12
 13Usage:
 14
 15    python manage.py extension [operation] [extension_type] [-s/--source] [-n/--name] [--overwrite]
 16
 17Operations:
 18
 19- `list`
 20    - Use `list` for quick inspection of the database. If you need to supply a `--name` 
 21for an operation, use the value that is printed by the `list` operation.
 22- `register`
 23    - When you `register` an extension a new database object for that extension instance is 
 24created. Add `--overwrite` 
 25update an existing instance based on the primary key of the extension defined in 
 26`--source`. Note: the name of the primary key field is different for every extension, 
 27but generally is something like "widgetid".
 28- `unregister`
 29    - Running `unregister` will delete the specified instance from the database.
 30- `activate`
 31    - The `activate` and `deactivate` operations are only valid operations for a few different
 32extension types. These actions alter an instance's `config['show']` value, but do not
 33create or delete the instance. A deactivated extension will be hidden from the user
 34interface but remain in the database.
 35- `deactivate`
 36    See above.
 37
 38Extension types:
 39
 40- `card-component`
 41- `datatype`
 42- `etl-module`
 43- `function`
 44- `plugin` → use this for "workflows"
 45- `report`
 46- `search-filter`
 47- `widget`
 48
 49
 50    """
 51
 52    def __init__(self, *args, **kwargs):
 53        """ @private """
 54        self.help = self.__doc__
 55
 56    def add_arguments(self, parser):
 57        # """@private"""
 58        parser.formatter_class = ArchesHelpTextFormatter
 59        parser.add_argument(
 60            "operation",
 61            choices=[
 62                "list",
 63                "register",
 64                "unregister",
 65                "activate",
 66                "deactivate",
 67            ],
 68            help=f"""OPERATION
 69            {_s.req('list')}: List registered extensions of the specified type. The {_s.opt('name')} of each extension is printed.
 70            {_s.req('register')}: Register extension from source file (provide {_s.opt('-s/--source')}).
 71            {_s.req('unregister')}: Unregister the specified extension (provide {_s.opt('-n/--name')}).
 72            {_s.req('activate')}: Activate this extension (not available for all extension types) (provide {_s.opt('-n/--name')}).
 73            {_s.req('deactivate')}: Deactivate this extension but don't unregister it (not available for all extension types, experimental) (provide {_s.opt('-n/--name')}).
 74            """
 75        )
 76        parser.add_argument(
 77            "extension_type",
 78            choices=[
 79                "card-component",
 80                "datatype",
 81                "etl-module",
 82                "function",
 83                "plugin",
 84                "report",
 85                "search-filter",
 86                "widget",
 87            ],
 88            help="""EXTENSION TYPE
 89            Specify what type of extension you are managing.
 90            """
 91        )
 92        parser.add_argument(
 93            "-s", "--source",
 94            help=f"Use with {_s.req('register')} to provide a JSON or .py file when registering an extension.",
 95        )
 96        parser.add_argument(
 97            "-n", "--name",
 98            help=f"Use with {_s.req('unregister')} for the name of the extension to remove."
 99        )
100        parser.add_argument(
101            "--overwrite",
102            action="store_true",
103            help=f"Use with {_s.req('register')} to overwrite an existing extension with the provided source definition.",
104        )
105
106    def handle(self, *args, **options):
107
108        ex = options["extension_type"]
109        manager = ExtensionManager(extension_type=ex)
110
111        # the list operation only makes sense in the context of the CLI,
112        # so all code sits here, not in the manager.
113        if options["operation"] == "list":
114            manager.print_list()
115
116        if options["operation"] == "register":
117            print(f"Register {ex}: {options['source']} (overwrite = {options['overwrite']}")
118            manager.register(options["source"], overwrite=options['overwrite'])
119
120        if options["operation"] == "unregister":
121            print(f"Unregister {ex}: {options['name']}")
122            manager.unregister(options["name"])
123
124        if options["operation"] == "activate":
125            print(f"Activate {ex}: {options['name']}")
126            manager.set_active(name=options["name"])
127
128        if options["operation"] == "deactivate":
129            print(_s.warn("Warning: Deactivating core Arches extensions, like the Advanced "\
130            "search filter, may cause unintended consequences."))
131            print(f"Deactivate {ex}: {options['name']}")
132            manager.set_active(name=options["name"], active=False)

Use this command to manage extensions within Arches.

Usage:

python manage.py extension [operation] [extension_type] [-s/--source] [-n/--name] [--overwrite]

Operations:

  • list
    • Use list for quick inspection of the database. If you need to supply a --name for an operation, use the value that is printed by the list operation.
  • register
    • When you register an extension a new database object for that extension instance is created. Add --overwrite update an existing instance based on the primary key of the extension defined in --source. Note: the name of the primary key field is different for every extension, but generally is something like "widgetid".
  • unregister
    • Running unregister will delete the specified instance from the database.
  • activate
    • The activate and deactivate operations are only valid operations for a few different extension types. These actions alter an instance's config['show'] value, but do not create or delete the instance. A deactivated extension will be hidden from the user interface but remain in the database.
  • deactivate See above.

Extension types:

  • card-component
  • datatype
  • etl-module
  • function
  • plugin → use this for "workflows"
  • report
  • search-filter
  • widget
help = ''
def add_arguments(self, parser):
 56    def add_arguments(self, parser):
 57        # """@private"""
 58        parser.formatter_class = ArchesHelpTextFormatter
 59        parser.add_argument(
 60            "operation",
 61            choices=[
 62                "list",
 63                "register",
 64                "unregister",
 65                "activate",
 66                "deactivate",
 67            ],
 68            help=f"""OPERATION
 69            {_s.req('list')}: List registered extensions of the specified type. The {_s.opt('name')} of each extension is printed.
 70            {_s.req('register')}: Register extension from source file (provide {_s.opt('-s/--source')}).
 71            {_s.req('unregister')}: Unregister the specified extension (provide {_s.opt('-n/--name')}).
 72            {_s.req('activate')}: Activate this extension (not available for all extension types) (provide {_s.opt('-n/--name')}).
 73            {_s.req('deactivate')}: Deactivate this extension but don't unregister it (not available for all extension types, experimental) (provide {_s.opt('-n/--name')}).
 74            """
 75        )
 76        parser.add_argument(
 77            "extension_type",
 78            choices=[
 79                "card-component",
 80                "datatype",
 81                "etl-module",
 82                "function",
 83                "plugin",
 84                "report",
 85                "search-filter",
 86                "widget",
 87            ],
 88            help="""EXTENSION TYPE
 89            Specify what type of extension you are managing.
 90            """
 91        )
 92        parser.add_argument(
 93            "-s", "--source",
 94            help=f"Use with {_s.req('register')} to provide a JSON or .py file when registering an extension.",
 95        )
 96        parser.add_argument(
 97            "-n", "--name",
 98            help=f"Use with {_s.req('unregister')} for the name of the extension to remove."
 99        )
100        parser.add_argument(
101            "--overwrite",
102            action="store_true",
103            help=f"Use with {_s.req('register')} to overwrite an existing extension with the provided source definition.",
104        )

Entry point for subclassed commands to add custom arguments.

def handle(self, *args, **options):
106    def handle(self, *args, **options):
107
108        ex = options["extension_type"]
109        manager = ExtensionManager(extension_type=ex)
110
111        # the list operation only makes sense in the context of the CLI,
112        # so all code sits here, not in the manager.
113        if options["operation"] == "list":
114            manager.print_list()
115
116        if options["operation"] == "register":
117            print(f"Register {ex}: {options['source']} (overwrite = {options['overwrite']}")
118            manager.register(options["source"], overwrite=options['overwrite'])
119
120        if options["operation"] == "unregister":
121            print(f"Unregister {ex}: {options['name']}")
122            manager.unregister(options["name"])
123
124        if options["operation"] == "activate":
125            print(f"Activate {ex}: {options['name']}")
126            manager.set_active(name=options["name"])
127
128        if options["operation"] == "deactivate":
129            print(_s.warn("Warning: Deactivating core Arches extensions, like the Advanced "\
130            "search filter, may cause unintended consequences."))
131            print(f"Deactivate {ex}: {options['name']}")
132            manager.set_active(name=options["name"], active=False)

The actual logic of the command. Subclasses must implement this method.