diff --git a/examples/onedrive/files/copy_file.py b/examples/onedrive/files/copy_file.py index d0cbf75e..bd96722c 100644 --- a/examples/onedrive/files/copy_file.py +++ b/examples/onedrive/files/copy_file.py @@ -10,13 +10,15 @@ client = GraphClient.with_username_and_password( test_tenant, test_client_id, test_username, test_password ) -source_path = "archive/Sample.rtf" -new_name = "Sample (copy).rtf" +# source_path = "archive/Sample.rtf" +local_path = "../../data/Financial Sample.xlsx" +source_file = client.me.drive.root.upload_file(local_path).execute_query() +# new_name = "Sample (copy).rtf" +# source_file = client.me.drive.root.get_by_path(source_path) # source file item target_path = "archive/2018" -source_file_item = client.me.drive.root.get_by_path(source_path) # source file item -target_folder_item = client.me.drive.root.get_by_path(target_path) # target folder item +target_folder = client.me.drive.root.get_by_path(target_path) # result = source_file_item.copy(name=new_name).execute_query() # copy to the same folder with a different name -result = source_file_item.copy( - parent=target_folder_item +result = source_file.copy( + parent=target_folder ).execute_query() # copy to another folder print(result.value) diff --git a/office365/onedrive/driveitems/driveItem.py b/office365/onedrive/driveitems/driveItem.py index e5a31d9a..af1bb4ef 100644 --- a/office365/onedrive/driveitems/driveItem.py +++ b/office365/onedrive/driveitems/driveItem.py @@ -469,6 +469,7 @@ def convert(self, format_name): return self.get_content(format_name) def copy(self, name=None, parent=None, conflict_behavior=ConflictBehavior.Fail): + # type: (str, ItemReference|"DriveItem", str) -> ClientResult[str] """Asynchronously creates a copy of an driveItem (including any children), under a new parent item or with a new name. @@ -480,32 +481,28 @@ def copy(self, name=None, parent=None, conflict_behavior=ConflictBehavior.Fail): Returns location for details about how to monitor the progress of the copy, upon accepting the request. """ - return_type = ClientResult(self.context) # type: ClientResult[str] + return_type = ClientResult(self.context, str()) - def _create_request(request): - # type: (RequestOptions) -> None - request.url += "?@microsoft.graph.conflictBehavior={0}".format( - conflict_behavior - ) + def _copy(parent_reference): + # type: (ItemReference) -> None + + def _create_request(request): + # type: (RequestOptions) -> None + request.url += "?@microsoft.graph.conflictBehavior={0}".format( + conflict_behavior + ) + + def _process_response(resp): + # type: (requests.Response) -> None + resp.raise_for_status() + location = resp.headers.get("Location", None) + if location is None: + return + return_type.set_property("__value", location) - def _process_response(resp): - # type: (requests.Response) -> None - resp.raise_for_status() - location = resp.headers.get("Location", None) - if location is None: - return - return_type.set_property("__value", location) - - def _create_and_add_query(parent_reference): - """ - :param office365.onedrive.listitems.item_reference.ItemReference or None parent_reference: Reference to the - parent item the copy will be created in. - """ payload = {"name": name, "parentReference": parent_reference} - self.context.before_execute(_create_request) - self.context.after_execute(_process_response) qry = ServiceOperationQuery(self, "copy", None, payload, None, return_type) - self.context.add_query(qry) + self.context.add_query(qry).before_execute(_create_request).after_execute(_process_response) if isinstance(parent, DriveItem): @@ -513,11 +510,11 @@ def _drive_item_loaded(): parent_reference = ItemReference( drive_id=parent.parent_reference.driveId, _id=parent.id ) - _create_and_add_query(parent_reference) + _copy(parent_reference) parent.ensure_property("parentReference", _drive_item_loaded) else: - _create_and_add_query(parent) + _copy(parent) return return_type def move(self, name=None, parent=None, conflict_behavior=ConflictBehavior.Fail): @@ -668,7 +665,7 @@ def permanent_delete(self): return self def restore(self, parent_reference=None, name=None): - # type: (ItemReference or None, str or None) -> DriveItem + # type: (Optional[ItemReference], str) -> "DriveItem" """ Restore a driveItem that has been deleted and is currently in the recycle bin. NOTE: This functionality is currently only available for OneDrive Personal. diff --git a/office365/onedrive/storage/__init__.py b/office365/onedrive/storage/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/office365/onedrive/storage/storage.py b/office365/onedrive/storage/storage.py new file mode 100644 index 00000000..9bcfb358 --- /dev/null +++ b/office365/onedrive/storage/storage.py @@ -0,0 +1,5 @@ +from office365.entity import Entity + + +class Storage(Entity): + """Facilitates the structures of fileStorageContainers.""" diff --git a/office365/onedrive/workbooks/workbook.py b/office365/onedrive/workbooks/workbook.py index 34660ae0..ca672207 100644 --- a/office365/onedrive/workbooks/workbook.py +++ b/office365/onedrive/workbooks/workbook.py @@ -53,14 +53,12 @@ def refresh_session(self, session_id): """Use this API to refresh an existing workbook session. :param str session_id: Identifier of the workbook session """ - qry = ServiceOperationQuery(self, "refreshSession") - self.context.add_query(qry) - def _construct_request(request): # type: (RequestOptions) -> None request.set_header("workbook-session-id", session_id) - self.context.before_execute(_construct_request) + qry = ServiceOperationQuery(self, "refreshSession") + self.context.add_query(qry).before_execute(_construct_request) return self def close_session(self, session_id): @@ -73,8 +71,7 @@ def _construct_request(request): # type: (RequestOptions) -> None request.set_header("workbook-session-id", session_id) - self.context.before_execute(_construct_request) - self.context.add_query(qry) + self.context.add_query(qry).before_execute(_construct_request) return self @property