SHARE
TWEET

Untitled

a guest Feb 20th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import subprocess
  3. import sys
  4.  
  5. def run_checksum(basedir, filename, output):
  6.   args = ['xxhsum', filename]
  7.   process = subprocess.Popen(args, stdout=output, close_fds=True, cwd=basedir)
  8.   if process.wait() != 0:
  9.     raise subprocess.CalledProcessError(process.returncode, args)
  10.  
  11. def main():
  12.   # TODO: Replace with the actual basedir of the backup directory
  13.   basedir = os.getcwd()
  14.   checksums_path = os.path.join(basedir, 'CHECKSUMS')
  15.  
  16.   with open(checksums_path, 'wb') as output:
  17.     for root, dirs, files in os.walk(basedir):
  18.       for fname in files:
  19.         cpath = os.path.join(root, fname)
  20.         if cpath == checksums_path:
  21.           continue
  22.  
  23.         rpath = os.path.relpath(cpath, basedir)
  24.         run_checksum(basedir, rpath, output)
  25.  
  26. if __name__ == '__main__':
  27.   sys.exit(main())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top