Commit b6cbbb24 by Tobias Langer

Moved absolute path calculation to highest level.

parent 74e18604
...@@ -46,9 +46,6 @@ def create_dir(filename): ...@@ -46,9 +46,6 @@ def create_dir(filename):
Create the directory denoted by filename, if it doesn't exists. Ask for its Create the directory denoted by filename, if it doesn't exists. Ask for its
removal if it exists. removal if it exists.
""" """
cwd = os.getcwd()
path = os.path.join(cwd, filename)
try: try:
os.makedirs(path) os.makedirs(path)
except FileExistsError: except FileExistsError:
...@@ -58,18 +55,6 @@ def create_dir(filename): ...@@ -58,18 +55,6 @@ def create_dir(filename):
os.makedirs(path) os.makedirs(path)
return True 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): def create_header(headerfile, tasks, destination):
""" """
Create a header file for the experiment. Create a header file for the experiment.
...@@ -88,6 +73,8 @@ def main(): ...@@ -88,6 +73,8 @@ def main():
parser.add_argument('cpp', type=str, nargs='?', default='./template/experiment.cpp', help='path to optional custom c++ implementation.') parser.add_argument('cpp', type=str, nargs='?', default='./template/experiment.cpp', help='path to optional custom c++ implementation.')
args = parser.parse_args() args = parser.parse_args()
cwd = os.getcwd()
for num, experiment_file in enumerate(args.description): for num, experiment_file in enumerate(args.description):
with open(experiment_file, 'r') as experiment_description: with open(experiment_file, 'r') as experiment_description:
descr_json = experiment_description.read() descr_json = experiment_description.read()
...@@ -98,9 +85,11 @@ def main(): ...@@ -98,9 +85,11 @@ def main():
experiment['name']), experiment['name']),
file=sys.stderr) file=sys.stderr)
experiment_dir = os.path.join(cwd, experiment['name'])
# Create folder # Create folder
print('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) print('Skipping experiment ', experiment['name'], file=sys.stderr)
continue continue
...@@ -109,13 +98,15 @@ def main(): ...@@ -109,13 +98,15 @@ def main():
# Add header # Add header
print('create header file') print('create header file')
create_header(parser.header, tasks, experiment['name']) create_header(args.headerfile, experiment, experiment_dir)
# Add makefile & c++ file # Add makefile & c++ file
print('add Makefile') print('add Makefile')
makefile_path = os.path.join(experiment_dir, 'Makefile')
shutil.copyfile(args.makefile, makefile_path)
print('add C++ file') print('add C++ file')
cpp_file_path = os.path.join(experiment_dir, 'experiment.cpp')
copy_files(args.makefile, args.cpp, experiment['name']) shutil.copyfile(args.cpp, cpp_file_path)
if __name__ == '__main__': if __name__ == '__main__':
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