Ejemplo n.º 1
0
    def handle(self, url, name, type, method, console=sys.stdout, **options):
        user = options.get('user')
        owner = get_valid_user(user)
        register_layers = options.get('registerlayers')
        username = options.get('username')
        password = options.get('password')
        perm_spec = options.get('permspec')

        register_service = True

        # First Check if this service already exists based on the URL
        base_url = url
        try:
            service = Service.objects.get(base_url=base_url)
        except Service.DoesNotExist:
            service = None
        if service is not None:
            print "This is an existing Service"
            register_service = False
            # Then Check that the name is Unique
        try:
            service = Service.objects.get(name=name)
        except Service.DoesNotExist:
            service = None
        if service is not None:
            print "This is an existing service using this name.\nPlease specify a different name."
        if register_service:
            if method == 'C':
                response = _register_cascaded_service(type, url, name, username, password, owner=owner, verbosity=True)
            elif method == 'I':
                response = _register_indexed_service(type, url, name, username, password, owner=owner, verbosity=True)
            elif method == 'H':
                response = _register_harvested_service(url, name, username, password, owner=owner, verbosity=True)
            elif method == 'X':
                print 'Not Implemented (Yet)'
            elif method == 'L':
                print 'Local Services not configurable via API'
            else:
                print 'Invalid method'

            json_response = json.loads(response.content)
            if "id" in json_response:
                print "Service created with id of %d" % json_response["id"]
                service = Service.objects.get(id=json_response["id"])
            else:
                print "Something went wrong: %s" % response.content
                return

            print service.id
            print register_layers

        if service and register_layers:
            layers=[]
            for layer in service.servicelayer_set.all():
                layers.append(layer.typename)
            if service.method == 'C':
                response = _register_cascaded_layers(user, service, layers, perm_spec)
            elif service.method == 'I':
                response = _register_indexed_layers(user, service, layers, perm_spec)
            elif service.method == 'X':
                print 'Not Implemented (Yet)'
            elif service.method == 'L':
                print 'Local Services not configurable via API'
            else:
                print('Invalid Service Type')

        print response.content