Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gabriel Silva Vinha
codespeed
Commits
7b5423a6
Unverified
Commit
7b5423a6
authored
Dec 16, 2017
by
Miquel Torres
Committed by
GitHub
Dec 16, 2017
Browse files
Merge pull request #231 from chriscool/remove-api-lefover
tools: remove script still using previsously removed API
parents
5851468f
58de3833
Changes
2
Show whitespace changes
Inline
Side-by-side
tools/create_environment.py
deleted
100755 → 0
View file @
5851468f
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Check if an environment exists, create otherwise
"""
import
json
import
urllib2
from
optparse
import
OptionParser
,
OptionError
from
django.utils
import
simplejson
CODESPEED_URL
=
'http://speedcenter'
def
get_options
():
"""Get the options and arguments
"""
parser
=
OptionParser
()
parser
.
add_option
(
"-e"
,
"--environment"
,
dest
=
"environment"
,
help
=
"name of the environment to create"
)
(
options
,
args
)
=
parser
.
parse_args
()
if
not
options
.
environment
:
parser
.
error
(
"No environment given"
)
return
options
,
args
def
is_environment
(
environment
):
"""check if environment does exist
return:
True if it exist
False if it doesn't exist
"""
url
=
CODESPEED_URL
+
'/api/v1/environment/'
request
=
urllib2
.
Request
(
url
)
opener
=
urllib2
.
build_opener
()
try
:
raw_data
=
opener
.
open
(
request
)
except
urllib2
.
HTTPError
as
e
:
raise
e
data
=
simplejson
.
load
(
raw_data
)
if
environment
in
[
env
[
'name'
]
for
env
in
data
[
'objects'
]]:
return
True
return
False
def
create_environment
(
environment
):
"""create the environment
return:
True if success
False if not created
"""
url
=
CODESPEED_URL
+
'/api/v1/environment/'
data
=
json
.
dumps
({
'name'
:
environment
})
request
=
urllib2
.
Request
(
url
,
data
,
{
'Content-Type'
:
'application/json'
})
try
:
f
=
urllib2
.
urlopen
(
request
)
response
=
f
.
read
()
f
.
close
()
except
urllib2
.
HTTPError
as
e
:
raise
e
return
response
def
main
():
(
options
,
args
)
=
get_options
()
if
is_environment
(
options
.
environment
):
print
"Found environment, doing nothing."
else
:
print
create_environment
(
options
.
environment
)
if
__name__
==
"__main__"
:
main
()
tools/save_single_result_via_api.py
deleted
100755 → 0
View file @
5851468f
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Submit a single result via the RESTful API using requests
Note, that is just an example. You need to add an user
to get the apikey via the /admin
All resources in the result_data dict need to exist.
"""
import
json
import
requests
def
get_data
():
"""Helper function to build a valid POST request to save a result"""
result_data
=
{
'commitid'
:
'/api/v1/revision/2/'
,
'branch'
:
'/api/v1/branch/1/'
,
# Always use default for trunk/master/tip
'project'
:
'/api/v1/project/2/'
,
'executable'
:
'/api/v1/executable/1/'
,
'benchmark'
:
'/api/v1/benchmark/1/'
,
'environment'
:
'/api/v1/environment/2/'
,
'result_value'
:
4000
,
}
headers
=
{
'content-type'
:
'application/json'
,
'Authorization'
:
'ApiKey apiuser2:2ee0fa1a175ccc3b88b245e799d70470e5d53430'
}
url
=
'http://localhost:8000/api/v1/benchmark-result/'
return
(
url
,
result_data
,
headers
)
def
main
():
url
,
result_data
,
headers
=
get_data
()
print
"{0}: {1}"
.
format
(
url
,
result_data
)
r
=
requests
.
post
(
url
,
data
=
json
.
dumps
(
result_data
),
headers
=
headers
)
print
r
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