aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'master/setup-master.py')
-rwxr-xr-xmaster/setup-master.py134
1 files changed, 104 insertions, 30 deletions
diff --git a/master/setup-master.py b/master/setup-master.py
index 448933d..896f680 100755
--- a/master/setup-master.py
+++ b/master/setup-master.py
@@ -8,61 +8,135 @@
#
import sys, os, shutil
+try:
+ from django.core import management
+except ImportError:
+ print "You need to install django-1.0 first."
+ sys.exit(1)
+
+# XXX: Document this in the help
+if os.environ.has_key('PYTHONPATH'):
+ sys.path.insert(0, os.environ['PYTHONPATH'])
DESTDIR = 'autotua_master'
-SYMLINKS = True
+SYMLINKS = False
def print_help():
print \
"""\
%(file)s: Setup the django webapp for autotua
Usage:
- %(file)s <where>
+ %(file)s install <where>
+ <edit db settings>
+ %(file)s syncdb <where>
Example:
- %(file)s /home/me/projects/
-will create `/home/me/projects/autotua` with all the necessary files.
+ %(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]}
-if len(sys.argv) == 1:
+def install_master():
+ """Start the new project"""
+
+ management.call_command('startproject', DESTDIR)
+ if SYMLINKS:
+ os.symlink(cwd+'/autotua', DESTDIR+'/master')
+ for file in ['autotua_settings.py', 'urls.py']:
+ dest_file = DESTDIR+'/'+file
+ if os.path.isfile(dest_file):
+ os.remove(dest_file)
+ os.symlink(cwd+'/custom/'+file, dest_file)
+ else:
+ shutil.copytree(cwd+'/autotua', DESTDIR+'/master')
+ for file in ['autotua_settings.py', 'urls.py']:
+ shutil.copy(cwd+'/custom/'+file, DESTDIR)
+ settings = open(DESTDIR+'/settings.py', 'a')
+ settings.write('\nfrom autotua_settings import *\n')
+ settings.close()
+
+def syncdb_master():
+ """Initialize the database"""
+ import settings
+ from django.core.management import setup_environ
+ setup_environ(settings)
+ from db_defaults import providers, archs, stages, releases, mirrors
+ from master.models import StageProvider, Arch, Stage, Release, Mirror
+ import copy
+
+ management.call_command('syncdb')
+ for provider in providers:
+ provobj = StageProvider(name=provider)
+ provobj.save()
+ # Populate arch list
+ for generic_arch in archs[provider]:
+ gen_archobj = Arch(provider=provobj)
+ # If (generic, (specific1, specific2))
+ if isinstance(generic_arch, tuple):
+ gen_archobj.generic = generic_arch[0]
+ for arch in generic_arch[1]:
+ archobj = copy.copy(gen_archobj)
+ archobj.specific = arch
+ archobj.save()
+ # If (specific1, specific2, specific3)
+ else:
+ gen_archobj.generic = generic_arch
+ gen_archobj.specific = generic_arch
+ gen_archobj.save()
+ # Populate stage list
+ for stage in stages[provider]:
+ stageobj = Stage(provider=provobj)
+ stageobj.name = stage
+ stageobj.save()
+ # Populate release list
+ for release in releases[provider]:
+ releaseobj = Release(provider=provobj)
+ releaseobj.name = release
+ releaseobj.save()
+ # 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()
+
+if len(sys.argv) < 3:
print_help()
sys.exit(1)
os.chdir(os.path.dirname(sys.argv[0]))
cwd = os.getcwd()
-if not os.path.isdir(sys.argv[1]):
- os.makedirs(sys.argv[1])
-os.chdir(sys.argv[1])
-
-try:
- from django.core import management
-except ImportError:
- print "You need to install django-1.0 first."
- sys.exit(1)
+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)
-management.call_command('startproject', DESTDIR)
+sys.path.append(os.getcwd())
+sys.path.append(cwd+'/custom')
-if SYMLINKS:
- os.symlink(cwd+'/autotua', DESTDIR+'/master')
- for file in ['autotua_settings.py', 'urls.py']:
- dest_file = DESTDIR+'/'+file
- if os.path.isfile(dest_file):
- os.remove(dest_file)
- os.symlink(cwd+'/custom/'+file, dest_file)
+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':
+ syncdb_master()
+ print "All done! Now you can start the master with `python manage.py runserver`"
else:
- shutil.copytree(cwd+'/autotua', DESTDIR+'/master')
- for file in ['autotua_settings.py', 'urls.py']:
- shutil.copy(cwd+'/custom/'+file, DESTDIR)
-
-settings = open(DESTDIR+'/settings.py', 'a')
-settings.write('\nfrom autotua_settings import *\n')
-settings.close()
+ print_help()
+ sys.exit(1)
-print "All done. Now you need to run `python manage.py syncdb` after editing the database settings in %s/settings.py" % DESTDIR