Commit 0baf1624addfef18c0c8b5f2d65017d803c0ad35
1 parent
37c010cba0
Exists in
master
Better main organisation of the volia.data module
Showing 1 changed file with 22 additions and 19 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 | 6 | import core.data |
7 | 7 | ||
8 | # Main parser | ||
9 | parser = argparse.ArgumentParser(description="manage files") | ||
10 | subparsers = parser.add_subparsers(title="actions") | ||
11 | 8 | ||
12 | # Filter ids | ||
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", required=True) | ||
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) | ||
17 | parser_filter.set_defaults(which="filter") | ||
18 | 9 | ||
19 | # Convert | ||
20 | parser_convert = subparsers.add_parser("convert", help="convert a file") | ||
21 | parser_convert.add_argument("--file", type=str, help="...", required=True) | ||
22 | parser_convert.add_argument("--type-from", type=str, choices=["old-masseffect", "new-masseffect"], help="...", required=True) | ||
23 | parser_convert.add_argument("--type", choices=["old-masseffect", "new-masseffect"], required=True) | ||
24 | parser_convert.set_defaults(which="convert") | ||
25 | 10 | ||
26 | # Parse | ||
27 | args = parser.parse_args() | ||
28 | 11 | ||
29 | |||
30 | |||
31 | def filter_file(file, filter, outfile): | 12 | def filter_file(file, filter, outfile): |
32 | file_path = file | 13 | file_path = file |
33 | filter_path = filter | 14 | filter_path = filter |
34 | file_data = core.data.read_id_values(file_path) | 15 | file_data = core.data.read_id_values(file_path) |
35 | filter_data = core.data.read_lst(filter_path) | 16 | filter_data = core.data.read_lst(filter_path) |
36 | 17 | ||
37 | with open(outfile, "w") as out: | 18 | with open(outfile, "w") as out: |
38 | for id_ in filter_data: | 19 | for id_ in filter_data: |
39 | core.data.write_line(id_, file_data[id_], out) | 20 | core.data.write_line(id_, file_data[id_], out) |
40 | 21 | ||
41 | 22 | ||
42 | 23 | ||
43 | 24 | ||
44 | 25 | ||
45 | def convert(file, type_from, type): | 26 | def convert(file, type_from, type): |
46 | pass | 27 | pass |
47 | 28 | ||
48 | 29 | ||
49 | if __name__ == "__main__": | 30 | if __name__ == "__main__": |
31 | # Main parser | ||
32 | parser = argparse.ArgumentParser(description="manage files") | ||
33 | subparsers = parser.add_subparsers(title="actions") | ||
34 | |||
35 | # Filter ids | ||
36 | parser_filter = subparsers.add_parser("filter", help="filter a file") | ||
37 | parser_filter.add_argument("--file", type=str, help="path of the file to filter", required=True) | ||
38 | parser_filter.add_argument("--filter", type=str, help="filter file [id_from] [id_to]", required=True) | ||
39 | parser_filter.add_argument("--outfile", type=str, help="output file", required=True) | ||
40 | parser_filter.set_defaults(which="filter") |