Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Tobias Langer
/
experiment
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b6cbbb24
authored
Oct 05, 2016
by
Tobias Langer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved absolute path calculation to highest level.
parent
74e18604
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
19 deletions
+10
-19
generate.py
+10
-19
No files found.
generate.py
View file @
b6cbbb24
...
...
@@ -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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment