Example #1
0
    def post(self):
        if not self.source_provider.can_intra_move(self.destination_provider, self.json['source']['path']):
            resp = yield from tasks.move.adelay({
                'nid': self.json['source']['nid'],
                'path': self.json['source']['path'],
                'provider': self.source_provider.serialized()
            }, {
                'nid': self.json['destination']['nid'],
                'path': self.json['destination']['path'],
                'provider': self.destination_provider.serialized()
            },
                self.callback_url,
                self.auth,
                rename=self.json.get('rename'),
                conflict=self.json.get('conflict', 'replace'),
                start_time=time.time()
            )

            metadata, created = yield from tasks.wait_on_celery(resp)

        else:
            metadata, created = (
                yield from tasks.backgrounded(
                    self.source_provider.move,
                    self.destination_provider,
                    self.json['source']['path'],
                    self.json['destination']['path'],
                    rename=self.json.get('rename'),
                    conflict=self.json.get('conflict', 'replace'),
                )
            )

        if isinstance(metadata, list):
            metadata = [m.serialized() for m in metadata]
        else:
            metadata = metadata.serialized()

        if created:
            self.set_status(201)
        else:
            self.set_status(200)

        self.write(metadata)

        if self.source_provider.can_intra_move(self.destination_provider, self.json['source']['path']):
            self._send_hook('move', metadata)
Example #2
0
    def post(self):
        if not self.source_provider.can_intra_move(self.destination_provider, self.json["source"]["path"]):
            resp = yield from tasks.move.adelay(
                {
                    "nid": self.json["source"]["nid"],
                    "path": self.json["source"]["path"],
                    "provider": self.source_provider.serialized(),
                },
                {
                    "nid": self.json["destination"]["nid"],
                    "path": self.json["destination"]["path"],
                    "provider": self.destination_provider.serialized(),
                },
                self.callback_url,
                self.auth,
                rename=self.json.get("rename"),
                conflict=self.json.get("conflict", "replace"),
                start_time=time.time(),
            )

            metadata, created = yield from tasks.wait_on_celery(resp)

        else:
            metadata, created = (
                yield from tasks.backgrounded(
                    self.source_provider.move,
                    self.destination_provider,
                    self.json["source"]["path"],
                    self.json["destination"]["path"],
                    rename=self.json.get("rename"),
                    conflict=self.json.get("conflict", "replace"),
                )
            )

        metadata = metadata.serialized()

        if created:
            self.set_status(201)
        else:
            self.set_status(200)

        self.write(metadata)

        if self.source_provider.can_intra_move(self.destination_provider, self.json["source"]["path"]):
            self._send_hook("move", metadata)
Example #3
0
    def post(self):
        if not self.source_provider.can_intra_move(
                self.destination_provider, self.json['source']['path']):
            resp = yield from tasks.move.adelay(
                {
                    'nid': self.json['source']['nid'],
                    'path': self.json['source']['path'],
                    'provider': self.source_provider.serialized()
                }, {
                    'nid': self.json['destination']['nid'],
                    'path': self.json['destination']['path'],
                    'provider': self.destination_provider.serialized()
                },
                self.callback_url,
                self.auth,
                rename=self.json.get('rename'),
                conflict=self.json.get('conflict', 'replace'),
                start_time=time.time())

            metadata, created = yield from tasks.wait_on_celery(resp)

        else:
            metadata, created = (yield from tasks.backgrounded(
                self.source_provider.move,
                self.destination_provider,
                self.json['source']['path'],
                self.json['destination']['path'],
                rename=self.json.get('rename'),
                conflict=self.json.get('conflict', 'replace'),
            ))

        metadata = metadata.serialized()

        if created:
            self.set_status(201)
        else:
            self.set_status(200)

        self.write(metadata)

        if self.source_provider.can_intra_move(self.destination_provider,
                                               self.json['source']['path']):
            self._send_hook('move', metadata)
Example #4
0
    def post(self):
        if not self.source_provider.can_intra_copy(self.destination_provider, self.json['source']['path']):
            result = yield from tasks.copy.adelay({
                'nid': self.json['source']['nid'],
                'path': self.json['source']['path'],
                'provider': self.source_provider.serialized()
            }, {
                'nid': self.json['destination']['nid'],
                'path': self.json['destination']['path'],
                'provider': self.destination_provider.serialized()
            },
                self.callback_url,
                self.auth,
                rename=self.json.get('rename'),
                conflict=self.json.get('conflict', 'replace'),
                start_time=time.time()
            )

            metadata, created = yield from tasks.wait_on_celery(result)
        else:
            metadata, created = (
                yield from tasks.backgrounded(
                    self.source_provider.copy,
                    self.destination_provider,
                    self.json['source']['path'],
                    self.json['destination']['path'],
                    rename=self.json.get('rename'),
                    conflict=self.json.get('conflict', 'replace'),
                )
            )

            self._send_hook('copy', metadata)

        if created:
            self.set_status(201)
        else:
            self.set_status(200)

        self.write(metadata)
Example #5
0
    def move_or_copy(self):
        # Force the json body to load into memory
        yield self.request.body

        if self.json.get("action") not in ("copy", "move", "rename"):
            # Note: null is used as the default to avoid python specific error messages
            raise exceptions.InvalidParameters(
                "Action must be copy, move or rename, not {}".format(self.json.get("action", "null"))
            )

        if self.json["action"] == "rename":
            if not self.json.get("rename"):
                raise exceptions.InvalidParameters("Rename is required for renaming")
            action = "move"
            self.dest_auth = self.auth
            self.dest_provider = self.provider
            self.dest_path = self.path.parent
            self.dest_resource = self.resource
        else:
            if "path" not in self.json:
                raise exceptions.InvalidParameters("Path is required for moves or copies")

            action = self.json["action"]

            # Note: attached to self so that _send_hook has access to these
            self.dest_resource = self.json.get("resource", self.resource)

            # TODO optimize for same provider and resource
            self.dest_auth = yield from auth_handler.get(
                self.dest_resource, self.json.get("provider", self.provider.NAME), self.request
            )

            self.dest_provider = make_provider(
                self.json.get("provider", self.provider.NAME),
                self.dest_auth["auth"],
                self.dest_auth["credentials"],
                self.dest_auth["settings"],
            )

            self.dest_path = yield from self.dest_provider.validate_path(self.json["path"])

        if not getattr(self.provider, "can_intra_" + action)(self.dest_provider, self.path):
            # this weird signature syntax courtesy of py3.4 not liking trailing commas on kwargs
            result = yield from getattr(tasks, action).adelay(
                rename=self.json.get("rename"), conflict=self.json.get("conflict", DEFAULT_CONFLICT), *self.build_args()
            )
            metadata, created = yield from tasks.wait_on_celery(result)
        else:
            metadata, created = (
                yield from tasks.backgrounded(
                    getattr(self.provider, action),
                    self.dest_provider,
                    self.path,
                    self.dest_path,
                    rename=self.json.get("rename"),
                    conflict=self.json.get("conflict", DEFAULT_CONFLICT),
                )
            )

        if created:
            self.set_status(201)
        else:
            self.set_status(200)

        self.write({"data": metadata.json_api_serialized(self.dest_resource)})
Example #6
0
    def move_or_copy(self):
        # Force the json body to load into memory
        yield self.request.body

        if self.json.get('action') not in ('copy', 'move', 'rename'):
            # Note: null is used as the default to avoid python specific error messages
            raise exceptions.InvalidParameters('Action must be copy, move or rename, not {}'.format(self.json.get('action', 'null')))

        if self.json['action'] == 'rename':
            if not self.json.get('rename'):
                raise exceptions.InvalidParameters('Rename is required for renaming')
            action = 'move'
            self.dest_auth = self.auth
            self.dest_provider = self.provider
            self.dest_path = self.path.parent
            self.dest_resource = self.resource
        else:
            if 'path' not in self.json:
                raise exceptions.InvalidParameters('Path is required for moves or copies')

            action = self.json['action']

            # Note: attached to self so that _send_hook has access to these
            self.dest_resource = self.json.get('resource', self.resource)

            # TODO optimize for same provider and resource
            self.dest_auth = yield from auth_handler.get(
                self.dest_resource,
                self.json.get('provider', self.provider.NAME),
                self.request
            )

            self.dest_provider = make_provider(
                self.json.get('provider', self.provider.NAME),
                self.dest_auth['auth'],
                self.dest_auth['credentials'],
                self.dest_auth['settings']
            )

            self.dest_path = yield from self.dest_provider.validate_path(self.json['path'])

        if not getattr(self.provider, 'can_intra_' + action)(self.dest_provider, self.path):
            result = yield from getattr(tasks, action).adelay(*self.build_args(self.dest_provider, self.dest_path))
            metadata, created = yield from tasks.wait_on_celery(result)
        else:
            metadata, created = (
                yield from tasks.backgrounded(
                    getattr(self.provider, action),
                    self.dest_provider,
                    self.path,
                    self.dest_path,
                    rename=self.json.get('rename'),
                    conflict=self.json.get('conflict', 'replace'),
                )
            )

        metadata = metadata.serialized()

        if created:
            self.set_status(201)
        else:
            self.set_status(200)

        self.write(metadata)
Example #7
0
    def move_or_copy(self):
        # Force the json body to load into memory
        yield self.request.body

        if self.json.get('action') not in ('copy', 'move', 'rename'):
            # Note: null is used as the default to avoid python specific error messages
            raise exceptions.InvalidParameters(
                'Action must be copy, move or rename, not {}'.format(
                    self.json.get('action', 'null')))

        if self.json['action'] == 'rename':
            action = 'move'
            self.dest_auth = self.auth
            self.dest_provider = self.provider
            self.dest_path = self.path.parent
        else:
            if 'path' not in self.json:
                raise exceptions.InvalidParameters(
                    'Path is required for moves or copies')

            action = self.json['action']

            # Note: attached to self so that _send_hook has access to these
            self.dest_resource = self.json.get('resource', self.resource)

            # TODO optimize for same provider and resource
            self.dest_auth = yield from auth_handler.get(
                self.dest_resource,
                self.json.get('provider', self.provider.NAME), self.request)

            self.dest_provider = make_provider(
                self.json.get('provider',
                              self.provider.NAME), self.dest_auth['auth'],
                self.dest_auth['credentials'], self.dest_auth['settings'])

            self.dest_path = yield from self.dest_provider.validate_path(
                self.json['path'])

        if not getattr(self.provider, 'can_intra_' + action)(
                self.dest_provider, self.path):
            result = yield from getattr(tasks, action).adelay(
                *self.build_args(self.dest_provider, self.dest_path))
            metadata, created = yield from tasks.wait_on_celery(result)
        else:
            metadata, created = (yield from tasks.backgrounded(
                getattr(self.provider, action),
                self.dest_provider,
                self.path,
                self.dest_path,
                rename=self.json.get('rename'),
                conflict=self.json.get('conflict', 'replace'),
            ))

        metadata = metadata.serialized()

        if created:
            self.set_status(201)
        else:
            self.set_status(200)

        self.write(metadata)