| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
import re, fileinput, argparse |
| 17 |
|
| 18 |
NAME_ID_RE = re.compile(r'^(\w+):[^:]+:(\d+)') |
| 19 |
|
| 20 |
def main(): |
| 21 |
maps = [ ] |
| 22 |
for line in fileinput.input(args.files): |
| 23 |
m = NAME_ID_RE.match(line) |
| 24 |
if not m: |
| 25 |
continue |
| 26 |
if args.to: |
| 27 |
pair = (m[1], m[2]) |
| 28 |
else: |
| 29 |
pair = (m[2], m[1]) |
| 30 |
maps.append(':'.join(pair)) |
| 31 |
print(','.join(maps)) |
| 32 |
|
| 33 |
|
| 34 |
if __name__ == '__main__': |
| 35 |
parser = argparse.ArgumentParser(description="Output usermap or groupmap args for rsync.", add_help=False) |
| 36 |
action = parser.add_argument_group() |
| 37 |
action = parser.add_mutually_exclusive_group(required=True) |
| 38 |
action.add_argument("--from", action="store_true", help="Output the map for use on the sending side.") |
| 39 |
action.add_argument("--to", action="store_true", help="Output the map for use on the receiving side.") |
| 40 |
parser.add_argument("--help", "-h", action="help", help="Output this help message and exit.") |
| 41 |
parser.add_argument("files", metavar="FILE", default='-', nargs='*', help="The file(s) that hold the name & id pairs. Defaults to stdin.") |
| 42 |
args = parser.parse_args() |
| 43 |
main() |
| 44 |
|
| 45 |
|