Skip to content

Commit

Permalink
Fix error extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
JaskaranSM committed Jun 21, 2020
1 parent 45f75fb commit 1b79bbd
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions bot/helper/mirror_utils/upload_utils/gdriveTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,44 +290,31 @@ def clone(self, link):
LOGGER.info(f"File ID: {file_id}")
try:
meta = self.getFileMetadata(file_id)
except Exception as e:
return f"{str(e).replace('>', '').replace('<', '')}"
if meta.get("mimeType") == self.__G_DRIVE_DIR_MIME_TYPE:
dir_id = self.create_directory(meta.get('name'), parent_id)
try:
if meta.get("mimeType") == self.__G_DRIVE_DIR_MIME_TYPE:
dir_id = self.create_directory(meta.get('name'), parent_id)
result = self.cloneFolder(meta.get('name'), meta.get('name'), meta.get('id'), dir_id)
except Exception as e:
if isinstance(e, RetryError):
LOGGER.info(f"Total Attempts: {e.last_attempt.attempt_number}")
err = e.last_attempt.exception()
else:
err = str(e).replace('>', '').replace('<', '')
LOGGER.error(err)
return err
msg += f'<a href="{self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id)}">{meta.get("name")}</a>' \
f' ({get_readable_file_size(self.transferred_size)})'
if INDEX_URL is not None:
url = requests.utils.requote_uri(f'{INDEX_URL}/{meta.get("name")}/')
msg += f' | <a href="{url}"> Index URL</a>'
else:
try:
file = self.copyFile(meta.get('id'), parent_id)
except Exception as e:
if isinstance(e, RetryError):
LOGGER.info(f"Total Attempts: {e.last_attempt.attempt_number}")
err = e.last_attempt.exception()
else:
err = str(e).replace('>', '').replace('<', '')
LOGGER.error(err)
return err
msg += f'<a href="{self.__G_DRIVE_BASE_DOWNLOAD_URL.format(file.get("id"))}">{file.get("name")}</a>'
try:
msg += f' ({get_readable_file_size(int(meta.get("size")))}) '
msg += f'<a href="{self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id)}">{meta.get("name")}</a>' \
f' ({get_readable_file_size(self.transferred_size)})'
if INDEX_URL is not None:
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}')
url = requests.utils.requote_uri(f'{INDEX_URL}/{meta.get("name")}/')
msg += f' | <a href="{url}"> Index URL</a>'
except TypeError:
pass
else:
file = self.copyFile(meta.get('id'), parent_id)
msg += f'<a href="{self.__G_DRIVE_BASE_DOWNLOAD_URL.format(file.get("id"))}">{file.get("name")}</a>'
try:
msg += f' ({get_readable_file_size(int(meta.get("size")))}) '
except TypeError:
pass
if INDEX_URL is not None:
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}')
msg += f' | <a href="{url}"> Index URL</a>'
except Exception as err:
if isinstance(err, RetryError):
LOGGER.info(f"Total Attempts: {err.last_attempt.attempt_number}")
err = err.last_attempt.exception()
err = str(err).replace('>', '').replace('<', '')
LOGGER.error(err)
return err
return msg

def cloneFolder(self, name, local_path, folder_id, parent_id):
Expand Down

0 comments on commit 1b79bbd

Please sign in to comment.