-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
remote: separate tree functions from main remote classes #3931
Changes from all commits
d86b11a
a18d223
ccb5b84
2968fd2
becbfb4
d9302f4
faedca4
7c96960
e12a1ef
39d475d
71f4540
fc23c96
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 |
---|---|---|
|
@@ -8,19 +8,53 @@ | |
|
||
from dvc.path_info import CloudURLInfo | ||
from dvc.progress import Tqdm | ||
from dvc.remote.base import BaseRemote | ||
from dvc.remote.base import BaseRemote, BaseRemoteTree | ||
from dvc.scheme import Schemes | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class AzureRemoteTree(BaseRemoteTree): | ||
@property | ||
def blob_service(self): | ||
return self.remote.blob_service | ||
|
||
def _generate_download_url(self, path_info, expires=3600): | ||
from azure.storage.blob import BlobPermissions | ||
|
||
expires_at = datetime.utcnow() + timedelta(seconds=expires) | ||
|
||
sas_token = self.blob_service.generate_blob_shared_access_signature( | ||
path_info.bucket, | ||
path_info.path, | ||
permission=BlobPermissions.READ, | ||
expiry=expires_at, | ||
) | ||
download_url = self.blob_service.make_blob_url( | ||
path_info.bucket, path_info.path, sas_token=sas_token | ||
) | ||
return download_url | ||
|
||
def exists(self, path_info): | ||
paths = self.remote.list_paths(path_info.bucket, path_info.path) | ||
return any(path_info.path == path for path in paths) | ||
|
||
def remove(self, path_info): | ||
if path_info.scheme != self.scheme: | ||
raise NotImplementedError | ||
|
||
logger.debug(f"Removing {path_info}") | ||
self.blob_service.delete_blob(path_info.bucket, path_info.path) | ||
|
||
|
||
class AzureRemote(BaseRemote): | ||
scheme = Schemes.AZURE | ||
path_cls = CloudURLInfo | ||
REQUIRES = {"azure-storage-blob": "azure.storage.blob"} | ||
PARAM_CHECKSUM = "etag" | ||
COPY_POLL_SECONDS = 5 | ||
LIST_OBJECT_PAGE_SIZE = 5000 | ||
TREE_CLS = AzureRemoteTree | ||
|
||
def __init__(self, repo, config): | ||
super().__init__(repo, config) | ||
|
@@ -65,14 +99,7 @@ def get_etag(self, path_info): | |
def get_file_checksum(self, path_info): | ||
return self.get_etag(path_info) | ||
|
||
def remove(self, path_info): | ||
if path_info.scheme != self.scheme: | ||
raise NotImplementedError | ||
|
||
logger.debug(f"Removing {path_info}") | ||
self.blob_service.delete_blob(path_info.bucket, path_info.path) | ||
|
||
def _list_paths(self, bucket, prefix, progress_callback=None): | ||
def list_paths(self, bucket, prefix, progress_callback=None): | ||
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. Isn't this 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 probably should be. I think it makes sense to implement |
||
blob_service = self.blob_service | ||
next_marker = None | ||
while True: | ||
|
@@ -97,7 +124,7 @@ def list_cache_paths(self, prefix=None, progress_callback=None): | |
) | ||
else: | ||
prefix = self.path_info.path | ||
return self._list_paths( | ||
return self.list_paths( | ||
self.path_info.bucket, prefix, progress_callback | ||
) | ||
|
||
|
@@ -122,23 +149,3 @@ def _download( | |
to_file, | ||
progress_callback=pbar.update_to, | ||
) | ||
|
||
def exists(self, path_info): | ||
paths = self._list_paths(path_info.bucket, path_info.path) | ||
return any(path_info.path == path for path in paths) | ||
|
||
def _generate_download_url(self, path_info, expires=3600): | ||
from azure.storage.blob import BlobPermissions | ||
|
||
expires_at = datetime.utcnow() + timedelta(seconds=expires) | ||
|
||
sas_token = self.blob_service.generate_blob_shared_access_signature( | ||
path_info.bucket, | ||
path_info.path, | ||
permission=BlobPermissions.READ, | ||
expiry=expires_at, | ||
) | ||
download_url = self.blob_service.make_blob_url( | ||
path_info.bucket, path_info.path, sas_token=sas_token | ||
) | ||
return download_url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should etag be part of the tree too? Kinda like stat.