Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #77 #119

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions bot/helpers/gdrive_utils/gDrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def getFilesByFolderId(self, folder_id):
break
return files


@retry(wait=wait_exponential(multiplier=2, min=3, max=6), stop=stop_after_attempt(5),
retry=retry_if_exception_type(HttpError), before=before_log(LOGGER, logging.DEBUG))
def copyFile(self, file_id, dest_id):
Expand All @@ -76,7 +75,6 @@ def copyFile(self, file_id, dest_id):
else:
raise err


def cloneFolder(self, name, local_path, folder_id, parent_id):
files = self.getFilesByFolderId(folder_id)
new_id = None
Expand All @@ -85,7 +83,7 @@ def cloneFolder(self, name, local_path, folder_id, parent_id):
for file in files:
if file.get('mimeType') == self.__G_DRIVE_DIR_MIME_TYPE:
file_path = os.path.join(local_path, file.get('name'))
current_dir_id = self.create_directory(file.get('name'))
current_dir_id = self.create_directory(file.get('name'), parent_id)
new_id = self.cloneFolder(file.get('name'), file_path, file.get('id'), current_dir_id)
else:
try:
Expand All @@ -101,15 +99,18 @@ def cloneFolder(self, name, local_path, folder_id, parent_id):

@retry(wait=wait_exponential(multiplier=2, min=3, max=6), stop=stop_after_attempt(5),
retry=retry_if_exception_type(HttpError), before=before_log(LOGGER, logging.DEBUG))
def create_directory(self, directory_name):
file_metadata = {
"name": directory_name,
"mimeType": self.__G_DRIVE_DIR_MIME_TYPE
}
file_metadata["parents"] = [self.__parent_id]
file = self.__service.files().create(supportsTeamDrives=True, body=file_metadata).execute()
file_id = file.get("id")
return file_id
def create_directory(self, directory_name, parent_id=None):
file_metadata = {
"name": directory_name,
"mimeType": self.__G_DRIVE_DIR_MIME_TYPE
}
if parent_id is not None:
file_metadata["parents"] = [parent_id]
else:
file_metadata["parents"] = [self.__parent_id]
file = self.__service.files().create(supportsTeamDrives=True, body=file_metadata).execute()
file_id = file.get("id")
return file_id

def clone(self, link):
self.transferred_size = 0
Expand All @@ -134,7 +135,6 @@ def clone(self, link):
LOGGER.error(err)
return f"**ERROR:** ```{err}```"


@retry(wait=wait_exponential(multiplier=2, min=3, max=6), stop=stop_after_attempt(5),
retry=retry_if_exception_type(HttpError), before=before_log(LOGGER, logging.DEBUG))
def upload_file(self, file_path, mimeType=None):
Expand Down Expand Up @@ -219,4 +219,4 @@ def emptyTrash(self):


def authorize(self, creds):
return build('drive', 'v3', credentials=creds, cache_discovery=False)
return build('drive', 'v3', credentials=creds, cache_discovery=False)