File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -42,14 +42,25 @@ def main():
4242 if args .print :
4343 print_kvk (kvkData , args .keys )
4444
45- if args .output :
46- outputfile = args .output
47- else :
48- outputfile = name + ".ldml"
49-
50- with open (outputfile , 'wb' ) as ldmlfile :
51- ldml = convert_ldml (kvkData )
52- output_ldml (ldmlfile , ldml )
45+ outputfile = args .output if args .output else f'{ name } .ldml'
46+
47+ dirname = os .path .dirname (outputfile )
48+ if not os .path .isdir (dirname ):
49+ if os .path .exists (dirname ):
50+ logging .error (f'km-kvk2ldml: error, `{ dirname } ` exists but is not a directory' )
51+ sys .exit (3 )
52+ os .makedirs (dirname )
53+
54+ try :
55+ with open (outputfile , 'wb' ) as ldmlfile :
56+ ldml = convert_ldml (kvkData )
57+ output_ldml (ldmlfile , ldml )
58+ except PermissionError :
59+ logging .error (f'km-kvk2ldml: error, permission denied writing file `{ outputfile } `' )
60+ sys .exit (4 )
61+ except IsADirectoryError :
62+ logging .error (f'km-kvk2ldml: error, cannot create file `{ outputfile } ` - it is a directory' )
63+ sys .exit (5 )
5364
5465
5566if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments