2 # This script outputs either perl or python code that parses all possible options
3 # that the code in options.c might send to the server. The resulting code is then
4 # included in the rrsync script.
9 short_with_num = { '@': 1 }
10 long_opts = { # These include some extra long-args that BackupPC uses:
36 with open('../options.c') as fh:
38 m = re.search(r"argstr\[x\+\+\] = '([^.ie])'", line)
40 short_no_arg[m.group(1)] = 1
44 m = re.search(r'asprintf\([^,]+, "-([a-zA-Z0-9])\%l?[ud]"', line)
46 short_with_num[m.group(1)] = 1
50 m = re.search(r'args\[ac\+\+\] = "--([^"=]+)"', line)
52 last_long_opt = m.group(1)
53 if last_long_opt not in long_opts:
54 long_opts[last_long_opt] = 0
60 m = re.search(r'args\[ac\+\+\] = safe_arg\("", ([^[("\s]+)\);', line)
62 long_opts[last_long_opt] = 2
65 if 'args[ac++] = ' in line:
68 m = re.search(r'return "--([^"]+-dest)";', line)
70 long_opts[m.group(1)] = 2
74 m = re.search(r'asprintf\([^,]+, "--([^"=]+)=', line)
76 m = re.search(r'args\[ac\+\+\] = "--([^"=]+)=', line)
78 m = re.search(r'args\[ac\+\+\] = safe_arg\("--([^"=]+)"', line)
80 m = re.search(r'fmt = .*: "--([^"=]+)=', line)
82 long_opts[m.group(1)] = 1
85 long_opts['files-from'] = 3
88 ### START of options data produced by the cull-options script. ###
90 # To disable a short-named option, add its letter to this string:
93 txt += str_assign('short_disabled', 's') + "\n"
94 txt += '# These are also disabled when the restricted dir is not "/":\n'
95 txt += str_assign('short_disabled_subdir', 'KLk') + "\n"
96 txt += '# These are all possible short options that we will accept (when not disabled above):\n'
97 txt += str_assign('short_no_arg', ''.join(sorted(short_no_arg)), 'DO NOT REMOVE ANY')
98 txt += str_assign('short_with_num', ''.join(sorted(short_with_num)), 'DO NOT REMOVE ANY')
101 # To disable a long-named option, change its value to a -1. The values mean:
102 # 0 = the option has no arg; 1 = the arg doesn't need any checking; 2 = only
103 # check the arg when receiving; and 3 = always check the arg.
109 print("long_opts = {")
112 print("our %long_opt = (")
115 for opt in sorted(long_opts):
116 if opt.startswith(('min-', 'max-')):
120 print(' ', repr(opt) + sep, str(val) + ',')
126 print("\n### END of options data produced by the cull-options script. ###")
129 def str_assign(name, val, comment=None):
130 comment = ' # ' + comment if comment else ''
132 return name + ' = ' + repr(val) + comment + "\n"
133 return 'our $' + name + ' = ' + repr(val) + ';' + comment + "\n"
136 if __name__ == '__main__':
137 parser = argparse.ArgumentParser(description="Output culled rsync options for rrsync.", add_help=False)
138 out_group = parser.add_mutually_exclusive_group()
139 out_group.add_argument('--perl', action='store_true', help="Output perl code.")
140 out_group.add_argument('--python', action='store_true', help="Output python code (the default).")
141 parser.add_argument('--help', '-h', action='help', help="Output this help message and exit.")
142 args = parser.parse_args()