@@ -21,61 +21,77 @@ def main():
2121 # get arguments and invoke the conversion routines
2222 #
2323
24- parser = argparse .ArgumentParser (
25- description = 'Convert a text JSON/JData file to a binary JSON/JData file and vice versa.' )
24+ parser = argparse .ArgumentParser (description = "Convert a text JSON/JData file to a binary JSON/JData file and vice versa." )
2625
2726 parser .add_argument (
28- 'file' , nargs = '+' ,
29- help = 'path to a text-JData (json/jdt/jnii/jmsh/jnirs) file or a binary JData (bjd/jdb/bnii/bmsh/bnirs) file' )
27+ "file" ,
28+ nargs = "+" ,
29+ help = "path to a text-JData (json/jdt/jnii/jmsh/jnirs) file or a binary JData (bjd/jdb/bnii/bmsh/bnirs) file" ,
30+ )
3031 parser .add_argument (
31- '-f' , '--force' , action = 'store_const' , const = True ,
32- default = False , help = 'overwrite existing files when converting' )
32+ "-f" ,
33+ "--force" ,
34+ action = "store_const" ,
35+ const = True ,
36+ default = False ,
37+ help = "overwrite existing files when converting" ,
38+ )
3339 parser .add_argument (
34- '-r' , '--remove_input' , action = 'store_const' , const = True ,
35- default = False , help = 'delete the input file name after conversion' )
40+ "-r" ,
41+ "--remove_input" ,
42+ action = "store_const" ,
43+ const = True ,
44+ default = False ,
45+ help = "delete the input file name after conversion" ,
46+ )
3647 parser .add_argument (
37- '-c' , '--compression' , default = "" , help = 'set compression method (zlib,gzip,lzma,lz4)' )
48+ "-c" ,
49+ "--compression" ,
50+ default = "" ,
51+ help = "set compression method (zlib,gzip,lzma,lz4)" ,
52+ )
3853
3954 args = parser .parse_args ()
4055
4156 for path in args .file :
4257 spl = os .path .splitext (path )
4358 ext = spl [1 ].lower ()
4459
45- if ( ext in jext ['t' ]) :
46- dest = spl [0 ] + ' .jdb'
60+ if ext in jext ["t" ] :
61+ dest = spl [0 ] + " .jdb"
4762 try :
4863 if os .path .exists (dest ) and not args .force :
49- raise Exception (' File {} already exists.' .format (dest ))
64+ raise Exception (" File {} already exists." .format (dest ))
5065 data = load (path )
51- if ( len (args .compression )> 0 ) :
52- save (data ,dest ,{ ' compression' : args .compression })
66+ if len (args .compression ) > 0 :
67+ save (data , dest , { " compression" : args .compression })
5368 else :
54- save (data ,dest )
69+ save (data , dest )
5570 if args .remove_input :
5671 os .remove (path )
5772 except Exception as e :
58- print (' Error: {}' .format (e ))
73+ print (" Error: {}" .format (e ))
5974 sys .exit (1 )
6075
61- elif ( ext in jext ['b' ]) :
62- dest = spl [0 ] + ' .json'
76+ elif ext in jext ["b" ] :
77+ dest = spl [0 ] + " .json"
6378 try :
6479 if os .path .exists (dest ) and not args .force :
65- raise Exception (' File {} already exists.' .format (dest ))
80+ raise Exception (" File {} already exists." .format (dest ))
6681 data = load (path )
67- if ( len (args .compression )> 0 ) :
68- save (data ,dest ,{ ' compression' : args .compression })
82+ if len (args .compression ) > 0 :
83+ save (data , dest , { " compression" : args .compression })
6984 else :
70- save (data ,dest )
85+ save (data , dest )
7186 if args .remove_input :
7287 os .remove (path )
7388 except RuntimeError as e :
74- print (' Error: {}' .format (e ))
89+ print (" Error: {}" .format (e ))
7590 sys .exit (1 )
7691 else :
77- print (' Unsupported file extension on file: {}' .format (path ))
92+ print (" Unsupported file extension on file: {}" .format (path ))
7893 sys .exit (1 )
7994
80- if __name__ == '__main__' :
95+
96+ if __name__ == "__main__" :
8197 main ()
0 commit comments