RFC: remote: unify changed() method

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2019-01-09 17:46:36 +02:00
parent ee40a9a48a
commit 313541d047
6 changed files with 41 additions and 73 deletions
+41 -1
View File
@@ -108,7 +108,47 @@ class RemoteBase(object):
raise NotImplementedError
def changed(self, path_info, checksum_info):
raise NotImplementedError
"""Checks if data has changed.
A file is considered changed if:
- It doesn't exist on the working directory (was unlinked)
- Checksum is not computed (saving a new file)
- The checkusm stored in the State is different from the given one
- There's no file in the cache
Args:
path_info: dict with path information.
checksum: expected checksum for this data.
Returns:
bool: True if data has changed, False otherwise.
"""
logger.debug("checking if '{}'('{}') has changed."
.format(path_info, checksum_info))
if not self.exists(path_info):
logger.debug("'{}' doesn't exist.".format(path_info))
return True
checksum = checksum_info.get(self.PARAM_CHECKSUM)
if checksum is None:
logger.debug("checksum for '{}' is missing.".format(path_info))
return True
if self.changed_cache(checksum):
logger.debug("cache for '{}'('{}') has changed."
.format(path_info, checksum))
return True
actual = self.save_info(path_info)[self.PARAM_CHECKSUM]
if checksum != actual:
logger.debug("checksum '{}'(actual '{}') for '{}' has changed."
.format(checksum, actual, path_info))
return True
logger.debug("'{}' hasn't changed.".format(path_info))
return False
def save(self, path_info):
raise NotImplementedError
-13
View File
@@ -63,19 +63,6 @@ class RemoteGS(RemoteBase):
return {self.PARAM_CHECKSUM: self.get_md5(path_info['bucket'],
path_info['path'])}
def changed(self, path_info, checksum_info):
if not self.exists(path_info):
return True
md5 = checksum_info.get(self.PARAM_CHECKSUM, None)
if md5 is None:
return True
if self.changed_cache(md5):
return True
return checksum_info != self.save_info(path_info)
def copy(self, from_info, to_info, gs=None):
gs = gs if gs else self.gs
-13
View File
@@ -84,19 +84,6 @@ class RemoteHDFS(RemoteBase):
return {self.PARAM_CHECKSUM: self.checksum(path_info)}
def changed(self, path_info, checksum_info):
if not self.exists(path_info):
return True
checksum = checksum_info.get(self.PARAM_CHECKSUM, None)
if checksum is None:
return True
if self.changed_cache(checksum):
return True
return checksum_info != self.save_info(path_info)
def save(self, path_info):
if path_info['scheme'] != 'hdfs':
raise NotImplementedError
-20
View File
@@ -429,26 +429,6 @@ class RemoteLOCAL(RemoteBase):
return {self.PARAM_CHECKSUM: self.state.update(path_info['path'])}
def changed(self, path_info, checksum_info):
"""
A file is considered changed if:
- It doesn't exist on the working directory (was unlinked)
- Checksum is not computed (saving a new file)
- The checkusm stored in the State is different from the given one
- There's no file in the cache
"""
if not self.exists(path_info):
return True
md5 = checksum_info.get(self.PARAM_CHECKSUM, None)
if md5 is None:
return True
if self.changed_cache(md5):
return True
return checksum_info != self.save_info(path_info)
def remove(self, path_info):
if path_info['scheme'] != 'local':
raise NotImplementedError
-13
View File
@@ -98,19 +98,6 @@ class RemoteS3(RemoteBase):
return {self.PARAM_CHECKSUM: self.get_etag(path_info['bucket'],
path_info['path'])}
def changed(self, path_info, checksum_info):
if not self.exists(path_info):
return True
etag = checksum_info.get(self.PARAM_CHECKSUM, None)
if etag is None:
return True
if self.changed_cache(etag):
return True
return checksum_info != self.save_info(path_info)
def copy(self, from_info, to_info, s3=None):
s3 = s3 if s3 else self.s3
-13
View File
@@ -218,19 +218,6 @@ class RemoteSSH(RemoteBase):
return {self.PARAM_CHECKSUM: self.md5(path_info)}
def changed(self, path_info, checksum_info):
if not self.exists(path_info):
return True
md5 = checksum_info.get(self.PARAM_CHECKSUM, None)
if md5 is None:
return True
if self.changed_cache(md5):
return True
return checksum_info != self.save_info(path_info)
def save(self, path_info):
if path_info['scheme'] != 'ssh':
raise NotImplementedError