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
5c3e2918
authored
Oct 05, 2016
by
Tobias Langer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit.
parents
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
0 deletions
+135
-0
generate.py
+125
-0
taskset_template.json
+10
-0
No files found.
generate.py
0 → 100644
View file @
5c3e2918
#!/usr/bin/env python3.4
"""
This utility script helps in the creation of experiment setups. It therefore
reads experiment descriptions from json files and creates everything necessary
as a result.
It therefore performs the following actions:
* [x] Read the json file of every experiment
* [x] Create folders for every experiment
* [ ] Create the header file for every experiment
* [x] Add the make file for every experiment
* [x] Add c++ file for every experiment
"""
import
sys
import
os
import
argparse
import
shutil
import
json
header
=
'./template/header'
makefile
=
'./template/Makefile'
cpp
=
'./template/cpp'
def
query_yes_no
(
question
,
default
=
None
):
"""
Queries the user for a decision.
"""
if
default
is
None
:
prompt
=
' [y/n]'
elif
default
.
lower
()
is
'yes'
:
prompt
=
' [Y/n]'
elif
default
.
lower
()
is
'no'
:
prompt
=
' [y/N]'
else
:
raise
ValueError
(
'Invalid default answer {}'
.
format
(
default
))
while
True
:
print
(
question
,
prompt
)
choice
=
input
()
.
lower
()
if
'yes'
.
find
(
choice
)
==
0
:
return
True
elif
'no'
.
find
(
choice
)
==
0
:
return
False
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
:
if
not
query_yes_no
(
'Folder exists, remove?'
,
default
=
'yes'
):
return
False
shutil
.
rmtree
(
path
)
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.
"""
pass
def
main
():
"""
Starting point of the script, parses arguments and creates the experiments.
"""
parser
=
argparse
.
ArgumentParser
(
description
=
'Generate experiment data.'
)
parser
.
add_argument
(
'description'
,
type
=
str
,
nargs
=
'+'
,
help
=
'file containing the taskset description.'
)
parser
.
add_argument
(
'header'
,
type
=
str
,
nargs
=
'?'
,
default
=
'./template/config.h'
,
help
=
'path to optional custom header file.'
)
parser
.
add_argument
(
'makefile'
,
type
=
str
,
nargs
=
'?'
,
default
=
'./template/Makefile'
,
help
=
'path to optional custom makefile.'
)
parser
.
add_argument
(
'cpp'
,
type
=
str
,
nargs
=
'?'
,
default
=
'./template/experiment.cpp'
,
help
=
'path to optional custom c++ implementation.'
)
args
=
parser
.
parse_args
()
for
num
,
experiment_file
in
enumerate
(
args
.
description
):
with
open
(
experiment_file
,
'r'
)
as
experiment_description
:
descr_json
=
experiment_description
.
read
()
experiment
=
json
.
loads
(
descr_json
)
print
(
'[{}/{}] Creating experiment {}:'
.
format
(
num
,
len
(
args
.
description
),
experiment
[
'name'
]),
file
=
sys
.
stderr
)
# Create folder
print
(
'create folder'
)
if
not
create_dir
(
experiment
[
'name'
]):
print
(
'Skipping experiment '
,
experiment
[
'name'
],
file
=
sys
.
stderr
)
continue
# Read tasks
tasks
=
[]
# Add header
print
(
'create header file'
)
create_header
(
parser
.
header
,
tasks
,
experiment
[
'name'
])
# Add makefile & c++ file
print
(
'add Makefile'
)
print
(
'add C++ file'
)
copy_files
(
args
.
makefile
,
args
.
cpp
,
experiment
[
'name'
])
if
__name__
==
'__main__'
:
main
()
taskset_template.json
0 → 100644
View file @
5c3e2918
{
"tasks"
:
[
{
"wcet"
:
5
,
"period"
:
10
,
"deadline"
:
15
,
"periodical"
:
true
}
]
}
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