arches_extensions.management.commands.resource
1from django.core.management.base import BaseCommand 2 3from arches.app.models.models import ResourceInstance 4from arches.app.models.graph import Graph 5 6from arches_extensions.utils import get_graph 7 8class Command(BaseCommand): 9 """ 10 .. warning:: 11 This command is a work-in-progress 12 """ 13 14 def __init__(self, *args, **kwargs): 15 self.help = self.__doc__ 16 17 def add_arguments(self, parser): 18 19 parser.add_argument( 20 "operation", 21 choices=[ 22 "import", 23 "export", 24 "inspect", 25 ] 26 ) 27 28 parser.add_argument( 29 "-s", "--source", 30 action="store", 31 help="Path to upload file.", 32 ) 33 34 parser.add_argument( 35 "-g", "--graph", 36 action="store", 37 help="Graph name" 38 ) 39 40 parser.add_argument( 41 "--overwrite", 42 action="store_true", 43 help="Overwrite existing extension that matches the input extension name.", 44 ) 45 46 def handle(self, *args, **options): 47 48 if options["operation"] == "import": 49 self.register(options["extension_type"], options["source"], overwrite=options['overwrite']) 50 51 if options["operation"] == "export": 52 self.unregister(options["extension_type"], name=options["name"]) 53 54 if options["operation"] == "inspect": 55 56 if options['graph']: 57 graph = get_graph(options['graph']) 58 if graph is None: 59 print("Invalid graph") 60 return 61 graphs = [graph] 62 else: 63 graphs = Graph.objects.filter(isresource=True).exclude(name="Arches System Settings") 64 self.inspect(graphs) 65 66 def import_resources(self, source): 67 pass 68 69 def inspect(self, graphs=[]): 70 71 for graph in graphs: 72 print(graph.name) 73 res = ResourceInstance.objects.filter(graph=graph) 74 print(res.count())
class
Command(django.core.management.base.BaseCommand):
10class Command(BaseCommand): 11 """ 12 .. warning:: 13 This command is a work-in-progress 14 """ 15 16 def __init__(self, *args, **kwargs): 17 self.help = self.__doc__ 18 19 def add_arguments(self, parser): 20 21 parser.add_argument( 22 "operation", 23 choices=[ 24 "import", 25 "export", 26 "inspect", 27 ] 28 ) 29 30 parser.add_argument( 31 "-s", "--source", 32 action="store", 33 help="Path to upload file.", 34 ) 35 36 parser.add_argument( 37 "-g", "--graph", 38 action="store", 39 help="Graph name" 40 ) 41 42 parser.add_argument( 43 "--overwrite", 44 action="store_true", 45 help="Overwrite existing extension that matches the input extension name.", 46 ) 47 48 def handle(self, *args, **options): 49 50 if options["operation"] == "import": 51 self.register(options["extension_type"], options["source"], overwrite=options['overwrite']) 52 53 if options["operation"] == "export": 54 self.unregister(options["extension_type"], name=options["name"]) 55 56 if options["operation"] == "inspect": 57 58 if options['graph']: 59 graph = get_graph(options['graph']) 60 if graph is None: 61 print("Invalid graph") 62 return 63 graphs = [graph] 64 else: 65 graphs = Graph.objects.filter(isresource=True).exclude(name="Arches System Settings") 66 self.inspect(graphs) 67 68 def import_resources(self, source): 69 pass 70 71 def inspect(self, graphs=[]): 72 73 for graph in graphs: 74 print(graph.name) 75 res = ResourceInstance.objects.filter(graph=graph) 76 print(res.count())
This command is a work-in-progress
def
add_arguments(self, parser):
19 def add_arguments(self, parser): 20 21 parser.add_argument( 22 "operation", 23 choices=[ 24 "import", 25 "export", 26 "inspect", 27 ] 28 ) 29 30 parser.add_argument( 31 "-s", "--source", 32 action="store", 33 help="Path to upload file.", 34 ) 35 36 parser.add_argument( 37 "-g", "--graph", 38 action="store", 39 help="Graph name" 40 ) 41 42 parser.add_argument( 43 "--overwrite", 44 action="store_true", 45 help="Overwrite existing extension that matches the input extension name.", 46 )
Entry point for subclassed commands to add custom arguments.
def
handle(self, *args, **options):
48 def handle(self, *args, **options): 49 50 if options["operation"] == "import": 51 self.register(options["extension_type"], options["source"], overwrite=options['overwrite']) 52 53 if options["operation"] == "export": 54 self.unregister(options["extension_type"], name=options["name"]) 55 56 if options["operation"] == "inspect": 57 58 if options['graph']: 59 graph = get_graph(options['graph']) 60 if graph is None: 61 print("Invalid graph") 62 return 63 graphs = [graph] 64 else: 65 graphs = Graph.objects.filter(isresource=True).exclude(name="Arches System Settings") 66 self.inspect(graphs)
The actual logic of the command. Subclasses must implement this method.