in benchmarking/benchmarks/benchmarks.py [0:0]
def _copyFile(self, field, destination_name, source):
if "location" not in field:
return False
location = field["location"]
if location[0:4] == "http":
abs_name = destination_name
getLogger().info("Downloading {}".format(location))
r = requests.get(location)
if r.status_code == 200:
with open(destination_name, "wb") as f:
f.write(r.content)
else:
abs_name = self._getAbsFilename(field, source, None)
if os.path.isfile(abs_name):
if os.stat(abs_name).st_size < COPY_THRESHOLD:
shutil.copyfile(abs_name, destination_name)
else:
if not os.path.isfile(destination_name):
getLogger().info(
"Create symlink between {} and {}".format(
abs_name, destination_name
)
)
os.symlink(abs_name, destination_name)
else:
import distutils.dir_util
distutils.dir_util.copy_tree(abs_name, destination_name)
if os.path.isdir(destination_name) and field["md5"] == "directory":
return False
assert os.path.isfile(destination_name), "File {} cannot be retrieved".format(
destination_name
)
# verify the md5 matches the file downloaded
md5 = self._calculateMD5(destination_name, field["md5"], abs_name)
if md5 != field["md5"]:
getLogger().info(
"Source file {} is changed, ".format(location)
+ " updating MD5. "
+ "Please commit the updated json file."
)
field["md5"] = md5
return True
return False