Skip to content

Commit 2272413

Browse files
zwarediegorusso
authored andcommitted
Copy sample_project to speed_python
Also adjust manage.py to use speed_python
1 parent 263860b commit 2272413

23 files changed

Lines changed: 845 additions & 1 deletion

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
.DS_Store
55
*.db
66
sample_project/repos/*
7+
speed_python/repos/*
78
override
89
build
910
dist

manage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os, sys
33

44
if __name__ == "__main__":
5-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample_project.settings")
5+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "speed_python.settings")
66

77
from django.core.management import execute_from_command_line
88

speed_python/README.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Codespeed Example instance
2+
3+
Codespeed uses the Web framework [Django](http://djangoproject.com/). To get a
4+
Codespeed instance running you need to set up a Django Project. This directory
5+
is just such a project for your reference and a jump start to create your own.
6+
7+
## For the impatient
8+
9+
Warning: It is recommended to use [virtualenv](http://pypi.python.org/pypi/virtualenv) to avoid installing
10+
stuff on the root path of your operating system.
11+
However, it works also this way and might be desired in production
12+
environments.
13+
14+
### Testing with the built-in Development Server
15+
That will give you *just* the Django development server version. Please
16+
refer to *Installing for Production* for serious installations.
17+
18+
It is assumed you are in the root directory of the Codespeed software.
19+
20+
1. Install the Python pip module
21+
`which pip >/dev/null || easy_install pip`
22+
(You might be required to use sudo)
23+
2. You *must* copy the `sample_project` directory to your project. (Prevents updates on
24+
git tracked files in the future.) Let's call it speedcenter
25+
`cp -r sample_project speedcenter`
26+
3a. (When configuring your own project) `pip install codespeeed`
27+
3b. (For Codespeed development) Install Django and other dependencies using pip
28+
`pip install -r requirements.txt`. This will not install codespeed itself, as we want runserver to only "see" the local codespeed copy
29+
4. Add codespeed to your Python path
30+
Either
31+
`export PYTHONPATH=../:$PYTHONPATH`
32+
or
33+
`ln -s ./codespeed ./sample_project`
34+
5. Initialise the Django Database
35+
`python manage.py syncdb`
36+
(Yes, add a superuser.)
37+
`python manage.py migrate`
38+
Optionally, you may want to load the fixture data for a try
39+
`python manage.py loaddata ../codespeed/fixtures/testdata.json`
40+
6. Finally, start the Django development server.
41+
`python manage.py runserver`
42+
7. Enjoy.
43+
`python -m webbrowser -n http://localhost:8000`
44+
45+
## Installing for production
46+
There are many choices to get Django Web apps served. It all depends on
47+
your preferences and existing set up. Two options are shown. Please do
48+
not hesitate to consult a search engine to tune your set-up.
49+
50+
### NGINX + GUNICORN: Easy as manage.py runserver
51+
Assumed you have a [Debian](http://www.debian.org) like system.
52+
53+
1. Follow the steps from the development server set-up up to the the 6th step (database init).
54+
2. Install [nginx](http://nginx.net/) and [gunicorn](http://gunicorn.org/)
55+
`sudo apt-get install nginx gunicorn`
56+
3. Tune /etc/nginx/sites-enabled/default to match
57+
deploy/nginx.default-site.conf
58+
(Hint: See diff /etc/nginx/sites-enabled/default deploy/nginx.default-site.conf
59+
for changes)
60+
Note, the sitestatic dir needs to point to your speedcenter/sitestatic dir!
61+
4. Restart nginx
62+
/etc/init.d/nginx restart`
63+
5. Prepare static files
64+
`cd /path/to/speedcenter/`
65+
`python ./manage.py collectstatic`
66+
6. Add 'gunicorn' to your INSTALLED_APPS in settings.py
67+
INSTALLED_APPS = (
68+
'django.contrib.auth',
69+
[...]
70+
'south',
71+
'gunicorn'
72+
)
73+
6. Run speedcenter by
74+
`python ./manage.py run_gunicorn`
75+
7. Check your new speedcenter site! Great! But wait, who runs gunicorn after the
76+
terminal exits?
77+
There are several options like upstart, runit, or supervisor.
78+
Let's go with supervisor:
79+
1. <Ctrl>+<c> to exit gunicorn
80+
2. `apt-get install supervisor`
81+
3. `cp deploy/supervisor-speedcenter.conf /etc/supervisor/conf.d/speedcenter.conf`
82+
4. `$EDITOR /etc/supervisor/conf.d/speedcenter.conf #adjust the path`
83+
5. `supervisorctl update`
84+
6. `supervisorctl status`
85+
speedcenter RUNNING pid 2036, uptime 0:00:05
86+
8. Warning: You may find another way to run gunicorn using `gunicorn_django`. That might
87+
have a shebang of `#!/usr/bin/python` bypassing your virtualenv. Run it out of your
88+
virtualenv by `python $(which gunicorn_django)`
89+
90+
### Good old Apache + mod_wsgi
91+
If you don't like surprises and are not into experimenting go with the old work horse.
92+
Assumed you have a [Debian](http://www.debian.org) like system.
93+
94+
1. Follow the steps from the development server set-up
95+
2. Prepare static files
96+
`cd /path/to/speedcenter/`
97+
`python ./manage.py collectstatic`
98+
3. Install apache and mod_wsgi
99+
`apt-get install apache2 libapache2-mod-wsgi`
100+
4. Copy deploy/apache-speedcenter.conf
101+
`cp deploy/apache-speedcenter.conf /etc/apache2/sites-available/speedcenter.conf`
102+
5. Edit /etc/apache2/sites-available/speedcenter.conf to match your needs
103+
6. Enable the new vhost
104+
`a2ensite speedcenter.conf`
105+
7. Restart apache
106+
`/etc/init.d/apache2 restart`
107+
8. Check your new vhost.
108+
109+
## Customisations
110+
111+
### Using your own Templates
112+
Just edit your very own Django templates in `speedcenter/templates`. A good
113+
start is `codespeed/base.html` the root of all templates.
114+
115+
If you need to change the codespeed templates:
116+
1. Copy the templates from the codespeed module into your Django project folder.
117+
`cp -r codespeed/templates/codespeed speedcenter/templates/`
118+
2. Edit the templates in speedcenter/templates/codespeed/*html
119+
Please, also refer to the [Django template docu]
120+
(http://docs.djangoproject.com/en/1.4/ref/templates/)
121+
122+
### Changing the URL Scheme
123+
If you don't want to have your speedcenter in the root url you can change urls.py.
124+
Comment (add a '#' at the beginning) line number 25 `(r'^', include('cod...`
125+
and uncomment the next line `(r'^speed/', include('cod...` (Note, Python is
126+
picky about indentation).
127+
Please, also refer to the [Django URL dispatcher docu]
128+
(http://docs.djangoproject.com/en/1.4/topics/http/urls/).
129+
130+
### Codespeed settings
131+
The main config file is `settings.py`. There you configure everything related
132+
to your set up.

speed_python/__init__.py

Whitespace-only changes.

speed_python/client.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# encoding: utf-8
2+
3+
from urlparse import urljoin
4+
import logging
5+
import platform
6+
import urllib
7+
import sys
8+
9+
10+
def save_to_speedcenter(url=None, project=None, commitid=None, executable=None,
11+
benchmark=None, result_value=None, **kwargs):
12+
"""Save a benchmark result to your speedcenter server
13+
14+
Mandatory:
15+
16+
:param url:
17+
Codespeed server endpoint
18+
(e.g. `http://codespeed.example.org/result/add/`)
19+
:param project:
20+
Project name
21+
:param commitid:
22+
VCS identifier
23+
:param executable:
24+
The executable name
25+
:param benchmark:
26+
The name of this particular benchmark
27+
:param float result_value:
28+
The benchmark result
29+
30+
Optional:
31+
32+
:param environment:
33+
System description
34+
:param date revision_date:
35+
Optional, default will be either VCS commit, if available, or the
36+
current date
37+
:param date result_date:
38+
Optional
39+
:param float std_dev:
40+
Optional
41+
:param float max:
42+
Optional
43+
:param float min:
44+
Optional
45+
"""
46+
47+
data = {
48+
'project': project,
49+
'commitid': commitid,
50+
'executable': executable,
51+
'benchmark': benchmark,
52+
'result_value': result_value,
53+
}
54+
55+
data.update(kwargs)
56+
57+
if not data.get('environment', None):
58+
data['environment'] = platform.platform(aliased=True)
59+
60+
f = urllib.urlopen(url, urllib.urlencode(data))
61+
62+
response = f.read()
63+
status = f.getcode()
64+
65+
f.close()
66+
67+
if status == 202:
68+
logging.debug("Server %s: HTTP %s: %s", url, status, response)
69+
else:
70+
raise IOError("Server %s returned HTTP %s" % (url, status))
71+
72+
73+
if __name__ == "__main__":
74+
from optparse import OptionParser
75+
76+
parser = OptionParser()
77+
parser.add_option("--benchmark")
78+
parser.add_option("--commitid")
79+
parser.add_option("--environment",
80+
help="Use a custom Codespeed environment")
81+
parser.add_option("--executable")
82+
parser.add_option("--max", type="float")
83+
parser.add_option("--min", type="float")
84+
parser.add_option("--project")
85+
parser.add_option("--branch")
86+
parser.add_option("--result-date")
87+
parser.add_option("--result-value", type="float")
88+
parser.add_option("--revision_date")
89+
parser.add_option("--std-dev", type="float")
90+
parser.add_option("--url",
91+
help="URL of your Codespeed server (e.g. http://codespeed.example.org)")
92+
93+
(options, args) = parser.parse_args()
94+
95+
if args:
96+
parser.error("All arguments must be provided as command-line options")
97+
98+
# Yes, the optparse manpage has a snide comment about "required options"
99+
# being gramatically dubious. Yes, it's still wrong about not needing to
100+
# do this.
101+
required = ('url', 'environment', 'project', 'commitid', 'executable',
102+
'benchmark', 'result_value')
103+
104+
if not all(getattr(options, i) for i in required):
105+
parser.error("The following parameters must be provided:\n\t%s" % "\n\t".join(
106+
"--%s".replace("_", "-") % i for i in required))
107+
108+
kwargs = {}
109+
for k, v in options.__dict__.items():
110+
if v is not None:
111+
kwargs[k] = v
112+
kwargs.setdefault('branch', 'default')
113+
114+
if not kwargs['url'].endswith("/result/add/"):
115+
kwargs['url'] = urljoin(kwargs['url'], '/result/add/')
116+
117+
try:
118+
save_to_speedcenter(**kwargs)
119+
sys.exit(0)
120+
except StandardError, e:
121+
logging.error("Error saving results: %s", e)
122+
sys.exit(1)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<VirtualHost *>
2+
ServerName speed.pypy.org
3+
DocumentRoot /var/www/speed.pypy.org
4+
5+
ErrorLog /var/log/apache2/speed-pypy.org-error.log
6+
7+
# Possible values include: debug, info, notice, warn, error, crit,
8+
# alert, emerg.
9+
LogLevel warn
10+
11+
CustomLog /var/log/apache2/speed-pypy.org-access.log combined
12+
ServerSignature On
13+
14+
Alias /static/ /path/to/speedcenter/sitestatic/
15+
16+
<Directory /path/to/speedcenter/sitestatic/>
17+
Order allow,deny
18+
Allow from all
19+
</Directory>
20+
21+
ProxyRequests Off
22+
<Proxy *>
23+
Order deny,allow
24+
Allow from all
25+
</Proxy>
26+
ProxyPass /static !
27+
ProxyPass / http://localhost:8000/
28+
ProxyPassReverse / http://localhost:8000/
29+
30+
</VirtualHost>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<VirtualHost speedcenter.foo.bar:80>
2+
ServerName speedcenter.foo.bar
3+
ServerAlias speed speed.foo.bar
4+
DocumentRoot /var/www/speedcenter/
5+
ServerAdmin admin@foo.bar
6+
ErrorLog /var/log/apache2/speedcenter-errors.log
7+
CustomLog /var/log/apache2/speedcenter-access.log combined
8+
DirectoryIndex index.html index.shtml
9+
10+
Alias /static/ /path/to/speedcenter/sitestatic/
11+
12+
WSGIDaemonProcess speedcenter user=www-data group=www-data python-path=/path/to/virtualenv/codespeed/lib/python2.6/site-packages/
13+
WSGIProcessGroup speedcenter
14+
WSGIScriptAlias / /path/to/speedcenter/django.wsgi
15+
</VirtualHost>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<VirtualHost *:80>
2+
ServerAdmin name@mail.server
3+
ServerName myspeedcenter
4+
5+
TransferLog /var/log/apache2/myspeedcenter.pypy.org.log
6+
ErrorLog /var/log/apache2/myspeedcenter.pypy.org.err
7+
8+
# To be able to serve images for admin site:
9+
Alias /admin_media/ /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media/
10+
<Directory /usr/local/lib/python2.7/dist-packages/django/contrib/admin/media/>
11+
Order deny,allow
12+
Allow from all
13+
</Directory>
14+
15+
# Serve media files
16+
Alias /static/ /path/to/codespeed/app/static/
17+
<Directory /path/to/codespeed/app/static/>
18+
Order deny,allow
19+
Allow from all
20+
</Directory>
21+
22+
#let Django handle requests
23+
WSGIScriptAlias / /path/to/example/project/example/deploy/django.wsgi
24+
<Directory /path/to/example/project/example/deploy/>
25+
Order deny,allow
26+
Allow from all
27+
</Directory>
28+
</VirtualHost>

speed_python/deploy/django.wsgi

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
WSGI config
5+
"""
6+
7+
import os
8+
import sys
9+
10+
current_dir = os.path.abspath(os.path.dirname(__file__).replace('\\','/'))
11+
dirs = current_dir.split(os.path.sep)
12+
del(dirs[-1])
13+
codespeed_dir = os.path.sep.join(dirs)
14+
del(dirs[-1])
15+
project_dir = os.path.sep.join(dirs)
16+
17+
sys.path.append(project_dir)
18+
sys.path.append(codespeed_dir)
19+
os.environ['DJANGO_SETTINGS_MODULE'] = codespeed_dir.split(os.path.sep)[-1] + '.settings'
20+
21+
import django.core.handlers.wsgi
22+
application = django.core.handlers.wsgi.WSGIHandler()
23+

0 commit comments

Comments
 (0)