in xar/py_util.py [0:0]
def copy_installation(self, src_paths, dst_paths, force=False):
"""
Copies an installation of this Wheel in `src_paths` to `dst_paths`.
Takes care to fix up the 'RECORD' file to reflect the new installtion
location.
"""
if self.is_wheel_archive(self.distribution.location):
raise self.Error("copy_installation() does not work with archives")
# Determine the src and dst roots.
if self.is_purelib():
src_root = src_paths["purelib"]
dst_root = dst_paths["purelib"]
else:
src_root = src_paths["platlib"]
dst_root = dst_paths["platlib"]
assert src_root[:1] == os.sep and dst_root[:1] == os.sep
# Create or overwrite the dst RECORD file.
dst_records_path = os.path.join(dst_root, self.distinfo_name(), self.RECORD)
if os.path.exists(dst_records_path) and not force:
raise self.Error("'RECORD' already exists: '%s'" % self.name)
xar_util.safe_mkdir(os.path.dirname(dst_records_path))
with open(dst_records_path, mode="w+t") as f:
# Loop over each record in the source distribution.
dst_records = csv.writer(f)
for record, record_hash, record_size in self.records():
# Get the normalized absolute path for the source record
src_record = os.path.normpath(os.path.join(src_root, record))
# Determine what 'kind' the record is, and get dst_record path.
kind, prefix = self._determine_kind(
src_root, src_paths, dst_paths, src_record
)
rel_record = src_record[len(prefix) + 1 :]
dst_record = os.path.join(dst_paths[kind], rel_record)
# Update the destination RECORD file.
new_record = os.path.relpath(dst_record, dst_root)
dst_records.writerow((new_record, record_hash, record_size))
# Don't write the records file, since we are recreating it.
if dst_record == dst_records_path:
continue
# Copy or overwrite the record
if os.path.exists(dst_record) and not force:
if not does_sha256_match(dst_record, record_hash):
raise self.Error("'%s' already exists" % dst_record)
xar_util.safe_mkdir(os.path.dirname(dst_record))
shutil.copy2(src_record, dst_record)