Skip to content

Commit

Permalink
rename get_prefer_checksum_type to checksum_type
Browse files Browse the repository at this point in the history
rename get_checksum_type_list to checksum_types
  • Loading branch information
vyloy committed May 7, 2019
1 parent 20969a4 commit d034618
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 41 deletions.
4 changes: 2 additions & 2 deletions dvc/output/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ def sep(self):

@property
def checksum_type(self):
for t in self.remote.get_checksum_type_list():
for t in self.remote.checksum_types():
if t in self.info:
return t
return None

@property
def checksum(self):
for t in self.remote.get_checksum_type_list():
for t in self.remote.checksum_types():
info = self.info.get(t)
if info:
return info
Expand Down
45 changes: 22 additions & 23 deletions dvc/remote/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ def group(self, name):
def cache(self):
return getattr(self.repo.cache, self.scheme)

def get_checksum_type_list(self):
def checksum_types(self):
return [self.PARAM_CHECKSUM]

def get_prefer_checksum_type(self):
def checksum_type(self):
return self.PARAM_CHECKSUM

def get_file_checksum(self, path_info):
Expand Down Expand Up @@ -186,7 +186,7 @@ def _collect_dir(self, path_info):
dir_info.append(
{
self.PARAM_RELPATH: relpath,
self.get_prefer_checksum_type(): checksum,
self.checksum_type(): checksum,
}
)

Expand All @@ -201,8 +201,8 @@ def get_dir_checksum(self, path_info):
if self.cache.changed_cache_file(checksum):
self.cache.move(from_info, to_info)

self.state.save(path_info, checksum, self.get_prefer_checksum_type())
self.state.save(to_info, checksum, self.get_prefer_checksum_type())
self.state.save(path_info, checksum, self.checksum_type())
self.state.save(to_info, checksum, self.checksum_type())

return checksum

Expand Down Expand Up @@ -271,7 +271,7 @@ def get_checksum(self, path_info, checksum_type=None):
return None

if checksum_type is None:
checksum_type = self.get_prefer_checksum_type()
checksum_type = self.checksum_type()
checksum = self.state.get(path_info, checksum_type)
if checksum:
return checksum
Expand All @@ -290,7 +290,7 @@ def save_info(self, path_info, checksum_type=None):
assert path_info["scheme"] == self.scheme
return {
checksum_type
or self.get_prefer_checksum_type(): self.get_checksum(
or self.checksum_type(): self.get_checksum(
path_info, checksum_type
)
}
Expand All @@ -305,7 +305,7 @@ def changed_checksum(self, path_info, checksum_info, addition_check=None):
return True

types = set(checksum_info.keys())
supported_types = set(self.get_checksum_type_list())
supported_types = set(self.checksum_types())
intersection = supported_types.intersection(types)
if not supported_types.intersection(types):
logger.debug(
Expand Down Expand Up @@ -390,25 +390,25 @@ def _save_file(self, path_info, checksum, save_link=True):
# we need to update path and cache, since in case of reflink,
# or copy cache type moving original file results in updates on
# next executed command, which causes md5 recalculation
self.state.save(path_info, checksum, self.get_prefer_checksum_type())
self.state.save(cache_info, checksum, self.get_prefer_checksum_type())
self.state.save(path_info, checksum, self.checksum_type())
self.state.save(cache_info, checksum, self.checksum_type())

def _save_dir(self, path_info, checksum):
cache_info = self.checksum_to_path_info(checksum)
dir_info = self.get_dir_cache(checksum)

entry_info = path_info.copy()
for entry in dir_info:
entry_checksum = entry[self.get_prefer_checksum_type()]
entry_checksum = entry[self.checksum_type()]
entry_info["path"] = self.ospath.join(
path_info["path"], entry[self.PARAM_RELPATH]
)

self._save_file(entry_info, entry_checksum, save_link=False)

self.state.save_link(path_info)
self.state.save(cache_info, checksum, self.get_prefer_checksum_type())
self.state.save(path_info, checksum, self.get_prefer_checksum_type())
self.state.save(cache_info, checksum, self.checksum_type())
self.state.save(path_info, checksum, self.checksum_type())

def is_empty(self, path_info):
return False
Expand All @@ -432,8 +432,8 @@ def save(self, path_info, checksum_info):
self.scheme,
)

checksum = checksum_info[self.get_prefer_checksum_type()]
if not self.changed_cache(checksum, self.get_prefer_checksum_type()):
checksum = checksum_info[self.checksum_type()]
if not self.changed_cache(checksum, self.checksum_type()):
self._checkout(path_info, checksum)
return

Expand Down Expand Up @@ -522,14 +522,13 @@ def all(self):
def gc(self, cinfos):

used = {
info[self.repo.cache.local.get_prefer_checksum_type()]
info[self.repo.cache.local.checksum_type()]
for info in cinfos["local"]
}

if self.scheme != "":
used |= {
info[self.get_prefer_checksum_type()]
for info in cinfos[self.scheme]
info[self.checksum_type()] for info in cinfos[self.scheme]
}

removed = False
Expand All @@ -543,7 +542,7 @@ def gc(self, cinfos):

def changed_cache_file(self, checksum, checksum_type=None):
if checksum_type is None:
checksum_type = self.get_prefer_checksum_type()
checksum_type = self.checksum_type()
cache_info = self.checksum_to_path_info(checksum)
actual = self.get_checksum(cache_info, checksum_type)

Expand Down Expand Up @@ -585,7 +584,7 @@ def _changed_dir_cache(self, checksum, checksum_type):

def changed_cache(self, checksum, checksum_type=None):
if checksum_type is None:
checksum_type = self.get_prefer_checksum_type()
checksum_type = self.checksum_type()
if self.is_dir_checksum(checksum):
return self._changed_dir_cache(checksum, checksum_type)
return self.changed_cache_file(checksum, checksum_type)
Expand Down Expand Up @@ -656,12 +655,12 @@ def _checkout_dir(
entry_info = path_info.copy()
for entry in dir_info:
relpath = entry[self.PARAM_RELPATH]
checksum = entry[self.get_prefer_checksum_type()]
checksum = entry[self.checksum_type()]
entry_cache_info = self.checksum_to_path_info(checksum)
entry_info["url"] = self.ospath.join(path_info["url"], relpath)
entry_info["path"] = self.ospath.join(path_info["path"], relpath)

entry_checksum_info = {self.get_prefer_checksum_type(): checksum}
entry_checksum_info = {self.checksum_type(): checksum}
if self.changed(entry_info, entry_checksum_info):
if self.exists(entry_info):
self.safe_remove(entry_info, force=force)
Expand Down Expand Up @@ -699,7 +698,7 @@ def checkout(
if scheme not in ["", "local"] and scheme != self.scheme:
raise NotImplementedError

checksum = checksum_info.get(self.get_prefer_checksum_type())
checksum = checksum_info.get(self.checksum_type())
if not checksum:
msg = "No checksum info for '{}'."
logger.debug(msg.format(str(path_info)))
Expand Down
18 changes: 9 additions & 9 deletions dvc/remote/local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ def __init__(self, repo, config):
else:
self.cache_types = copy(self.DEFAULT_CACHE_TYPES)

self._hash = [modchecksum.CHECKSUM_MD5]
self._checksum_types = [modchecksum.CHECKSUM_MD5]
if repo is not None:
conf = repo.config.config[Config.SECTION_CHECKSUM]
hash_local = conf.get(Config.SECTION_CHECKSUM_LOCAL, None)
if hash_local:
self._hash = (
self._checksum_types = (
modchecksum.checksum_types_from_str(hash_local)
or self._hash
or self._checksum_types
)

if self.cache_dir is not None and not os.path.exists(self.cache_dir):
Expand Down Expand Up @@ -208,14 +208,14 @@ def isdir(self, path_info):
def walk(self, path_info):
return os.walk(path_info["path"])

def get_checksum_type_list(self):
return self._hash
def checksum_types(self):
return self._checksum_types

def get_prefer_checksum_type(self):
return self._hash[0]
def checksum_type(self):
return self._checksum_types[0]

def get_file_checksum(self, path_info):
return file_checksum(path_info["path"], self._hash[0])[0]
return file_checksum(path_info["path"], self._checksum_types[0])[0]

def remove(self, path_info):
if path_info["scheme"] != "local":
Expand Down Expand Up @@ -328,7 +328,7 @@ def _group(self, checksum_infos, show_checksums=False):
by_md5 = {}

for info in checksum_infos:
md5 = info[self.get_prefer_checksum_type()]
md5 = info[self.checksum_type()]

if show_checksums:
by_md5[md5] = {"name": md5}
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _collect_dir_cache(
info = out.dumpd()
ret = [info]
r = out.remote
md5 = info[r.get_prefer_checksum_type()]
md5 = info[r.checksum_type()]

if self.cache.local.changed_cache_file(md5):
try:
Expand Down
10 changes: 4 additions & 6 deletions dvc/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,12 @@ def is_stage_file(path):
return os.path.isfile(path) and Stage.is_valid_filename(path)

def changed_checksum(self):
for h in self.repo.cache.local.get_checksum_type_list():
for h in self.repo.cache.local.checksum_types():
if h in self.checksum:
return self.checksum[h] != self._compute_checksum(h)

return (
self._compute_checksum(
self.repo.cache.local.get_prefer_checksum_type()
)
self._compute_checksum(self.repo.cache.local.checksum_type())
is not None
)

Expand Down Expand Up @@ -406,7 +404,7 @@ def is_cached(self):
new_d.pop(k, None)
outs = old_d.get(self.PARAM_OUTS, [])
for out in outs:
out.pop(self.repo.cache.local.get_prefer_checksum_type(), None)
out.pop(self.repo.cache.local.checksum_type(), None)
out.pop(RemoteS3.PARAM_CHECKSUM, None)

if old_d != new_d:
Expand Down Expand Up @@ -721,7 +719,7 @@ def save(self):
for out in self.outs:
out.save()

hash_type = self.repo.cache.local.get_prefer_checksum_type()
hash_type = self.repo.cache.local.checksum_type()
self.checksum = {hash_type: self._compute_checksum(hash_type)}

@staticmethod
Expand Down

0 comments on commit d034618

Please sign in to comment.