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:
37 with open('../options.c') as fh:
39 m = re.search(r"argstr\[x\+\+\] = '([^.ie])'", line)
41 short_no_arg[m.group(1)] = 1
45 m = re.search(r'asprintf\([^,]+, "-([a-zA-Z0-9])\%l?[ud]"', line)
47 short_with_num[m.group(1)] = 1
51 m = re.search(r'args\[ac\+\+\] = "--([^"=]+)"', line)
53 last_long_opt = m.group(1)
54 if last_long_opt not in long_opts:
55 long_opts[last_long_opt] = 0
61 m = re.search(r'args\[ac\+\+\] = safe_arg\("", ([^[("\s]+)\);', line)
63 long_opts[last_long_opt] = 2
66 if 'args[ac++] = ' in line:
69 m = re.search(r'return "--([^"]+-dest)";', line)
71 long_opts[m.group(1)] = 2
75 m = re.search(r'asprintf\([^,]+, "--([^"=]+)=', line)
77 m = re.search(r'args\[ac\+\+\] = "--([^"=]+)=', line)
79 m = re.search(r'args\[ac\+\+\] = safe_arg\("--([^"=]+)"', line)
81 m = re.search(r'fmt = .*: "--([^"=]+)=', line)
83 long_opts[m.group(1)] = 1
86 long_opts['files-from'] = 3
89 ### START of options data produced by the cull-options script. ###
91 # To disable a short-named option, add its letter to this string:
94 txt += str_assign('short_disabled', 's') + "\n"
95 txt += '# These are also disabled when the restricted dir is not "/":\n'
96 txt += str_assign('short_disabled_subdir', 'KLk') + "\n"
97 txt += '# These are all possible short options that we will accept (when not disabled above):\n'
98 txt += str_assign('short_no_arg', ''.join(sorted(short_no_arg)), 'DO NOT REMOVE ANY')
99 txt += str_assign('short_with_num', ''.join(sorted(short_with_num)), 'DO NOT REMOVE ANY')
102 # To disable a long-named option, change its value to a -1. The values mean:
103 # 0 = the option has no arg; 1 = the arg doesn't need any checking; 2 = only
104 # check the arg when receiving; and 3 = always check the arg.
110 print("long_opts = {")
113 print("our %long_opt = (")
116 for opt in sorted(long_opts):
117 if opt.startswith(('min-', 'max-')):
121 print(' ', repr(opt) + sep, str(val) + ',')
127 print("\n### END of options data produced by the cull-options script. ###")
130 def str_assign(name, val, comment=None):
131 comment = ' # ' + comment if comment else ''
133 return name + ' = ' + repr(val) + comment + "\n"
134 return 'our $' + name + ' = ' + repr(val) + ';' + comment + "\n"
137 if __name__ == '__main__':
138 parser = argparse.ArgumentParser(description="Output culled rsync options for rrsync.", add_help=False)
139 out_group = parser.add_mutually_exclusive_group()
140 out_group.add_argument('--perl', action='store_true', help="Output perl code.")
141 out_group.add_argument('--python', action='store_true', help="Output python code (the default).")
142 parser.add_argument('--help', '-h', action='help', help="Output this help message and exit.")
143 args = parser.parse_args()