1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
#!/usr/bin/python
# vim: set sw=4 sts=4 et :
# Copyright: 2008 Gentoo Foundation
# Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
# License: AGPL-3
#
# Immortal lh!
#
import sys, os, shutil
try:
from django.core import management
except ImportError:
print "You need to install django-1.0 first."
sys.exit(1)
# Remove current directory from search path
sys.path = sys.path[1:]
# XXX: Document this in the help
if os.environ.has_key('PYTHONPATH'):
sys.path.insert(0, os.environ['PYTHONPATH'])
DESTDIR = 'autotua_master'
SYMLINKS = False
def print_help():
print \
"""\
%(file)s: Setup the django webapp for autotua
Usage:
%(file)s install <where>
<edit db settings>
%(file)s syncdb <where>
Example:
%(file)s install /home/me/projects/
will create `/home/me/projects/autotua_master` with all the necessary files.
You then need to edit the database settings in
/home/me/projects/autotua_master/settings.py
After this, running
%(file)s syncdb /home/me/projects/autotua_master
will initialize the db
By default, the directory will have the files copied.
Toggle `SYMLINKS` to symlink the files instead.
""" % {'file': sys.argv[0]}
def install_master():
"""Start the new project"""
import subprocess
management.call_command('startproject', DESTDIR)
if SYMLINKS:
os.symlink(srcdir+'/master', DESTDIR+'/master')
for file in ['urls.py']:
dest_file = DESTDIR+'/'+file
if os.path.isfile(dest_file):
os.remove(dest_file)
os.symlink(srcdir+'/custom/'+file, dest_file)
else:
shutil.copytree(srcdir+'/master', DESTDIR+'/master')
for file in ['urls.py']:
shutil.copy(srcdir+'/custom/'+file, DESTDIR)
settings = open(DESTDIR+'/settings.py', 'a')
master_settings = open(srcdir+'/custom/merge_settings.py')
settings.write('\n'+master_settings.read())
settings.close()
master_settings.close()
# Install icons
icondir = os.path.abspath(srcdir+'/icons')
installdir = os.path.abspath(DESTDIR)
subprocess.check_call('cd %s; make DESTDIR=%s install' % (icondir, installdir), shell=True)
def syncdb_master():
"""Initialize the database"""
from db_defaults import groups, providers, archs, releases, mirrors
import copy
management.call_command('syncdb')
# User-related defaults
for group in groups:
Group(name=group).save()
# Job-related defaults
for (gen_arch, spec_archs) in archs.iteritems():
gen_archobj = Arch(generic=gen_arch)
for spec_arch in spec_archs:
archobj = copy.copy(gen_archobj)
archobj.specific = spec_arch
archobj.save()
# Populate providers
for provider in providers:
provobj = Provider(name=provider)
provobj.save()
# Populate release list
releaseobj = Release(provider=provobj)
for (release, relarchs) in releases[provider].iteritems():
relobj = copy.copy(releaseobj)
relobj.name = release
relobj.save()
for (relgen_arch, relspec_archs) in relarchs.iteritems():
for relspec_arch in relspec_archs:
relobj.archs.add(Arch.objects.get(generic=relgen_arch,
specific=relspec_arch))
# Populate mirror list
obj = Mirror(owner=provobj)
obj.structure = mirrors[provider]['structure']
for server in mirrors[provider]['servers']:
serverobj = copy.copy(obj)
serverobj.server = server[0]
serverobj.prefix = server[1]
serverobj.save()
def setup_gpg():
from autotua import crypt
from master import const
if not os.path.isdir(const.GPGHOME):
os.mkdir(const.GPGHOME, 0700)
data = {'name': 'AutotuA Master',
'email': 'autotua@localhost',
'expire': '1m'}
print 'Creating a "sample" gpg key (expires in 1 month)'
crypt.Crypto(gpghome=const.GPGHOME).init_gpghome(**data)
def setup_sample_job():
from sample_data import sample_job
job = Job()
for i in ['name', 'jobtagerev', 'atoms']:
setattr(job, i, sample_job[i])
maintainers = User.objects.filter(username=sample_job['maintainer'][0])
if maintainers:
job.maintainer = maintainers[0]
else:
job.maintainer = User.objects.create_user(*sample_job['maintainer'])
job.release = Release.objects.get(name=sample_job['release'],
provider=Provider.objects.get(name=sample_job['provider']))
job.arch = job.release.archs.get(specific=sample_job['arch'])
# If stage is not set, defaults to stage3
job.save()
if len(sys.argv) < 3:
print_help()
sys.exit(1)
# cd to setup-master.py location
os.chdir(os.path.dirname(sys.argv[0]))
# Store the current directory
# We cd and store to work around relative invocations
srcdir = os.getcwd()
if not os.path.isdir(sys.argv[2]):
os.makedirs(sys.argv[2])
os.chdir(sys.argv[2])
if management.get_version() < '0.99':
print "You need django-1.0 to use this."
sys.exit(1)
sys.path.append(os.getcwd())
# Add cwd+/custom
sys.path.append(srcdir+'/custom')
if sys.argv[1] == 'install':
install_master()
print """Setup done.
Now you need to edit the database settings in %(dest)s/settings.py
and run `./setup-master.py syncdb %(dest)s`""" % { 'dest': os.path.join(sys.argv[2], DESTDIR) }
elif sys.argv[1] == 'syncdb':
# Import stuff
import settings
from django.core.management import setup_environ
setup_environ(settings)
from master.models import User, Group, Provider, Arch, Release, Mirror, Job, Slave
# Start stuff
syncdb_master()
setup_sample_job()
setup_gpg()
print "All done! Now you can start the master with `python manage.py runserver`"
else:
print_help()
sys.exit(1)
|