11import argparse
2- import sys , os
2+ import os
3+ import sys
4+ from typing import Callable , Dict , List
35
46from . import menudiff
57from . import __version__
68
7- FMT_UNIFIED = ' unified'
8- FMT_CONTEXT = ' context'
9- FMT_HTML = ' html'
10- FMT_REPORT = ' report'
11- FMT_DEFAULT = FMT_UNIFIED
12- FMT_CHOICES = [FMT_UNIFIED , FMT_CONTEXT , FMT_HTML , FMT_REPORT ]
13-
14- SKIP_MODULE = ' module'
15- SKIP_COMMENT = ' comment'
16- SKIP_LABELS = ' labels'
17- SKIP_CHOICES = [SKIP_MODULE , SKIP_COMMENT , SKIP_LABELS ]
18-
19- SORT_INDEX = ' index'
20- SORT_NAME = ' name'
21- SORT_EXPRESSION = ' expression'
22- SORT_DEFAULT = SORT_INDEX
23- SORT_CHOICES = [SORT_INDEX , SORT_NAME , SORT_EXPRESSION ]
24-
25- DIFF_FUNCTIONS = {
9+ FMT_UNIFIED : str = " unified"
10+ FMT_CONTEXT : str = " context"
11+ FMT_HTML : str = " html"
12+ FMT_REPORT : str = " report"
13+ FMT_DEFAULT : str = FMT_UNIFIED
14+ FMT_CHOICES : List [ str ] = [FMT_UNIFIED , FMT_CONTEXT , FMT_HTML , FMT_REPORT ]
15+
16+ SKIP_MODULE : str = " module"
17+ SKIP_COMMENT : str = " comment"
18+ SKIP_LABELS : str = " labels"
19+ SKIP_CHOICES : List [ str ] = [SKIP_MODULE , SKIP_COMMENT , SKIP_LABELS ]
20+
21+ SORT_INDEX : str = " index"
22+ SORT_NAME : str = " name"
23+ SORT_EXPRESSION : str = " expression"
24+ SORT_DEFAULT : str = SORT_INDEX
25+ SORT_CHOICES : List [ str ] = [SORT_INDEX , SORT_NAME , SORT_EXPRESSION ]
26+
27+ DIFF_FUNCTIONS : Dict [ str , Callable ] = {
2628 FMT_UNIFIED : menudiff .unified_diff ,
2729 FMT_CONTEXT : menudiff .context_diff ,
2830 FMT_HTML : menudiff .html_diff ,
2931 FMT_REPORT : menudiff .report_diff ,
3032}
3133
32- def parse_args ():
34+
35+ def parse_args () -> argparse .Namespace :
3336 parser = argparse .ArgumentParser ()
34- parser .add_argument (' file' ,
37+ parser .add_argument (" file" ,
3538 nargs = 2 ,
3639 help = "XML menu files 'FILE1 FILE2'"
3740 )
38- parser .add_argument ('-f' , ' --format' ,
39- metavar = ' <format>' ,
41+ parser .add_argument ("-f" , " --format" ,
42+ metavar = " <format>" ,
4043 choices = FMT_CHOICES ,
4144 default = FMT_DEFAULT ,
42- help = "select output format, default is '{0 }'" . format ( FMT_DEFAULT )
45+ help = f "select output format, default is '{ FMT_DEFAULT } '"
4346 )
44- parser .add_argument ('-s' , ' --skip' ,
45- metavar = ' <mode>' ,
46- action = ' append' ,
47+ parser .add_argument ("-s" , " --skip" ,
48+ metavar = " <mode>" ,
49+ action = " append" ,
4750 choices = SKIP_CHOICES ,
4851 default = [],
4952 help = "skip information"
5053 )
51- parser .add_argument (' --sort' ,
52- metavar = ' <key>' ,
54+ parser .add_argument (" --sort" ,
55+ metavar = " <key>" ,
5356 choices = SORT_CHOICES ,
5457 default = SORT_DEFAULT ,
55- help = "select key for algorithm sorting, default is '{0 }'" . format ( SORT_DEFAULT )
58+ help = f "select key for algorithm sorting, default is '{ SORT_DEFAULT } '"
5659 )
57- parser .add_argument ('-d' , ' --dump' ,
58- action = ' store_true' ,
59- help = "dump the extracted intermediate content"
60+ parser .add_argument ("-d" , " --dump" ,
61+ action = " store_true" ,
62+ help = "dump the extracted intermediate content"
6063 )
61- parser .add_argument ('-o' ,
62- dest = ' ostream' ,
63- metavar = ' <file>' ,
64- type = argparse .FileType ('w' ),
64+ parser .add_argument ("-o" ,
65+ dest = " ostream" ,
66+ metavar = " <file>" ,
67+ type = argparse .FileType ("wt" ),
6568 default = sys .stdout ,
6669 help = "write output to file"
6770 )
68- parser .add_argument ('-v' , ' --verbose' ,
69- action = ' count' ,
71+ parser .add_argument ("-v" , " --verbose" ,
72+ action = " count" ,
7073 help = "increase output verbosity"
7174 )
72- parser .add_argument (' --version' ,
73- action = ' version' ,
75+ parser .add_argument (" --version" ,
76+ action = " version" ,
7477 version = "%(prog)s {0}" .format (__version__ )
7578 )
7679 return parser .parse_args ()
7780
78- def main ():
81+
82+ def main () -> int :
7983 args = parse_args ()
8084
81- from_file = args .file [0 ]
82- to_file = args .file [1 ]
85+ from_file : str = args .file [0 ]
86+ to_file : str = args .file [1 ]
8387
84- skip = []
88+ skip : List [ str ] = []
8589
8690 # Skip module specific attributes
8791 if SKIP_MODULE in args .skip :
88- skip .append (' uuid_firmware' )
89- skip .append (' n_modules' )
90- skip .append (' module_id' )
91- skip .append (' module_index' )
92+ skip .append (" uuid_firmware" )
93+ skip .append (" n_modules" )
94+ skip .append (" module_id" )
95+ skip .append (" module_index" )
9296
9397 # Skip comments
9498 if SKIP_COMMENT in args .skip :
95- skip .append (' comment' )
99+ skip .append (" comment" )
96100
97101 # Skip comments
98102 if SKIP_LABELS in args .skip :
99- skip .append (' labels' )
103+ skip .append (" labels" )
100104
101105 # Extract information from XMLs
102106 from_menu = menudiff .Menu (from_file )
@@ -121,5 +125,6 @@ def main():
121125
122126 return 0
123127
124- if __name__ == '__main__' :
128+
129+ if __name__ == "__main__" :
125130 sys .exit (main ())
0 commit comments