44import subprocess
55import sys
66
7+ if "CRUNCH_BUILD_DIR" in os .environ .keys ():
8+ build_dir = os .environ ["CRUNCH_BUILD_DIR" ]
9+ else :
10+ build_dir = "build"
11+
712def print_command (command_list ):
813 print ("running: " + " " .join (command_list ), file = sys .stderr )
914
1015def convert_path (path ):
16+ if path .startswith ("build/" ):
17+ path = build_dir + path [len ("build" ):]
1118 return path .replace ("/" , os .path .sep )
1219
1320def run (command_list ):
@@ -17,19 +24,24 @@ def run(command_list):
1724 exit (returncode )
1825
1926def mkdir (path ):
27+ path = convert_path (path )
2028 print_command (["mkdir" , path ])
2129 os .makedirs (path , exist_ok = True )
2230
23- def crunch (input_path , output_path , options = []):
24- executable_extension = ["" , ".exe" ][sys .platform == 'win32' ]
25- executable_name = "crunch" + executable_extension
26-
27- build_dir = "build"
31+ def get_build_dir ():
2832 windows_build_dir = os .path .join (build_dir , "Release" )
2933 if os .path .exists (windows_build_dir ):
30- build_dir = windows_build_dir
34+ return windows_build_dir
35+ return build_dir
3136
32- executable_path = os .path .join (build_dir , executable_name )
37+ def get_executable_path (executable_name ):
38+ executable_extension = ["" , ".exe" ][sys .platform == 'win32' ]
39+ executable_name += executable_extension
40+ build_dir = get_build_dir ()
41+ return os .path .join (build_dir , executable_name )
42+
43+ def crunch (input_path , output_path , options = []):
44+ executable_path = get_executable_path ("crunch" )
3345 command_list = [executable_path ] + options
3446
3547 if input_path :
@@ -39,6 +51,26 @@ def crunch(input_path, output_path, options=[]):
3951
4052 run (command_list )
4153
54+ def example (num , input_path , output_path , options = []):
55+ executable_path = get_executable_path ("example" + str (num ))
56+ command_list = [executable_path ]
57+
58+ if (num == 1 ):
59+ command_list += [options [0 ]]
60+ options = options [1 :]
61+
62+ if input_path :
63+ input_path = convert_path (input_path )
64+ command_list += [input_path ]
65+
66+ command_list += options
67+
68+ if output_path :
69+ output_path = convert_path (output_path )
70+ command_list += ["-out" , output_path ]
71+
72+ run (command_list )
73+
4274crunch (None , None , ["--help" ])
4375
4476mkdir ("build/test/0" )
@@ -99,3 +131,17 @@ def crunch(input_path, output_path, options=[]):
99131
100132mkdir ("build/test/7" )
101133crunch ("test/black.jpg" , "build/test/7/black.crn" )
134+
135+ mkdir ("build/test/8" )
136+ example (1 , "test/unvanquished_64.png" , None , ["i" ])
137+ example (1 , "test/unvanquished_64.png" , "build/test/8/unvanquished_64.dds" , ["c" ])
138+
139+ mkdir ("build/test/9" )
140+ example (1 , "test/unvanquished_64.png" , "build/test/9/unvanquished_64.crn" , ["c" , "-crn" ])
141+ example (1 , "build/test/9/unvanquished_64.crn" , "build/test/9/unvanquished_64.dds" , ["d" ])
142+
143+ mkdir ("build/test/10" )
144+ example (2 , "build/test/9/unvanquished_64.crn" , "build/test/10/unvanquished_64.dds" )
145+
146+ mkdir ("build/test/11" )
147+ example (3 , "test/unvanquished_64.png" , "build/test/11/unvanquished_64.dds" )
0 commit comments