Advertisement
iklio

Untitled

Dec 26th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os, subprocess, shutil
  4. import sys, errno
  5.  
  6. def getKey(item):
  7.     return item[0]
  8.  
  9.  
  10.  
  11. if (len(sys.argv)<3):
  12.     print "destination source1 [source2]\n"
  13.     sys.exit(1)
  14. dest = sys.argv[1];
  15. if (not os.path.isdir(dest)):
  16.     print "Destination dir must exist!\n"
  17.     sys.exit(1)
  18. filelist = []
  19. for src in sys.argv[2:]:
  20.     for (dirpath, dirnames, filenames) in os.walk(src):
  21.         for d in dirnames:
  22.             reldir = os.path.relpath(os.path.join(dirpath, d), src)
  23.             try:
  24.                 os.makedirs(os.path.join(dest, reldir))
  25.             except OSError as exc:  # Python >2.5
  26.                 if exc.errno == errno.EEXIST and os.path.isdir(os.path.join(dest, reldir)):
  27.                     pass
  28.                 else:
  29.                     raise
  30.         for f in filenames:
  31.             absfile = os.path.join(dirpath, f)
  32.             relfile = os.path.relpath(absfile, src)
  33.             try:
  34.                 startblock = int(subprocess.check_output(['getfattr', '-n', 'user.ltfs.startblock', '--only-values', '--absolute-names', absfile]))
  35.             except:
  36.                 startblock = 0
  37.             #print "" + relfile + "  === " + str(startblock)
  38.             filelist.append((startblock, absfile, os.path.join(dest, relfile)))
  39.  
  40. filelist = sorted(filelist, key=getKey)
  41. for f in filelist:
  42.     print "" + str(f[0]) + " == " + f[1] + " to " + f[2]  + "\n"
  43.     shutil.copyfile(f[1], f[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement