From 9d9080b5b905f9351b38b9ebb52937baa7839212 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 15 Aug 2008 22:30:42 +0530 Subject: Initial autotua-master import. Run setup-master.py to setup the django webapp --- master/autotua/__init__.py | 0 master/autotua/media/css/default.css | 48 ++++++++++++++++++++ master/autotua/media/images/404.png | Bin 0 -> 12953 bytes master/autotua/media/images/topcorners.gif | Bin 0 -> 234 bytes master/autotua/models.py | 32 ++++++++++++++ master/autotua/process/__init__.py | 33 ++++++++++++++ master/autotua/process/const.py | 40 +++++++++++++++++ master/autotua/process/validate.py | 35 +++++++++++++++ master/autotua/templates/basic.html | 31 +++++++++++++ master/autotua/templates/content.html | 9 ++++ master/autotua/templates/data.html | 8 ++++ master/autotua/urls.py | 22 ++++++++++ master/autotua/views.py | 19 ++++++++ master/custom/autotua_settings.py | 9 ++++ master/custom/urls.py | 17 ++++++++ master/setup-master.py | 68 +++++++++++++++++++++++++++++ 16 files changed, 371 insertions(+) create mode 100644 master/autotua/__init__.py create mode 100644 master/autotua/media/css/default.css create mode 100644 master/autotua/media/images/404.png create mode 100644 master/autotua/media/images/topcorners.gif create mode 100644 master/autotua/models.py create mode 100644 master/autotua/process/__init__.py create mode 100644 master/autotua/process/const.py create mode 100644 master/autotua/process/validate.py create mode 100644 master/autotua/templates/basic.html create mode 100644 master/autotua/templates/content.html create mode 100644 master/autotua/templates/data.html create mode 100644 master/autotua/urls.py create mode 100644 master/autotua/views.py create mode 100644 master/custom/autotua_settings.py create mode 100644 master/custom/urls.py create mode 100755 master/setup-master.py (limited to 'master') diff --git a/master/autotua/__init__.py b/master/autotua/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/master/autotua/media/css/default.css b/master/autotua/media/css/default.css new file mode 100644 index 0000000..a7ad6d4 --- /dev/null +++ b/master/autotua/media/css/default.css @@ -0,0 +1,48 @@ +/* vim: set sw=4 sts=4 et : + * Copyright: 2008 Gentoo Foundation + * Author(s): Nirbheek Chauhan + * License: GPL-2 + * + * Immortal lh! + */ + +body { + color: black; + background-color: #ffffff; + float: left; + margin: 1.5%; + width: 98%; +} + +a:link { + color: #4d4d4d; +} + +a:visited, a:hover { + color: black; +} + +#topcurves img { + width: 99%; + float: left; +} + +#header { + width: 96%; + text-align: center; + font-size: 2em; + background-color: #e6e6e6; + padding: 1.5%; + padding-top: 0%; + float: left; +} + +#content { + width: 100% + float: left; +} + +#footer { + width: 100%; + float: left; +} diff --git a/master/autotua/media/images/404.png b/master/autotua/media/images/404.png new file mode 100644 index 0000000..f54fa84 Binary files /dev/null and b/master/autotua/media/images/404.png differ diff --git a/master/autotua/media/images/topcorners.gif b/master/autotua/media/images/topcorners.gif new file mode 100644 index 0000000..a0fa668 Binary files /dev/null and b/master/autotua/media/images/topcorners.gif differ diff --git a/master/autotua/models.py b/master/autotua/models.py new file mode 100644 index 0000000..958bb3e --- /dev/null +++ b/master/autotua/models.py @@ -0,0 +1,32 @@ +# vim: set sw=4 sts=4 et : +# Copyright: 2008 Gentoo Foundation +# Author(s): Nirbheek Chauhan +# License: GPL-2 +# +# Immortal lh! +# + +from django.db import models +from django.contrib.auth.models import User + +# Create your models here. +class Job(models.Model): + # Identifier for the job + name = models.CharField(max_length=30, unique=True) + # Name of maintainer + maintainer = models.ForeignKey(User) + # gentoo://stage{1..4} or URL + # Using a URL => stage, arch, type, release ignored + stage = models.CharField(max_length=25) + # i686, amd64, g4, etc. + arch = models.CharField(max_length=25) # choices; const.archs['all'] + # Type of stage; hardened, uclibc, etc + #type = CharField(maxlength=25) # const.stage_types + # List of releases? + release = models.CharField(max_length=25) + # Revision of jobtage tree to use (auto generated) + jobtagerev = models.CharField(max_length=50) + # Space-separated list of atoms + atoms = models.TextField() + class Meta: + unique_together = [("name", "maintainer")] diff --git a/master/autotua/process/__init__.py b/master/autotua/process/__init__.py new file mode 100644 index 0000000..6eb934c --- /dev/null +++ b/master/autotua/process/__init__.py @@ -0,0 +1,33 @@ +# vim: set sw=4 sts=4 et : +# Copyright: 2008 Gentoo Foundation +# Author(s): Nirbheek Chauhan +# License: GPL-2 +# +# Immortal lh! +# + +import random +from django.core.validators import ValidationError +import const, validate + +schemes = ['http', 'https', 'ftp'] + +def generate_stage_url(**kwargs): + scheme = kwargs['stage'].split('://', 1)[0] + if scheme in schemes: + return kwargs['stage'] + kwargs['gen_arch'] = _get_arch_dir(kwargs['arch']) + kwargs['mirror'] = random.choice(const.MIRRORS[scheme]) + url = const.STAGE_URI % kwargs + return url + +def _get_arch_dir(arch): + """ + Convert specific archs to generic archs + i686 -> x86 + mips4 -> mips + """ + for i in const.ARCHS: + if arch in const.ARCHSs[i]: + return i + raise ValidationError(const.VERRORS['invalid_arch'] % i) diff --git a/master/autotua/process/const.py b/master/autotua/process/const.py new file mode 100644 index 0000000..d88e2a0 --- /dev/null +++ b/master/autotua/process/const.py @@ -0,0 +1,40 @@ +# vim: set sw=4 sts=4 et : +# Copyright: 2008 Gentoo Foundation +# Author(s): Nirbheek Chauhan +# License: GPL-2 +# +# Immortal lh! +# + +# No 'arm' in here because the dir structure is weird +# and it hasn't been updated in forever anyway. +# Use a custom stage url if you want to use arm +# +# 'Mirror dir': () +ARCHS = { 'x86': ('i686', 'x86',), + 'amd64': ('amd64',), + 'ppc': ('970-32ul', '970-64ul', 'g4', 'power5', 'ppc', 'ppc64',), + 'sparc': ('sparc64',) + 'alpha': ('alpha',), + 'ia64': ('ia64',), + 'hppa': ('hppa1.1', 'hppa2.0',), + 'mips': ('cobalt', 'mips3', 'mips4', 'n32',), + 'sh': ('sh4',), + 's390': ('s390', 's390x',) } + +# How do we get this list? Keep updating it regularly? +# Do we associate mirrors with the slave's geo location? +MIRRORS = { 'gentoo': ('http://gentoo.osuosl.org',) } +# Example: +# http://gentoo.osuosl.org/releases/hppa/2008.0/stages/stage3-hppa2.0-2008.0.tar.bz2 +STAGES = ('stage1', 'stage2', 'stage3', 'stage4',) +STAGE_URI = '%(mirror)/releases/%(gen_arch)s/%(release)s/stages/%(stage)s-%(arch)s-%(release)s.tar.bz2' +#stage_types = ('', 'hardened', 'hardened+nomultilib') + +VERRORS = { 'invalid_stage': 'Invalid stage: %s', + 'invalid_arch': 'Invalid arch: %s', + 'invalid_type': 'Invalid type: %s', + 'invalid_release': 'Invalid release: %s' } + +for arch in ARCHS.values()[:]: + ARCHS['all'] = ARCHS['all'].__add__(arch) diff --git a/master/autotua/process/validate.py b/master/autotua/process/validate.py new file mode 100644 index 0000000..9a84537 --- /dev/null +++ b/master/autotua/process/validate.py @@ -0,0 +1,35 @@ +# vim: set sw=4 sts=4 et : +# Copyright: 2008 Gentoo Foundation +# Author(s): Nirbheek Chauhan +# License: GPL-2 +# +# Immortal lh! +# + +from datetime import datetime +from django.core.validators import ValidationError +import const + +def is_stage(stage): + if stage not in const.STAGES: + raise ValidationError(const.VERRORS['invalid_stage'] % stage) + return True + +def is_arch(arch): + if arch not in const.ARCHS['all']: + raise ValidationError(const.VERRORS['invalid_arch'] % i) + return True + +def is_type(type): + if type not in const.STAGE_TYPE: + raise ValidationError(const.VERRORS['invalid_type'] % type) + return True + +def is_release(release): + year, state = release.split('_', 1) + try: + if int(year.split('.', 1)[0]) > datetime.now().year: + raise ValidationError(const.VERRORS['invalid_release'] % release) + except: + raise ValidationError(const.VERRORS['invalid_release'] % release) + return True diff --git a/master/autotua/templates/basic.html b/master/autotua/templates/basic.html new file mode 100644 index 0000000..0147cfa --- /dev/null +++ b/master/autotua/templates/basic.html @@ -0,0 +1,31 @@ + + +{# vim: set sw=4 sts=4 et filetype=htmldjango : #} +{# Copyright: 2008 Gentoo Foundation #} +{# Author(s): Nirbheek Chauhan #} +{# License: GPL-2 #} +{# #} +{# Immortal lh! #} +{# #} + + + {% block title %}AutotuA{% endblock %} + + {##} + {% block head %}{% endblock %} + + +
+ +
+ +
+ {% block content %}{% endblock %} +
+ + + diff --git a/master/autotua/templates/content.html b/master/autotua/templates/content.html new file mode 100644 index 0000000..6f68c97 --- /dev/null +++ b/master/autotua/templates/content.html @@ -0,0 +1,9 @@ +{# vim: set sw=4 sts=4 et filetype=htmldjango : #} +{# Copyright: 2008 Gentoo Foundation #} +{# Author(s): Nirbheek Chauhan #} +{# License: GPL-2 #} +{# #} +{# Immortal lh! #} +{# #} +{% extends "basic.html" %} +{% block content %}{{ first_name }} {{ last_name }} <{{ email }}>{% endblock %} diff --git a/master/autotua/templates/data.html b/master/autotua/templates/data.html new file mode 100644 index 0000000..bc448fb --- /dev/null +++ b/master/autotua/templates/data.html @@ -0,0 +1,8 @@ +{# vim: set sw=4 sts=4 et filetype=htmldjango : #} +{# Copyright: 2008 Gentoo Foundation #} +{# Author(s): Nirbheek Chauhan #} +{# License: GPL-2 #} +{# #} +{# Immortal lh! #} +{# #} +{{ data }} diff --git a/master/autotua/urls.py b/master/autotua/urls.py new file mode 100644 index 0000000..c5ffc08 --- /dev/null +++ b/master/autotua/urls.py @@ -0,0 +1,22 @@ +# vim: set sw=4 sts=4 et : +# Copyright: 2008 Gentoo Foundation +# Author(s): Nirbheek Chauhan +# License: GPL-2 +# +# Immortal lh! +# + +from django.conf.urls.defaults import * +from django.conf import settings +from views import * + +urlpatterns = patterns('', + (r'^~([a-zA-Z0-9_]+)/$', user_page), +) + +# Static media serving for development purposes +if settings.DEBUG: + urlpatterns += patterns('', + # [1:] to remove prefixed slash + (r'^%s(?P.*)$' % settings.MEDIA_PREFIX[1:], 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), + ) diff --git a/master/autotua/views.py b/master/autotua/views.py new file mode 100644 index 0000000..5b86b16 --- /dev/null +++ b/master/autotua/views.py @@ -0,0 +1,19 @@ +# vim: set sw=4 sts=4 et : +# Copyright: 2008 Gentoo Foundation +# Author(s): Nirbheek Chauhan +# License: GPL-2 +# +# Immortal lh! +# + +from django.http import HttpResponse +from django.shortcuts import get_object_or_404, render_to_response +from master.models import User +from django.conf import settings + +def user_page(request, username): + user = get_object_or_404(User, username=username) + details = {'media_prefix': settings.MEDIA_PREFIX} + for i in ('first_name', 'last_name', 'email',): + details[i] = getattr(user, i) + return render_to_response('content.html', details) diff --git a/master/custom/autotua_settings.py b/master/custom/autotua_settings.py new file mode 100644 index 0000000..b038853 --- /dev/null +++ b/master/custom/autotua_settings.py @@ -0,0 +1,9 @@ +import os +from settings import * + +_cwd = os.path.dirname(__file__) + +MEDIA_PREFIX = '/site_media/' +TEMPLATE_DIRS += os.path.join(_cwd, 'master', 'templates').replace('\\', '/'), +INSTALLED_APPS += ('master',) +MEDIA_ROOT = os.path.join(_cwd, 'master', 'media').replace('\\', '/') diff --git a/master/custom/urls.py b/master/custom/urls.py new file mode 100644 index 0000000..c6ce8da --- /dev/null +++ b/master/custom/urls.py @@ -0,0 +1,17 @@ +from django.conf.urls.defaults import * + +# Uncomment the next two lines to enable the admin: +# from django.contrib import admin +# admin.autodiscover() + +urlpatterns = patterns('', + (r'^', include('master.urls')), + # Example: + # (r'^master/', include('master.foo.urls')), + + # Uncomment the next line to enable admin documentation: + # (r'^admin/doc/', include('django.contrib.admindocs.urls')), + + # Uncomment the next line for to enable the admin: + # (r'^admin/(.*)', admin.site.root), +) diff --git a/master/setup-master.py b/master/setup-master.py new file mode 100755 index 0000000..448933d --- /dev/null +++ b/master/setup-master.py @@ -0,0 +1,68 @@ +#!/usr/bin/python +# vim: set sw=4 sts=4 et : +# Copyright: 2008 Gentoo Foundation +# Author(s): Nirbheek Chauhan +# License: GPL-2 +# +# Immortal lh! +# + +import sys, os, shutil + +DESTDIR = 'autotua_master' +SYMLINKS = True + +def print_help(): + print \ + """\ +%(file)s: Setup the django webapp for autotua +Usage: + %(file)s + +Example: + %(file)s /home/me/projects/ +will create `/home/me/projects/autotua` with all the necessary files. + +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: + 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 management.get_version() < '0.99': + print "You need django-1.0 to use this." + sys.exit(1) + +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() + +print "All done. Now you need to run `python manage.py syncdb` after editing the database settings in %s/settings.py" % DESTDIR -- cgit v1.2.3-65-gdbad