-
Notifications
You must be signed in to change notification settings - Fork 1.3k
tree: Implement upload_fobj protocol to all trees #5307
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
Changes from all commits
02f1c4a
ee43ff6
893bf2f
34a6004
c96615f
60bf00f
e8cb073
38ad72f
200a1fb
4d455a7
8a38cb9
80f29e1
5be166e
8ae1efc
1a43bfc
ffbc667
2d178ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -59,6 +59,8 @@ class BaseTree: | |||||||
| TRAVERSE_PREFIX_LEN = 3 | ||||||||
| TRAVERSE_THRESHOLD_SIZE = 500000 | ||||||||
| CAN_TRAVERSE = True | ||||||||
|
|
||||||||
| # Needed for some providers, and http open() | ||||||||
| CHUNK_SIZE = 64 * 1024 * 1024 # 64 MiB | ||||||||
|
Comment on lines
+62
to
64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it is now only used in http, so I guess no need to have it in the base class.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used in the |
||||||||
|
|
||||||||
| PARAM_CHECKSUM: ClassVar[Optional[str]] = None | ||||||||
|
|
@@ -226,9 +228,6 @@ def move(self, from_info, to_info): | |||||||
| def copy(self, from_info, to_info): | ||||||||
| raise RemoteActionNotImplemented("copy", self.scheme) | ||||||||
|
|
||||||||
| def copy_fobj(self, fobj, to_info, chunk_size=None): | ||||||||
| raise RemoteActionNotImplemented("copy_fobj", self.scheme) | ||||||||
|
|
||||||||
| def symlink(self, from_info, to_info): | ||||||||
| raise RemoteActionNotImplemented("symlink", self.scheme) | ||||||||
|
|
||||||||
|
|
@@ -364,8 +363,14 @@ def upload( | |||||||
| no_progress_bar=no_progress_bar, | ||||||||
| ) | ||||||||
|
|
||||||||
| def upload_fobj(self, fobj, to_info, no_progress_bar=False): | ||||||||
| raise RemoteActionNotImplemented("upload_fobj", self.scheme) | ||||||||
| def upload_fobj(self, fobj, to_info, no_progress_bar=False, **pbar_args): | ||||||||
| if not hasattr(self, "_upload_fobj"): | ||||||||
| raise RemoteActionNotImplemented("upload_fobj", self.scheme) | ||||||||
|
|
||||||||
| with Tqdm.wrapattr( | ||||||||
| fobj, "read", disable=no_progress_bar, bytes=True, **pbar_args | ||||||||
| ) as wrapped: | ||||||||
| self._upload_fobj(wrapped, to_info) # pylint: disable=no-member | ||||||||
|
|
||||||||
| def download( | ||||||||
| self, | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -345,29 +345,12 @@ def _gdrive_shared_drive_id(self, item_id): | |
| return item.get("driveId", None) | ||
|
|
||
| @_gdrive_retry | ||
| def _gdrive_upload_file( | ||
| self, | ||
| parent_id, | ||
| title, | ||
| no_progress_bar=False, | ||
| from_file="", | ||
| progress_name="", | ||
| ): | ||
| def _gdrive_upload_fobj(self, fobj, parent_id, title): | ||
|
||
| item = self._drive.CreateFile( | ||
| {"title": title, "parents": [{"id": parent_id}]} | ||
| ) | ||
|
|
||
| with open(from_file, "rb") as fobj: | ||
| total = os.path.getsize(from_file) | ||
| with Tqdm.wrapattr( | ||
| fobj, | ||
| "read", | ||
| desc=progress_name, | ||
| total=total, | ||
| disable=no_progress_bar, | ||
| ) as wrapped: | ||
| item.content = wrapped | ||
| item.Upload() | ||
| item.content = fobj | ||
| item.Upload() | ||
| return item | ||
|
|
||
| @_gdrive_retry | ||
|
|
@@ -570,16 +553,23 @@ def getsize(self, path_info): | |
| gdrive_file.FetchMetadata(fields="fileSize") | ||
| return gdrive_file.get("fileSize") | ||
|
|
||
| def _upload( | ||
| self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs | ||
| ): | ||
| def _upload_fobj(self, fobj, to_info): | ||
| dirname = to_info.parent | ||
| assert dirname | ||
| parent_id = self._get_item_id(dirname, True) | ||
| parent_id = self._get_item_id(dirname, create=True) | ||
| self._gdrive_upload_fobj(fobj, parent_id, to_info.name) | ||
|
|
||
| self._gdrive_upload_file( | ||
| parent_id, to_info.name, no_progress_bar, from_file, name | ||
| ) | ||
| def _upload( | ||
| self, from_file, to_info, name=None, no_progress_bar=False, **_kwargs | ||
| ): | ||
| with open(from_file, "rb") as fobj: | ||
| self.upload_fobj( | ||
| fobj, | ||
| to_info, | ||
| no_progress_bar=no_progress_bar, | ||
| desc=name or to_info.name, | ||
| total=os.path.getsize(from_file), | ||
| ) | ||
|
|
||
| def _download(self, from_info, to_file, name=None, no_progress_bar=False): | ||
| item_id = self._get_item_id(from_info) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.