Created
February 18, 2019 17:41
-
-
Save abg/860bf39eaed7fd23b3cf9b44a1febea3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
import sys | |
def run_checksum(basedir, filename, output): | |
args = ['xxhsum', filename] | |
process = subprocess.Popen(args, stdout=output, close_fds=True, cwd=basedir) | |
if process.wait() != 0: | |
raise subprocess.CalledProcessError(process.returncode, args) | |
def main(): | |
# TODO: Replace with the actual basedir of the backup directory | |
basedir = os.getcwd() | |
checksums_path = os.path.join(basedir, 'CHECKSUMS') | |
with open(checksums_path, 'wb') as output: | |
for root, dirs, files in os.walk(basedir): | |
for fname in files: | |
cpath = os.path.join(root, fname) | |
if cpath == checksums_path: | |
continue | |
rpath = os.path.relpath(cpath, basedir) | |
run_checksum(basedir, rpath, output) | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment