-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed all sources. Replaced with a simple manifest. Replaced build-…
…labs.sh with a Python program (build-labs).
- Loading branch information
Showing
33 changed files
with
188 additions
and
11,418 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/tmp |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
import os | ||
import shutil | ||
from subprocess import call as call_process | ||
|
||
TMP_DIR = "tmp" | ||
BUILD_DIR = os.path.join(TMP_DIR, "build_mp") | ||
COPY_DIR = os.path.join(TMP_DIR, "copy") | ||
|
||
def die(msg): | ||
sys.stderr.write(msg + "\n") | ||
sys.exit(1) | ||
|
||
def find_in_path(executable): | ||
def is_exe(fpath): | ||
return os.path.isfile(fpath) and os.access(fpath, os.X_OK) | ||
|
||
for path in os.environ["PATH"].split(os.pathsep): | ||
path = path.strip('"') | ||
exe_file = os.path.join(path, executable) | ||
if is_exe(exe_file): | ||
return exe_file | ||
|
||
return None | ||
|
||
def sh(cmd): | ||
try: | ||
print ' '.join(cmd) | ||
rc = call_process(cmd) | ||
if rc != 0: | ||
raise OSError('Command failed.') | ||
except OSError as e: | ||
raise Exception( | ||
'Failed to run {0}: {1}'.format(' '.join(cmd), e.message) | ||
) | ||
|
||
|
||
if len(sys.argv) != 3: | ||
die("Usage: {0} path_to_training_repo course".format(sys.argv[0])) | ||
|
||
course = sys.argv[2] | ||
course_dir = os.path.join("src", course) | ||
manifest = os.path.join(course_dir, "labs.txt") | ||
training_repo = sys.argv[1] | ||
|
||
if not os.path.exists(training_repo): | ||
die('Training repo "{0}" does not exist.'.format(training_repo)) | ||
|
||
if not os.path.exists(course_dir): | ||
die('Course directory "{0}" does not exist.'.format(course_dir)) | ||
|
||
if not os.path.exists(manifest): | ||
die('Course manifest "{0}" does not exist.'.format(manifest)) | ||
|
||
master_parse = find_in_path("master_parse") | ||
if master_parse is None: | ||
die("Can't find master_parse in path.") | ||
|
||
if os.path.exists(TMP_DIR): | ||
shutil.rmtree(TMP_DIR) | ||
|
||
|
||
rc = 0 | ||
try: | ||
for i in (TMP_DIR, COPY_DIR): | ||
try: | ||
os.mkdir(i) | ||
except OSError as e: | ||
die('Cannot make directory "{0}": {1}'.format(i, e.message)) | ||
|
||
with open(manifest) as f: | ||
for i, line in enumerate(f.readlines()): | ||
line_number = i + 1 | ||
line = line.strip() | ||
if len(line) == 0: | ||
continue | ||
if line.startswith("#"): | ||
continue | ||
tokens = line.split('|') | ||
if len(tokens) != 2: | ||
raise Exception( | ||
'"{0}", line {1}: 2 fields expected, not {2}.'.format( | ||
manifest, line_number, len(tokens) | ||
) | ||
) | ||
|
||
source, target = tokens | ||
source = os.path.join(training_repo, | ||
os.path.expanduser(source.strip())) | ||
target = os.path.expanduser(target.strip()) | ||
|
||
if not os.path.exists(source): | ||
raise Exception( | ||
'"{0}", line {1}: "{2}" does not exist.'.format( | ||
manifest, line_number, source | ||
) | ||
) | ||
|
||
if os.path.exists(BUILD_DIR): | ||
shutil.rmtree(BUILD_DIR) | ||
|
||
cmd = ["master_parse", "-d", BUILD_DIR, "-ei", "UTF-8", "-eo", | ||
"UTF8", "-py", "-db", "-in", "-st", "-cc", source] | ||
sh(cmd) | ||
|
||
dir, file = os.path.split(source) | ||
base, ext = os.path.splitext(file) | ||
|
||
student_lab = os.path.join(BUILD_DIR, base, 'python', | ||
'{0}_student.py'.format(base)) | ||
|
||
target_filename = os.path.basename(target) | ||
tmp_target = os.path.join(COPY_DIR, target_filename) | ||
print "mv {0} {1}".format(student_lab, tmp_target) | ||
shutil.move(student_lab, tmp_target) | ||
|
||
target_base, _ = os.path.splitext(target_filename) | ||
cmd = ["gendbc", "--flatten", COPY_DIR, | ||
"{0}.dbc".format(target_base)] | ||
sh(cmd) | ||
|
||
shutil.copy(tmp_target, target) | ||
|
||
|
||
except Exception as e: | ||
sys.stderr.write(e.message + "\n") | ||
rc = 1 | ||
|
||
finally: | ||
if os.path.exists(TMP_DIR): | ||
shutil.rmtree(TMP_DIR) | ||
|
||
sys.exit(rc) | ||
|
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.