def fetch(repo: RepositoryContractWrapper, commit_id: int): """Replace the current local files, their contents and the directory structure with the ones specified at the given commit""" for root, dirs, files in os.walk("./"): for name in files: filepath = os.path.join(root, name) if filepath == "./.repodata.json": # Don't delete the repodata file - that is going to end badly continue os.remove(filepath) for directory in dirs: fulldir = os.path.join(root, directory) os.rmdir(fulldir) file_ids = repo.get_files_from_commit(commit_id) ipfs = ipfshttpclient.connect() for fid in file_ids: filedata = repo.get_file(fid) filepath = filedata[0] ipfshash = filedata[1] os.makedirs(os.path.dirname(filepath), exist_ok=True) with open(filepath, "wb") as outfile: outfile.write(ipfs.cat(ipfshash))
def get_all_files_from_commit(repo: RepositoryContractWrapper, commit_id): file_id_list = repo.get_files_from_commit(commit_id) files = [] for f in file_id_list: files.append(repo.get_file(f)) return files