Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os, subprocess, shutil
- import sys, errno
- def getKey(item):
- return item[0]
- if (len(sys.argv)<3):
- print "destination source1 [source2]\n"
- sys.exit(1)
- dest = sys.argv[1];
- if (not os.path.isdir(dest)):
- print "Destination dir must exist!\n"
- sys.exit(1)
- filelist = []
- for src in sys.argv[2:]:
- for (dirpath, dirnames, filenames) in os.walk(src):
- for d in dirnames:
- reldir = os.path.relpath(os.path.join(dirpath, d), src)
- try:
- os.makedirs(os.path.join(dest, reldir))
- except OSError as exc: # Python >2.5
- if exc.errno == errno.EEXIST and os.path.isdir(os.path.join(dest, reldir)):
- pass
- else:
- raise
- for f in filenames:
- absfile = os.path.join(dirpath, f)
- relfile = os.path.relpath(absfile, src)
- try:
- startblock = int(subprocess.check_output(['getfattr', '-n', 'user.ltfs.startblock', '--only-values', '--absolute-names', absfile]))
- except:
- startblock = 0
- #print "" + relfile + " === " + str(startblock)
- filelist.append((startblock, absfile, os.path.join(dest, relfile)))
- filelist = sorted(filelist, key=getKey)
- for f in filelist:
- print "" + str(f[0]) + " == " + f[1] + " to " + f[2] + "\n"
- shutil.copyfile(f[1], f[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement