Skip to content

Commit

Permalink
made changes suggested by aiguofer in PR aiguofer#48
Browse files Browse the repository at this point in the history
  • Loading branch information
benhoman committed Oct 25, 2021
1 parent e762ee5 commit 9854108
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
27 changes: 17 additions & 10 deletions gspread_pandas/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def create_folder(self, path, parents=True):
self.refresh_directories()
return parent

def move_file(self, file_id, path, create=False):
def move_file(self, file_id, path=None, folder_id=None, create=False):
"""
Move a file to the given path.
Expand All @@ -414,22 +414,29 @@ def move_file(self, file_id, path, create=False):
path : str
folder path. A path starting with `/` will use your drive, for shared drives
the path will start with `<Shared Drive Name>/` (no leading /)
(Default value = None)
folder_id: str
folder id to move file to. (Default value = None)
create : bool
whether to create any missing folders (Default value = False)
Returns
-------
"""
if path == "/":
folder_id = "root"
else:
parent, missing = folders_to_create(path, self._get_dirs(False))
if missing:
if not create:
raise Exception("Folder does not exist")
if path is None and folder_id is None:
raise Exception("Either path or folder_id is required")

if path:
if path == "/":
folder_id = "root"
else:
parent, missing = folders_to_create(path, self._get_dirs(False))
if missing:
if not create:
raise Exception("Folder does not exist")

parent = self.create_folder(path)
folder_id = parent["id"]
parent = self.create_folder(path)
folder_id = parent["id"]

old_parents = self._drive_request(
"get", file_id, params={"fields": "parents"}
Expand Down
13 changes: 9 additions & 4 deletions gspread_pandas/spread.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,19 +1012,24 @@ def list_permissions(self):
"""
return self.client.list_permissions(self.spread.id)

def move(self, path="/", create=True):
def move(self, path="/", folder_id=None, create=True):
"""
Move the current spreadsheet to the specified path in your Google drive. If the
file is not currently in you drive, it will be added.
Move the current spreadsheet to the specified path or folder_id in your
Google drive. If the file is not currently in you drive, it will be
added.
Parameters
----------
path : str
folder path (Default value = "/")
folder_id: str
folder id (Default value = None)
create : bool
if true, create folders as needed (Default value = True)
Returns
-------
"""
self.client.move_file(self.spread.id, path, create)
if folder_id:
path = None
self.client.move_file(self.spread.id, path, folder_id, create)

0 comments on commit 9854108

Please sign in to comment.