Skip to content

Commit

Permalink
update=False now working again
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-martin-dev committed Jan 26, 2024
1 parent a58a34c commit d6db505
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
19 changes: 6 additions & 13 deletions Driveup/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,13 @@ def upload(self,file_path: Union[str, List[str]],folder_id:Union[str, List[str]]
pbar.update(10)

drive_service = self.drive_service
# # possible refactor
# if update == True:
# file_metadata = service.get_update(file_title,file_id,folder_id,drive_service,self.mode)

# Fill metadata for file creation

file_metadata = {}
file_metadata['name'] = file_title
file_metadata['parents'] = folder_id if self.mode == 'service' else [folder_id]
if file_id != None:
file_metadata['id'] = file_id

# if self.mode == 'client':
# file_metadata = {'name': file_title,'parents': [folder_id]}
# else:
# file_metadata = {'name': file_title,'parents': folder_id}

file_extension = utils.get_file_extension(file_path)

if convert == True:
Expand All @@ -115,10 +106,12 @@ def upload(self,file_path: Union[str, List[str]],folder_id:Union[str, List[str]]

pbar.update(40)

if duplicate_check:
if duplicate_check and update == True:
file_id = file_metadata['id']
gfile = self.update(file_path,file_id)
else:
else:
if update == False:
del file_metadata['id']
media = MediaFileUpload(file_path, resumable=True)
gfile = drive_service.files().create(body=file_metadata, media_body=media, fields='id',supportsAllDrives=True).execute()

Expand Down Expand Up @@ -243,7 +236,7 @@ def upload_folder(self,local_folder_path :str,folder_id :str,update : bool =True
# uploaded_files_counter += 1
# print(f"\n\nUploading folder's files : {uploaded_files_counter}/{total_files_to_upload_count}")
try:
self.upload(file_path,folder_id,update=update,convert=convert,url=False) # url=False -> not checking everytime
self.upload(file_path,folder_id,convert=convert,url=False) # url=False -> not checking everytime
except Exception as e:
print(f"Error uploading file: {file_path}\nERROR: {e}")
pbar.update(1)
Expand Down
8 changes: 6 additions & 2 deletions Driveup/features/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ def create_subfolder(subfolder_name,subfolder_id,parent_folder_id,update,service

# subfolder_metadata = {'name': subfolder_name, 'mimeType': 'application/vnd.google-apps.folder', 'parents': [parent_folder_id]}

duplicate_check, subfolder_metadata = find_duplicate(subfolder_metadata,service)
if update == True:
duplicate_check, subfolder_metadata = find_duplicate(subfolder_metadata,service)
else:
duplicate_check = False
subfolder_metadata.pop('id',None)

if duplicate_check == False:
subfolder_metadata['parents'] = [subfolder_metadata['parents']]
Expand All @@ -176,7 +180,7 @@ def create_subfolder(subfolder_name,subfolder_id,parent_folder_id,update,service
file_id = subfolder_metadata.get('id')

subfolder_metadata = service.files().update(fileId=file_id,removeParents=old_parents,addParents=old_parents,supportsAllDrives=True).execute()

print(subfolder_metadata)
return subfolder_metadata['id']

# if subfolder == None:
Expand Down
2 changes: 1 addition & 1 deletion tests/drive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_reupload_folder(self):

drive_obj = Drive(creds)

drive_obj.upload_folder(DOWNLOAD_FOLDER_PATH,'1Qq__pF7GrOdf9LyTLWCELIk6OrYwwVe9',subfolder=False,convert=True)
drive_obj.upload_folder(DOWNLOAD_FOLDER_PATH,'1Qq__pF7GrOdf9LyTLWCELIk6OrYwwVe9',convert=True)



Expand Down

0 comments on commit d6db505

Please sign in to comment.