Merge lp:~canonical-isd-hackers/canonical-identity-provider/remove-space-shuttle-dependency into lp:canonical-identity-provider/release

Proposed by Ricardo Kirkner
Status: Merged
Approved by: Ricardo Kirkner
Approved revision: no longer in the source branch.
Merged at revision: 132
Proposed branch: lp:~canonical-isd-hackers/canonical-identity-provider/remove-space-shuttle-dependency
Merge into: lp:canonical-identity-provider/release
Diff against target: 335 lines (+210/-45)
5 files modified
fabfile.py (+2/-0)
payload/__init__.py (+11/-26)
payload/django.py (+24/-0)
payload/postgresql.py (+168/-0)
payload/virtualenv.py (+5/-19)
To merge this branch: bzr merge lp:~canonical-isd-hackers/canonical-identity-provider/remove-space-shuttle-dependency
Reviewer Review Type Date Requested Status
Anthony Lenton (community) Approve
Review via email: mp+52219@code.launchpad.net

Commit message

remove space-shuttle dependency for bootstrap

Description of the change

This branch removes the recently introduced dependency on space-shuttle, by backporting the required functions.

To post a comment you must log in.
Revision history for this message
Anthony Lenton (elachuni) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'fabfile.py'
--- fabfile.py 1970-01-01 00:00:00 +0000
+++ fabfile.py 2011-03-04 18:20:44 +0000
@@ -0,0 +1,2 @@
1# use a payload package to keep fabric code organized
2from payload import *
03
=== added directory 'payload'
=== renamed file 'fabfile.py' => 'payload/__init__.py'
--- fabfile.py 2011-03-03 19:11:04 +0000
+++ payload/__init__.py 2011-03-04 18:20:44 +0000
@@ -1,3 +1,7 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3from __future__ import absolute_import
4
1import os.path5import os.path
2import sys6import sys
3import textwrap7import textwrap
@@ -5,22 +9,8 @@
5from fabric.api import local9from fabric.api import local
6from fabric.context_managers import cd10from fabric.context_managers import cd
711
8try:12from .virtualenv import *
9 import space.shuttle13from .postgresql import *
10except ImportError:
11 from _virtualenv import (
12 setup_virtualenv,
13 virtualenv,
14 )
15
16 def install_space_shuttle():
17 # install space shuttle
18 virtualenv('pip install bzr+ssh://bazaar.launchpad.net/'
19 '~canonical-isd-hackers/space-shuttle/trunk')
20
21 created = setup_virtualenv()
22 if created:
23 install_space_shuttle()
2414
2515
26# constants16# constants
@@ -41,10 +31,6 @@
41# environment31# environment
42def bootstrap():32def bootstrap():
43 """Bootstrap the development environment"""33 """Bootstrap the development environment"""
44 from space.shuttle.virtualenv import (
45 setup_virtualenv,
46 install_dependencies,
47 )
48 # run sanity checks34 # run sanity checks
49 _check_psycopg2_conflicts()35 _check_psycopg2_conflicts()
50 # bootstrap36 # bootstrap
@@ -61,6 +47,11 @@
61 local("find . -name '*.pyc' -delete")47 local("find . -name '*.pyc' -delete")
6248
6349
50def clean_coverage():
51 """Remove coverage report files."""
52 local("rm -rf .coverage coverage.d coverage.xml")
53
54
64# development55# development
65def test(functional=False):56def test(functional=False):
66 """Run whole test suite."""57 """Run whole test suite."""
@@ -140,9 +131,3 @@
140 includes = config/devel.cfg131 includes = config/devel.cfg
141 """ % os.path.abspath(os.curdir)))132 """ % os.path.abspath(os.curdir)))
142133
143
144# extend fabfile with custom space.shuttle targets if available
145try:
146 from space.shuttle import *
147except ImportError:
148 pass
149134
=== added file 'payload/django.py'
--- payload/django.py 1970-01-01 00:00:00 +0000
+++ payload/django.py 2011-03-04 18:20:44 +0000
@@ -0,0 +1,24 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3from __future__ import absolute_import
4
5import os
6
7
8__all__ = [
9 'get_django_settings',
10]
11
12
13def get_django_settings(*keys):
14 # setup the correct django environment
15 os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings'
16 # get django settings
17 from django.conf import settings
18
19 result = dict.fromkeys(keys)
20 for key in keys:
21 result[key] = getattr(settings, key)
22
23 return result
24
025
=== added file 'payload/postgresql.py'
--- payload/postgresql.py 1970-01-01 00:00:00 +0000
+++ payload/postgresql.py 2011-03-04 18:20:44 +0000
@@ -0,0 +1,168 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3from __future__ import absolute_import
4
5from fabric.api import (
6 env,
7 local,
8 settings,
9)
10from fabric.context_managers import hide
11
12from .virtualenv import virtualenv
13from .django import get_django_settings
14
15
16__all__ = [
17 'createdb',
18 'dropdb',
19 'resetdb',
20 'setup_database',
21 'setup_postgresql_server',
22 'shutdown_postgresql_server',
23 'start_postgresql_server',
24 'stop_postgresql_server',
25 'syncdb',
26]
27
28
29def setup_postgresql_server():
30 """Setup the PostgreSQL server."""
31 _set_postgres_environment(host='/dev/shm/postgresql')
32 local("mkdir -p %s" % env.postgres['DATA'])
33 local("%s %s/initdb -A trust" % (env.postgres['ENV'], env.postgres['BIN']))
34 start_postgresql_server()
35 setup_database()
36
37
38def shutdown_postgresql_server():
39 """Shutdown the PostgreSQL server."""
40 _set_postgres_environment(host='/dev/shm/postgresql')
41 dropdb()
42 stop_postgresql_server()
43 local("rm -rf %s" % env.postgres['HOST'])
44
45
46def start_postgresql_server():
47 """Start the PostgreSQL server."""
48 _set_postgres_environment()
49 cmd = ['%(ENV)s', '%(BIN)s/pg_ctl', 'start', '-w', '-l',
50 '%(HOST)s/postgresql.log', '-o', "'-F", '-k', "%(HOST)s'"]
51 local(' '.join(cmd) % env.postgres)
52
53
54def stop_postgresql_server():
55 """Stop the PostgreSQL server."""
56 _set_postgres_environment()
57 cmd = ['%(ENV)s', '%(BIN)s/pg_ctl', 'stop', '-w', '-l',
58 '%(HOST)s/postgresql.log', '-o', "'-F", '-k', "%(HOST)s'"]
59 local(' '.join(cmd) % env.postgres)
60
61
62def setup_database():
63 """Setup the database."""
64 success = _check_database()
65 if not success:
66 createdb()
67 _createrole()
68 syncdb()
69
70
71def createdb():
72 """Create the database."""
73 _set_postgres_environment()
74 local("%(ENV)s %(BIN)s/createdb %(DATABASE)s" % env.postgres)
75
76
77def dropdb(warn_only=False):
78 """Remove the database."""
79 _set_postgres_environment()
80 if isinstance(warn_only, basestring):
81 warn_only = warn_only.lower() == 'yes'
82 with settings(warn_only=warn_only):
83 local("%(ENV)s %(BIN)s/dropdb %(DATABASE)s" % env.postgres)
84
85
86def syncdb():
87 """Sync the database."""
88 args = '--noinput'
89 virtualenv("python django_project/manage.py syncdb %s" % args,
90 capture=False)
91
92
93def resetdb():
94 """Drop and recreate then sync the database."""
95 with settings(hide='warnings'):
96 dropdb(warn_only=True)
97 createdb()
98 syncdb()
99
100
101# helpers
102# =======
103
104
105def _check_database():
106 """Check the database is accessible."""
107 with hide('aborts', 'running'):
108 try:
109 _set_postgres_environment()
110 local("%(ENV)s psql -U postgres -c '\q'"
111 % env.postgres, capture=False)
112 success = True
113 except SystemExit:
114 # there was an error connecting to the db,
115 # presumably the db didn't exist
116 success = False
117 return success
118
119
120def _set_database_environment():
121 """Update the environment with the database settings."""
122 if 'database' in env:
123 # environment already set up
124 return
125
126 settings = get_django_settings('DATABASE_HOST', 'DATABASE_PORT',
127 'DATABASE_USER', 'DATABASE_PASSWORD', 'DATABASE_NAME')
128 env.database = {
129 'HOST': settings['DATABASE_HOST'],
130 'PORT': settings['DATABASE_PORT'],
131 'NAME': settings['DATABASE_NAME'],
132 'USER': settings['DATABASE_USER'],
133 'PASSWORD': settings['DATABASE_PASSWORD'],
134 }
135
136
137def _set_postgres_environment(host=''):
138 """Update the environment with the PostgreSQL settings."""
139 if 'postgres' in env:
140 # environment already set up
141 return
142
143 _set_database_environment()
144 host = host if host else env.database['HOST']
145 port = env.database['PORT']
146
147 pg_env = []
148 env.postgres = {
149 'BIN': '/usr/lib/postgresql/8.4/bin',
150 'DATABASE': env.database['NAME'],
151 }
152
153 if host:
154 data = "%s/data" % host
155 pg_env.append("PGHOST=%s" % host)
156 pg_env.append("PGDATA=%s" % data)
157 env.postgres.update({'HOST': host, 'DATA': data})
158 if port:
159 pg_env.append("PGPORT=%s" % port)
160 env.postgres['ENV'] = ' '.join(pg_env)
161
162
163def _createrole():
164 """Create required users/roles."""
165 _set_postgres_environment()
166 local("%s %s/createuser --superuser --createdb postgres" % (
167 env.postgres['ENV'], env.postgres['BIN']))
168
0169
=== renamed file '_virtualenv.py' => 'payload/virtualenv.py'
--- _virtualenv.py 2011-03-03 16:45:01 +0000
+++ payload/virtualenv.py 2011-03-04 18:20:44 +0000
@@ -1,3 +1,7 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3from __future__ import absolute_import
4
1import os5import os
26
3from fabric.api import (7from fabric.api import (
@@ -7,14 +11,11 @@
711
812
9__all__ = [13__all__ = [
10 'create_pip_cache',
11 'install_dependencies',14 'install_dependencies',
12 'setup_virtualenv',15 'setup_virtualenv',
13 'virtualenv',16 'virtualenv',
14 ]17 ]
1518
16PIP_DOWNLOAD_CACHE = os.path.expanduser(
17 os.environ.get('PIP_DOWNLOAD_CACHE', '~/.pip/cache'))
18VIRTUALENV = '.env'19VIRTUALENV = '.env'
1920
2021
@@ -42,28 +43,13 @@
42 return created43 return created
4344
4445
45def install_dependencies(offline=False):46def install_dependencies():
46 """Install all dependencies into the virtualenv."""47 """Install all dependencies into the virtualenv."""
47 cmd = ['pip', 'install', '-r', 'requirements.txt']48 cmd = ['pip', 'install', '-r', 'requirements.txt']
48 if offline:
49 cmd.extend(['-f', "file://%s" % os.path.abspath(
50 PIP_DOWNLOAD_CACHE), '--no-index'])
51 virtualenv(' '.join(cmd), capture=False)49 virtualenv(' '.join(cmd), capture=False)
52 virtualenv('python setup.py develop')50 virtualenv('python setup.py develop')
5351
5452
55def create_pip_cache(verbose=False):
56 """Create a pip cache."""
57 capture = True
58 local("mkdir -p %s" % PIP_DOWNLOAD_CACHE)
59 cmd = ['pip', 'install', '-r', 'requirements.txt', '--no-install',
60 '-d', PIP_DOWNLOAD_CACHE]
61 if verbose:
62 capture = False
63 cmd.append('-v')
64 virtualenv(' '.join(cmd), capture=capture)
65
66
67# helpers53# helpers
68# =======54# =======
6955