From b6cbbb24c4c11b04ec33aae4ca1b3c6ec6d71bda Mon Sep 17 00:00:00 2001 From: Tobias Langer Date: Wed, 5 Oct 2016 12:53:19 +0200 Subject: [PATCH] Moved absolute path calculation to highest level. --- generate.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/generate.py b/generate.py index 6ebef16..cb483e4 100644 --- a/generate.py +++ b/generate.py @@ -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() -- libgit2 0.26.0