Commit 58de3833 authored by Christian Couder's avatar Christian Couder
Browse files

tools: remove script still using previsously removed API

Commit 8ea2dc22 (Remove tastypie dependency, 2013-11-13) removed the
api/v1 REST api, but there are still scripts using this API.

It would be nice if there was a way simple way to programmatically
create an environment, or at least documentation to explain how it
could be done. But for now let's just remove the misleading
parent 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
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
True if it exist
False if it doesn't exist
url = CODESPEED_URL + '/api/v1/environment/'
request = urllib2.Request(url)
opener = urllib2.build_opener()
raw_data =
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
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'})
f = urllib2.urlopen(request)
response =
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."
print create_environment(options.environment)
if __name__ == "__main__":
#!/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 =, data=json.dumps(result_data), headers=headers)
print r
if __name__ == "__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 to comment