2 # This script takes an input of filenames and outputs a set of include/exclude
3 # directives that can be used by rsync to copy just the indicated files using
4 # an --exclude-from=FILE or -f'. FILE' option. To be able to delete files on
5 # the receiving side, either use --delete-excluded or change the exclude (-)
6 # rules to hide filter rules (H) that only affect the sending side.
8 import os, fileinput, argparse
12 for line in fileinput.input(args.files):
13 dirs = line.strip().lstrip('/').split('/')
16 for j in range(1, len(dirs)):
19 path = '/' + '/'.join(dirs[:j]) + '/'
23 print('+', '/' + '/'.join(dirs))
25 for path in sorted(paths):
26 print('-', path + '*')
30 if __name__ == '__main__':
31 parser = argparse.ArgumentParser(description="Transform a list of files into a set of include/exclude rules.", add_help=False)
32 parser.add_argument("--help", "-h", action="help", help="Output this help message and exit.")
33 parser.add_argument("files", metavar="FILE", default='-', nargs='*', help="The file(s) that hold the pathnames to translate. Defaults to stdin.")
34 args = parser.parse_args()