Last active
August 29, 2015 14:18
-
-
Save frankzhao/0e8016f1b372051befbe to your computer and use it in GitHub Desktop.
Batch compile Wireworlds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Frank Zhao 2015 | |
# Test compilation of Wireworld submissions | |
from os import listdir, mkdir | |
from subprocess import Popen, PIPE, STDOUT | |
from shutil import copy2 | |
import zipfile | |
def attempt_compilation(folder, path): | |
path = path + "/" | |
copy2(compile_script, path + compile_script) | |
print("Attempting to compile: " + folder) | |
command = "cd " + path + " && ./" + compile_script | |
process = Popen(command, stdout=PIPE, stderr=PIPE, | |
shell=True, universal_newlines=True) | |
stdout, stderr = process.communicate() | |
if process.returncode == 0 and "Warning:" in stderr: | |
print ("Compilation successful with warnings.\n") | |
elif process.returncode == 0: | |
print ("Compilation successful.\n") | |
else: | |
print ("Compilation failed.\n") | |
# Write output to file | |
with open(folder + "/compile_log.txt", "w") as outfile: | |
outfile.write(stdout + "\n" + stderr) | |
compile_script = "make_Wireworld_compile_everything" | |
file_list = listdir(".") | |
files = [] | |
for file in file_list: | |
if ".zip" in file: | |
files.append(file) | |
for file in files: | |
print("Extracting: " + file) | |
try: | |
with zipfile.ZipFile(file, 'r') as z: | |
# Extract contents | |
folder = file.replace(".zip", "") | |
mkdir(folder) | |
z.extractall("./"+folder+"/") | |
# Try compilation | |
try: | |
# Guess directory structure is /Assignment_1/Sources | |
attempt_compilation(folder, folder+"/Assignment_1") | |
except IOError: | |
# Guess directory structure is /Sources | |
attempt_compilation(folder, folder) | |
except IOError: | |
print("Directory structure is incorrect.\n") | |
with open(folder + "/compile_log.txt", "w") as outfile: | |
outfile.write("Directory structure is incorrect.") | |
except zipfile.BadZipfile: | |
print("Bad zip archive: " + file + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment