1- import pathlib
1+ import pathlib , sys
22
33from sourcehold .tool .convert .aiv .exports import to_json
44from sourcehold .tool .convert .aiv .imports import from_json
@@ -13,7 +13,7 @@ def convert_aiv(args):
1313 return None
1414
1515 inp = args .input
16- if not pathlib .Path (inp ).exists ():
16+ if inp != '-' and not pathlib .Path (inp ).exists ():
1717 raise Exception (f"file does not exist: { inp } " )
1818 inp_invert_y = False
1919 inp_format = args .from_format
@@ -45,7 +45,10 @@ def convert_aiv(args):
4545 if out_format == "json" :
4646 args .output = "-"
4747 elif out_format == "aiv" :
48- args .output = f"{ pathlib .Path (inp ).name } .aiv"
48+ if inp == "-" :
49+ args .output = "output.aiv"
50+ else :
51+ args .output = f"{ pathlib .Path (inp ).name } .aiv"
4952 #args.output = f"{pathlib.Path(inp).name}.json"
5053
5154 if args .debug :
@@ -55,13 +58,17 @@ def convert_aiv(args):
5558
5659 conv = to_json (path = inp , include_extra = args .extra , report = args .debug , invert_y = out_invert_y , skip_keep = out_skip_keep )
5760 if args .output == "-" :
58- print (conv )
61+ sys .stdout .write (conv )
62+ sys .stdout .flush ()
5963 else :
6064 pathlib .Path (args .output ).write_text (conv )
6165 elif inp_format .startswith ('json' ) and out_format .startswith ("aiv" ):
62- conv = from_json (path = inp , report = args .debug , invert_y = inp_invert_y )
66+ if inp == "-" :
67+ conv = from_json (f = sys .stdin , report = args .debug , invert_y = inp_invert_y )
68+ else :
69+ conv = from_json (path = inp , report = args .debug , invert_y = inp_invert_y )
6370 conv .to_file (args .output )
6471 else :
65- raise NotImplementedError (f"combination of in -format '{ inp_format } ' and out -format '{ out_format } ' not implemented" )
72+ raise NotImplementedError (f"combination of from -format '{ inp_format } ' and to -format '{ out_format } ' not implemented" )
6673
6774 return True
0 commit comments