26
26
Options:
27
27
-a --all import all modules
28
28
-h --help print help
29
+ -o file
30
+ --output file output file
29
31
'''
30
32
output_header = '//https://github.com/rust-lang-ja/ac-library-rs\n '
31
- opt_list = ['help' , 'all' ]
33
+ opt_list = ['help' , 'all' , 'output=' ]
32
34
output_list_all = ('convolution' , 'dsu' , 'fenwicktree' , 'lazysegtree' , 'math' ,
33
35
'maxflow' , 'mincostflow' , 'modint' , 'scc' , 'segtree' ,
34
36
'string' , 'twosat' ,
44
46
'segtree' : ('internal_bit' , 'internal_type_traits' ,),
45
47
'twosat' : ('internal_scc' ,), }
46
48
src_path = 'src/'
49
+ output_path = None
47
50
48
51
49
52
def output_file (filename ):
50
53
global src_path
51
54
52
55
res = []
53
- with open (src_path + filename + '.rs' , 'r' ) as f :
56
+ with open (src_path + filename + '.rs' , 'r' , encoding = 'utf-8' , newline = '' ) as f :
54
57
res .append ('pub mod {} {{' .format (filename ))
55
58
56
59
for line in f :
@@ -61,7 +64,7 @@ def output_file(filename):
61
64
62
65
63
66
try :
64
- opts , args = getopt .getopt (sys .argv [1 :], 'ah ' , opt_list )
67
+ opts , args = getopt .getopt (sys .argv [1 :], 'aho: ' , opt_list )
65
68
except getopt .GetoptError as e :
66
69
print (e )
67
70
print (usage )
@@ -77,6 +80,8 @@ def output_file(filename):
77
80
sys .exit (0 )
78
81
elif o == '--all' or o == '-a' :
79
82
args = list (output_list_all )
83
+ elif o == '--output' or o == '-o' :
84
+ output_path = v
80
85
81
86
output_list = set ()
82
87
@@ -108,11 +113,14 @@ def output_file(filename):
108
113
# rustfmt
109
114
with tempfile .TemporaryDirectory () as temp_dir :
110
115
temp_file = temp_dir + '/output.rs'
111
- with open (temp_file , 'w' ) as f :
116
+ with open (temp_file , 'w' , encoding = 'utf-8' , newline = '' ) as f :
112
117
print (output_header , file = f )
113
118
for i in output_data :
114
119
print (i , file = f )
115
120
output_data = subprocess .run (["rustfmt" , temp_file ], check = True )
116
- with open (temp_file , 'r' ) as f :
121
+ with open (temp_file , 'r' , encoding = 'utf-8' , newline = '' ) as f :
122
+ wf = open (output_path , 'w' , encoding = 'utf-8' , newline = '' ) if output_path is not None else sys .stdout
117
123
for line in f :
118
- print (line , end = "" )
124
+ print (line , end = '' , file = wf )
125
+ if output_path is not None :
126
+ wf .close ()
0 commit comments