support: added install_deps_ubuntu.sh
[rsync.git] / support / files-to-excludes
1 #!/usr/bin/env python3
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.
7
8 import os, fileinput, argparse
9
10 def main():
11     paths = set()
12     for line in fileinput.input(args.files):
13         dirs = line.strip().lstrip('/').split('/')
14         if not dirs:
15             continue
16         for j in range(1, len(dirs)):
17             if dirs[j] == '':
18                 continue
19             path = '/' + '/'.join(dirs[:j]) + '/'
20             if path not in paths:
21                 print('+', path)
22                 paths.add(path)
23         print('+', '/' + '/'.join(dirs))
24
25     for path in sorted(paths):
26         print('-', path + '*')
27     print('-', '/*')
28
29
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()
35     main()
36
37 # vim: sw=4 et