Skip to content

Commit 02c75c5

Browse files
authored
Merge pull request #9523 from keymanapp/fix/linux/9522_nonExistingDir
fix(linux): Fix exception in km-kvk2ldml
2 parents d7a3e8a + 940d5be commit 02c75c5

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

linux/keyman-config/km-kvk2ldml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff 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

5566
if __name__ == "__main__":

0 commit comments

Comments
 (0)