def main(): opts = cmd_opt_parse() multi_cmd_patterns, _ = fetch_cmd_patterns(opts.pattern, opts.pattern_file, opts.pattern_sep) ofname = opts.output if opts.output else opts.input + ".new" of = open(ofname, "w") filtered_fname = opts.filtered if opts.filtered else opts.input + ".filtered" filtered_f = open(filtered_fname, "w") readable_fname = opts.readable if opts.readable else opts.input + ".filtered_readable" readable_f = open(readable_fname, "w") with open(opts.input) as f: cmd_parser = CommandParser(f) for cmds, raw_buf in cmd_parser: old_part_num = len(cmds) matched, skip = match_and_filter_cmds(cmds, multi_cmd_patterns, filtered_f, readable_f) if matched: output_file = filtered_f if not skip: readable_f.write(" ".join(cmds) + "\n") else: output_file = of if not skip: if old_part_num != len(cmds): raw_buf = format_cmd_buf(cmds) write_array(raw_buf, output_file) of.close() filtered_f.close() readable_f.close()
def main(): opts = cmd_opt_parse() multi_cmd_patterns, key_patterns = fetch_cmd_patterns(opts.pattern, opts.pattern_file, opts.pattern_sep) ofname = opts.output if opts.output else opts.input + '.fetch' of = open(ofname, 'w') readable_fname = opts.readable if opts.readable else \ opts.input + '.fetch_readable' readable_f = open(readable_fname, 'w') filtered_fname = opts.filtered if opts.filtered else \ opts.input + '.filtered' filtered_f = open(filtered_fname, 'w') filtered_rfname = opts.input + '.filtered_readable' filtered_rf = open(filtered_rfname, 'w') # fetch all commands on the specified keys matched_cmds = [] with open(opts.input) as f: cmd_parser = CommandParser(f) # iterate each command in AOF for cmds, raw_buf in cmd_parser: key = cmds[1] for key_pattern in key_patterns: if not key_pattern.match(key): continue matched_cmds.append((cmds, raw_buf)) # filter specified commands for cmds, raw_buf in matched_cmds: old_part_num = len(cmds) matched, skip = match_and_filter_cmds(cmds, multi_cmd_patterns, filtered_f, filtered_rf) if matched: output_f = filtered_f output_readable_f = filtered_rf else: output_f = of output_readable_f = readable_f if not skip: if old_part_num != len(cmds): raw_buf = format_cmd_buf(cmds) write_array(raw_buf, output_f) output_readable_f.write(' '.join(cmds) + '\n') of.close() readable_f.close() filtered_f.close()
def main(): opts = cmd_opt_parse() multi_cmd_patterns, key_patterns = fetch_cmd_patterns( opts.pattern, opts.pattern_file, opts.pattern_sep) ofname = opts.output if opts.output else opts.input + '.fetch' of = open(ofname, 'w') readable_fname = opts.readable if opts.readable else \ opts.input + '.fetch_readable' readable_f = open(readable_fname, 'w') filtered_fname = opts.filtered if opts.filtered else \ opts.input + '.filtered' filtered_f = open(filtered_fname, 'w') filtered_rfname = opts.input + '.filtered_readable' filtered_rf = open(filtered_rfname, 'w') # fetch all commands on the specified keys matched_cmds = [] with open(opts.input) as f: cmd_parser = CommandParser(f) # iterate each command in AOF for cmds, raw_buf in cmd_parser: key = cmds[1] for key_pattern in key_patterns: if not key_pattern.match(key): continue matched_cmds.append((cmds, raw_buf)) # filter specified commands for cmds, raw_buf in matched_cmds: old_part_num = len(cmds) matched, skip = match_and_filter_cmds(cmds, multi_cmd_patterns, filtered_f, filtered_rf) if matched: output_f = filtered_f output_readable_f = filtered_rf else: output_f = of output_readable_f = readable_f if not skip: if old_part_num != len(cmds): raw_buf = format_cmd_buf(cmds) write_array(raw_buf, output_f) output_readable_f.write(' '.join(cmds) + '\n') of.close() readable_f.close() filtered_f.close()
def main(): opts = cmd_opt_parse() multi_cmd_patterns, _ = fetch_cmd_patterns(opts.pattern, opts.pattern_file, opts.pattern_sep) ofname = opts.output if opts.output else opts.input + '.new' of = open(ofname, 'w') filtered_fname = opts.filtered if opts.filtered else \ opts.input + '.filtered' filtered_f = open(filtered_fname, 'w') readable_fname = opts.readable if opts.readable else \ opts.input + '.filtered_readable' readable_f = open(readable_fname, 'w') with open(opts.input) as f: cmd_parser = CommandParser(f) for cmds, raw_buf in cmd_parser: old_part_num = len(cmds) matched, skip = match_and_filter_cmds(cmds, multi_cmd_patterns, filtered_f, readable_f) if matched: output_file = filtered_f if not skip: readable_f.write(' '.join(cmds) + '\n') else: output_file = of if not skip: if old_part_num != len(cmds): raw_buf = format_cmd_buf(cmds) write_array(raw_buf, output_file) of.close() filtered_f.close() readable_f.close()