Commit b6cbbb24 by Tobias Langer

Moved absolute path calculation to highest level.

parent 74e18604
......@@ -46,9 +46,6 @@ def create_dir(filename):
Create the directory denoted by filename, if it doesn't exists. Ask for its
removal if it exists.
"""
cwd = os.getcwd()
path = os.path.join(cwd, filename)
try:
os.makedirs(path)
except FileExistsError:
......@@ -58,18 +55,6 @@ def create_dir(filename):
os.makedirs(path)
return True
def copy_files(makefile, codefile, destination):
"""
Populate the experiments directory with Makefile and Codefile.
"""
cwd = os.getcwd()
target = os.path.join(cwd, destination)
makefile_path = os.path.join(cwd, makefile)
shutil.copyfile(makefile_path, os.path.join(target, 'Makefile'))
codefile_path = os.path.join(cwd, destination)
shutil.copyfile(codefile_path, os.path.join(target, 'experiment.cpp'))
def create_header(headerfile, tasks, destination):
"""
Create a header file for the experiment.
......@@ -88,6 +73,8 @@ def main():
parser.add_argument('cpp', type=str, nargs='?', default='./template/experiment.cpp', help='path to optional custom c++ implementation.')
args = parser.parse_args()
cwd = os.getcwd()
for num, experiment_file in enumerate(args.description):
with open(experiment_file, 'r') as experiment_description:
descr_json = experiment_description.read()
......@@ -98,9 +85,11 @@ def main():
experiment['name']),
file=sys.stderr)
experiment_dir = os.path.join(cwd, experiment['name'])
# Create folder
print('create folder')
if not create_dir(experiment['name']):
if not create_dir(experiment_dir):
print('Skipping experiment ', experiment['name'], file=sys.stderr)
continue
......@@ -109,13 +98,15 @@ def main():
# Add header
print('create header file')
create_header(parser.header, tasks, experiment['name'])
create_header(args.headerfile, experiment, experiment_dir)
# Add makefile & c++ file
print('add Makefile')
makefile_path = os.path.join(experiment_dir, 'Makefile')
shutil.copyfile(args.makefile, makefile_path)
print('add C++ file')
copy_files(args.makefile, args.cpp, experiment['name'])
cpp_file_path = os.path.join(experiment_dir, 'experiment.cpp')
shutil.copyfile(args.cpp, cpp_file_path)
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment