mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-05 23:09:32 +01:00
deps: s3/gs: check if key exists
Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
@@ -12,12 +12,14 @@ from dvc.cloud.gcp import DataCloudGCP
|
||||
class DependencyGS(DependencyS3):
|
||||
REGEX = DataCloudGCP.REGEX
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
return gc.Client()
|
||||
|
||||
def get_etag(self):
|
||||
o = urlparse(self.path)
|
||||
bucket_name = o.netloc
|
||||
key = o.path.lstrip('/')
|
||||
bucket = self.client.bucket(self.bucket)
|
||||
blob = bucket.get_blob(self.key)
|
||||
if not blob:
|
||||
return None
|
||||
|
||||
client = gc.Client()
|
||||
bucket = client.bucket(bucket_name)
|
||||
blob = bucket.get_blob(key)
|
||||
return blob.etag
|
||||
|
||||
+17
-6
@@ -18,14 +18,25 @@ class DependencyS3(DependencyBase):
|
||||
super(DependencyS3, self).__init__(stage, path)
|
||||
self.etag = etag
|
||||
|
||||
def get_etag(self):
|
||||
o = urlparse(self.path)
|
||||
bucket = o.netloc
|
||||
key = o.path.lstrip('/')
|
||||
@property
|
||||
def bucket(self):
|
||||
return urlparse(self.path).netloc
|
||||
|
||||
@property
|
||||
def key(self):
|
||||
return urlparse(self.path).path.lstrip('/')
|
||||
|
||||
@property
|
||||
def s3(self):
|
||||
session = boto3.Session()
|
||||
s3 = session.resource('s3')
|
||||
obj = s3.Object(bucket, key).get()
|
||||
return session.resource('s3')
|
||||
|
||||
def get_etag(self):
|
||||
try:
|
||||
obj = self.s3.Object(self.bucket, self.key).get()
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
return obj['ETag'].strip('"')
|
||||
|
||||
def changed(self):
|
||||
|
||||
Reference in New Issue
Block a user