Commit 37c010cba06f635e37428b8d8b6d18beef75fc7b
1 parent
85eea4a87e
Exists in
master
Filter works well now
Showing 1 changed file with 20 additions and 10 deletions Inline Diff
volia/data.py
1 | import argparse | 1 | import argparse |
2 | import sys | 2 | import sys |
3 | 3 | ||
4 | from utils import SubCommandRunner | 4 | from utils import SubCommandRunner |
5 | 5 | ||
6 | import core.data | ||
7 | |||
6 | # Main parser | 8 | # Main parser |
7 | parser = argparse.ArgumentParser(description="manage files") | 9 | parser = argparse.ArgumentParser(description="manage files") |
8 | subparsers = parser.add_subparsers(title="actions") | 10 | subparsers = parser.add_subparsers(title="actions") |
9 | 11 | ||
10 | |||
11 | |||
12 | # Filter ids | 12 | # Filter ids |
13 | parser_filter = subparsers.add_parser("filter", help="filter a file") | 13 | parser_filter = subparsers.add_parser("filter", help="filter a file") |
14 | parser_filter.add_argument("--file", type=str, help="path of the file to filter") | 14 | parser_filter.add_argument("--file", type=str, help="path of the file to filter", required=True) |
15 | parser_filter.add_argument("--filter", type=str, help="filter file [id_from] [id_to]") | 15 | parser_filter.add_argument("--filter", type=str, help="filter file [id_from] [id_to]", required=True) |
16 | parser_filter.add_argument("--outfile", type=str, help="output file", required=True) | ||
16 | parser_filter.set_defaults(which="filter") | 17 | parser_filter.set_defaults(which="filter") |
17 | 18 | ||
18 | # Convert | 19 | # Convert |
19 | parser_convert = subparsers.add_parser("convert", help="convert a file") | 20 | parser_convert = subparsers.add_parser("convert", help="convert a file") |
20 | parser_convert.add_argument("--file", type=str, help="...") | 21 | parser_convert.add_argument("--file", type=str, help="...", required=True) |
21 | parser_convert.add_argument("--type-from", type=str, choices=["old-masseffect", "new-masseffect"], help="...") | 22 | parser_convert.add_argument("--type-from", type=str, choices=["old-masseffect", "new-masseffect"], help="...", required=True) |
22 | parser_convert.add_argument("--type", choices=["old-masseffect", "new-masseffect"]) | 23 | parser_convert.add_argument("--type", choices=["old-masseffect", "new-masseffect"], required=True) |
23 | parser_convert.set_defaults(which="convert") | 24 | parser_convert.set_defaults(which="convert") |
24 | 25 | ||
25 | |||
26 | # Parse | 26 | # Parse |
27 | args = parser.parse_args() | 27 | args = parser.parse_args() |
28 | 28 | ||
29 | 29 | ||
30 | 30 | ||
31 | def filter_file(file_path, filter_path): | 31 | def filter_file(file, filter, outfile): |
32 | pass | 32 | file_path = file |
33 | filter_path = filter | ||
34 | file_data = core.data.read_id_values(file_path) | ||
35 | filter_data = core.data.read_lst(filter_path) | ||
33 | 36 | ||
37 | with open(outfile, "w") as out: | ||
38 | for id_ in filter_data: | ||
39 | core.data.write_line(id_, file_data[id_], out) | ||
40 | |||
41 | |||
42 | |||
43 | |||
34 | 44 | ||
35 | def convert(file, type_from, type): | 45 | def convert(file, type_from, type): |
36 | pass | 46 | pass |
37 | 47 | ||
38 | 48 | ||
39 | if __name__ == "__main__": | 49 | if __name__ == "__main__": |
40 | runner = SubCommandRunner({ | 50 | runner = SubCommandRunner({ |
41 | "convert" : convert, | 51 | "convert" : convert, |
42 | "filter": filter_file, | 52 | "filter": filter_file, |
43 | }) | 53 | }) |