Commit 37c010cba06f635e37428b8d8b6d18beef75fc7b

Authored by Quillot Mathias
1 parent 85eea4a87e
Exists in master

Filter works well now

Showing 1 changed file with 20 additions and 10 deletions Side-by-side Diff

... ... @@ -3,34 +3,44 @@
3 3  
4 4 from utils import SubCommandRunner
5 5  
  6 +import core.data
  7 +
6 8 # Main parser
7 9 parser = argparse.ArgumentParser(description="manage files")
8 10 subparsers = parser.add_subparsers(title="actions")
9 11  
10   -
11   -
12 12 # Filter ids
13 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")
15   -parser_filter.add_argument("--filter", type=str, help="filter file [id_from] [id_to]")
  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)
16 17 parser_filter.set_defaults(which="filter")
17 18  
18 19 # Convert
19 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("--type-from", type=str, choices=["old-masseffect", "new-masseffect"], help="...")
22   -parser_convert.add_argument("--type", choices=["old-masseffect", "new-masseffect"])
  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)
23 24 parser_convert.set_defaults(which="convert")
24 25  
25   -
26 26 # Parse
27 27 args = parser.parse_args()
28 28  
29 29  
30 30  
31   -def filter_file(file_path, filter_path):
32   - pass
  31 +def filter_file(file, filter, outfile):
  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 45 def convert(file, type_from, type):
36 46 pass