-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfile_converter.py
executable file
·54 lines (39 loc) · 1.36 KB
/
file_converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
##
##
## Aesthetic Integration Ltd.
## Copyright 2016
##
## file_converter.py
##
##
import argparse, sys, ntpath, subprocess, glob
from os.path import isfile, join
##
## Set the directory where the files are
##
parser = argparse.ArgumentParser()
parser.add_argument ('-i', '--input_dir')
parser.add_argument ('-x', '--file_ext')
args = parser.parse_args ()
print args
if not args.input_dir or not args.file_ext:
print "Either intput dir or file extension is unspecified!"
sys.exit(0)
try:
print args.input_dir + "/" + args.file_ext
files = glob.glob (args.input_dir + "/" + args.file_ext)
for f in files:
if not (isfile (f)): continue
head, in_file_name = ntpath.split(f)
elems = in_file_name.split('.')
out_file_name = elems[0] + ".bin"
# print 'out_file_name', (args.input_dir + '/' + out_file_name)
print 'processing', (args.input_dir + '/' + in_file_name)
try:
# exec_str = "./json2bin.native -i %s -o %s" % (args.input_dir + '/' + in_file_name, args.input_dir + '/' + out_file_name)
# print exec_str
subprocess.call ("./json2bin.native -i %s -o %s" % (args.input_dir + '/' + in_file_name, args.input_dir + '/' + out_file_name), shell=True)
except Exception, e:
raise Exception ('Failed on: ' + (args.input_dir + '/' + in_file_name) + ' : ' + str(e))
except Exception, e:
print "Failed to run the binary conversion script:", e