Commits

Pierre Bourdon  committed 0601cb7

Unbreak most of the Django apps

  • Participants
  • Parent commits fd1ddef
  • Branches cluster_asyncio, dhcp_hostname 4
    1. everything_wsgi
    2. fix_2014_install
    3. new_rpc
    4. prologin2015

Comments (0)

Files changed (25)

File django/homepage/manage.py

 import sys
 
 if __name__ == "__main__":
-    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "homepage.settings")
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE",
+                          "prologin.homepage.settings")
 
     from django.core.management import execute_from_command_line
 

File django/mdb/fixtures/initial_data.yaml

-- fields: {last: 0, mtype: user, network: 192.168.0.0/24}
-  model: mdbapi.ippool
-  pk: 1
-- fields: {last: 0, mtype: cluster, network: 192.168.2.0/24}
-  model: mdbapi.ippool
-  pk: 2
-- fields: {key: allow_self_registration, value_bool: false, value_int: null, value_str: ''}
-  model: mdbapi.volatilesetting
-  pk: 1
-- fields:
-    name: root
-    permissions: [19, 20, 21, 4, 5, 6, 1, 2, 3, 7, 8, 9, 10, 11, 12, 25, 26, 27, 22,
-      23, 24, 28, 29, 30, 13, 14, 15, 16, 17, 18]
-  model: auth.group
-  pk: 1

File django/mdb/manage.py

 import sys
 
 if __name__ == "__main__":
-    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mdb.settings")
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "prologin.mdb.settings")
 
     from django.core.management import execute_from_command_line
 

File django/udb/fixtures/initial_data.yaml

-- fields:
-    name: Organizer
-    permissions: [23]
-  model: auth.group
-  pk: 1
-- fields:
-    name: root
-    permissions: [19, 20, 21, 4, 5, 6, 1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-      17, 18, 22, 23, 24]
-  model: auth.group
-  pk: 2

File django/udb/manage.py

 import sys
 
 if __name__ == "__main__":
-    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "udb.settings")
+    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "prologin.udb.settings")
 
     from django.core.management import execute_from_command_line
 

File python-lib/prologin/homepage/admin.py

 # along with Prologin-SADM.  If not, see <http://www.gnu.org/licenses/>.
 
 from django.contrib import admin
-from homepage import models
+from prologin.homepage import models
 
 admin.site.register(models.Link)

File python-lib/prologin/homepage/settings.py

     'django.contrib.messages.middleware.MessageMiddleware',
 )
 
-ROOT_URLCONF = 'homepage.urls'
+ROOT_URLCONF = 'prologin.homepage.urls'
 
 # Python dotted path to the WSGI application used by Django's runserver.
-WSGI_APPLICATION = 'homepage.wsgi.application'
+WSGI_APPLICATION = 'prologin.homepage.wsgi.application'
 
 TEMPLATE_DIRS = (
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'django.contrib.admin',
-    'homepage',
+    'prologin.homepage',
 )
 
 # A sample logging configuration. The only tangible logging

File python-lib/prologin/homepage/urls.py

 admin.autodiscover()
 
 urlpatterns = patterns('',
-    url(r'^$', 'homepage.views.home', name='home'),
+    url(r'^$', 'prologin.homepage.views.home', name='home'),
     url(r'^admin/', include(admin.site.urls)),
 )

File python-lib/prologin/homepage/views.py

 
 from django.conf import settings
 from django.shortcuts import render_to_response
-from homepage.models import Link
+from prologin.homepage.models import Link
 
 def home(request):
     links = Link.objects.filter(contest_only=settings.CONTEST_MODE)

File python-lib/prologin/homepage/wsgi.py

 # if running multiple sites in the same mod_wsgi process. To fix this, use
 # mod_wsgi daemon mode with each site in its own daemon process, or use
 # os.environ["DJANGO_SETTINGS_MODULE"] = "home.settings"
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "homepage.settings")
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "prologin.homepage.settings")
 
 # This application object is used by any WSGI server configured to use this
 # file. This includes Django's development server, if the WSGI_APPLICATION

File python-lib/prologin/mdb/admin.py

 # along with Prologin-SADM.  If not, see <http://www.gnu.org/licenses/>.
 
 from django.contrib import admin
-from mdbapi import models
+from prologin.mdb import models
 
 
 class IPPoolAdmin(admin.ModelAdmin):

File python-lib/prologin/mdb/fixtures/initial_data.yaml

+- fields: {last: 0, mtype: user, network: 192.168.0.0/24}
+  model: mdbapi.ippool
+  pk: 1
+- fields: {last: 0, mtype: cluster, network: 192.168.2.0/24}
+  model: mdbapi.ippool
+  pk: 2
+- fields: {key: allow_self_registration, value_bool: false, value_int: null, value_str: ''}
+  model: mdbapi.volatilesetting
+  pk: 1
+- fields:
+    name: root
+    permissions: [19, 20, 21, 4, 5, 6, 1, 2, 3, 7, 8, 9, 10, 11, 12, 25, 26, 27, 22,
+      23, 24, 28, 29, 30, 13, 14, 15, 16, 17, 18]
+  model: auth.group
+  pk: 1

File python-lib/prologin/mdb/management/commands/addmachine.py

 import time
 
 from django.core.management.base import BaseCommand, CommandError
-from mdbapi.models import Machine
+from prologin.mdb.models import Machine
 from optparse import make_option
 
 class Command(BaseCommand):

File python-lib/prologin/mdb/models.py

 
 
 # Import the signal receivers so they are activated
-import mdbapi.receivers
+import prologin.mdb.receivers

File python-lib/prologin/mdb/receivers.py

 from django.conf import settings
 from django.dispatch import receiver
 from django.db.models.signals import post_save, pre_delete
-from mdbapi.models import Machine
+from prologin.mdb.models import Machine
 
 
 class UpdateSenderTask(threading.Thread):

File python-lib/prologin/mdb/settings.py

     'django.contrib.messages.middleware.MessageMiddleware',
 )
 
-ROOT_URLCONF = 'mdb.urls'
+ROOT_URLCONF = 'prologin.mdb.urls'
 
 # Python dotted path to the WSGI application used by Django's runserver.
-WSGI_APPLICATION = 'mdb.wsgi.application'
+WSGI_APPLICATION = 'prologin.mdb.wsgi.application'
 
 TEMPLATE_DIRS = (
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'django.contrib.admin',
-    'mdbapi',
+    'prologin.mdb',
 )
 
 # A sample logging configuration. The only tangible logging

File python-lib/prologin/mdb/urls.py

 
 from django.conf.urls import patterns, include, url
 from django.contrib import admin
-from mdbapi import views
+from prologin.mdb import views
 
 admin.autodiscover()
 

File python-lib/prologin/mdb/views.py

 # along with Prologin-SADM.  If not, see <http://www.gnu.org/licenses/>.
 
 import json
-import mdbapi.receivers  # To connect our receivers
+import prologin.mdb.receivers  # To connect our receivers
 
 from django.http import HttpResponse, HttpResponseForbidden
 from django.http import HttpResponseBadRequest, HttpResponseServerError
-from mdbapi.models import Machine, VolatileSetting
+from prologin.mdb.models import Machine, VolatileSetting
 
 
 def query(request):

File python-lib/prologin/mdb/wsgi.py

 # if running multiple sites in the same mod_wsgi process. To fix this, use
 # mod_wsgi daemon mode with each site in its own daemon process, or use
 # os.environ["DJANGO_SETTINGS_MODULE"] = "mdb.settings"
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mdb.settings")
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "prologin.mdb.settings")
 
 # This application object is used by any WSGI server configured to use this
 # file. This includes Django's development server, if the WSGI_APPLICATION
 from django.contrib.staticfiles.handlers import StaticFilesHandler
 application = StaticFilesHandler(application)
 
-from prologin.wsgi import ProloginWebApp
-application = ProloginWebApp(application, 'mdb-server')
+import prologin.web
+application = prologin.web.WsgiApp(application, 'mdb-server')
 
 # Apply WSGI middleware here.
 # from helloworld.wsgi import HelloWorldApplication

File python-lib/prologin/udb/fixtures/initial_data.yaml

+- fields:
+    name: Organizer
+    permissions: [23]
+  model: auth.group
+  pk: 1
+- fields:
+    name: root
+    permissions: [19, 20, 21, 4, 5, 6, 1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+      17, 18, 22, 23, 24]
+  model: auth.group
+  pk: 2

File python-lib/prologin/udb/settings.py

     'django.contrib.messages.middleware.MessageMiddleware',
 )
 
-ROOT_URLCONF = 'udb.urls'
+ROOT_URLCONF = 'prologin.udb.urls'
 
 # Python dotted path to the WSGI application used by Django's runserver.
-WSGI_APPLICATION = 'udb.wsgi.application'
+WSGI_APPLICATION = 'prologin.udb.wsgi.application'
 
 TEMPLATE_DIRS = (
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".

File python-lib/prologin/udb/wsgi.py

 # if running multiple sites in the same mod_wsgi process. To fix this, use
 # mod_wsgi daemon mode with each site in its own daemon process, or use
 # os.environ["DJANGO_SETTINGS_MODULE"] = "udb.settings"
-os.environ.setdefault("DJANGO_SETTINGS_MODULE", "udb.settings")
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "prologin.udb.settings")
 
 # This application object is used by any WSGI server configured to use this
 # file. This includes Django's development server, if the WSGI_APPLICATION
 from django.contrib.staticfiles.handlers import StaticFilesHandler
 application = StaticFilesHandler(application)
 
-from prologin.wsgi import ProloginWebApp
-application = ProloginWebApp(application, 'udb-server')
+import prologin.web
+application = prologin.web.WsgiApp(application, 'udb-server')
 
 # Apply WSGI middleware here.
 # from helloworld.wsgi import HelloWorldApplication

File python-lib/prologin/udbsync/server.py

 
 import prologin.config
 import prologin.log
-import prologin.udb
+import prologin.udb.client
 import prologin.synchronisation
 import sys
 
         )
 
     def get_initial_backlog(self):
-        return prologin.udb.connect(auth=True).query()
+        return prologin.udb.client.connect(auth=True).query()
 
 
 if __name__ == '__main__':

File python-lib/prologin/web.py

+# -*- encoding: utf-8 -*-
+# Copyright (c) 2013 Association Prologin <info@prologin.org>
+#
+# Prologin-SADM is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Prologin-SADM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Prologin-SADM.  If not, see <http://www.gnu.org/licenses/>.
+
+"""Provides utilities for Prologin web applications. Everything should be
+prologinized like this:
+
+    # WSGI application
+    import prologin.web
+    application = prologin.web.WsgiApp(application, 'app_name')
+
+    # Tornado application
+    import prologin.web
+    application = prologin.web.TornadoApp(handlers, 'app_name')
+
+    # BaseHTTPServer application
+    class MyRequestHandler(prologin.web.ProloginBaseHTTPRequestHandler):
+        ...
+
+If your application is an RPC server, this is handled automatically.
+
+This initializes logging using prologin.log, and maps some special URLs to
+useful pages:
+  * /__ping
+    Should always return the string "pong". Used for health checking.
+  * /__threads
+    Shows the status of all threads in the process and their current stack.
+  * [TODO] /__monitoring
+    Exports monitoring values for outside use.
+"""
+
+import sys
+import traceback
+
+def ping_handler():
+    return { 'Content-Type': 'text/plain' }, "pong"
+
+def threads_handler():
+    frames = sys._current_frames()
+    text = ['%d threads found\n\n' % len(frames)]
+    for i, frame in frames.items():
+        s = 'Thread 0x%x:\n%s\n' % (i, ''.join(traceback.format_stack(frame)))
+        text.append(s)
+    return { 'Content-Type': 'text/plain' }, ''.join(text)
+
+HANDLED_URLS = {
+    '/__ping': ping_handler,
+    '/__threads': threads_handler,
+}
+
+class WsgiApp:
+    def __init__(self, app, app_name):
+        self.app = app
+        self.app_name = app_name
+
+        # TODO(delroth): initialize logging
+
+    def __call__(self, environ, start_response):
+        if environ['PATH_INFO'] in HANDLED_URLS:
+            handler = HANDLED_URLS[environ['PATH_INFO']]
+            return self.call_handler(environ, start_response, handler)
+        return self.app(environ, start_response)
+
+    def call_handler(self, environ, start_response, handler):
+        try:
+            headers, text = handler()
+            start_response('200 OK', list(headers.items()))
+            return [text.encode('utf-8')]
+        except Exception:
+            start_response('500 Error', [('Content-Type', 'text/html')])
+            return [b'<h1>Onoes, internal server error.</h1>']

File python-lib/prologin/wsgi.py

-# -*- encoding: utf-8 -*-
-# Copyright (c) 2013 Association Prologin <info@prologin.org>
-#
-# Prologin-SADM is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Prologin-SADM is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Prologin-SADM.  If not, see <http://www.gnu.org/licenses/>.
-
-"""Provides WSGI utilities for Prologin web applications. Everything should be
-prologinized like this:
-
-    import prologin.wsgi
-    application = prologin.wsgi.ProloginWebApp(application, 'app_name')
-
-This initializes logging using prologin.log, and maps some special URLs to
-useful pages:
-  * /__ping
-    Should always return the string "pong". Used for health checking.
-  * /__threads
-    Shows the status of all threads in the process and their current stack.
-  * [TODO] /__monitoring
-    Exports monitoring values for outside use.
-"""
-
-import sys
-import traceback
-
-class ProloginWebApp:
-    def __init__(self, app, app_name):
-        self.app = app
-        self.app_name = app_name
-
-        # TODO(delroth): initialize logging
-
-    def __call__(self, environ, start_response):
-        HANDLED_URLS = {
-            '/__ping': self.ping_handler,
-            '/__threads': self.threads_handler,
-        }
-        if environ['PATH_INFO'] in HANDLED_URLS:
-            handler = HANDLED_URLS[environ['PATH_INFO']]
-            return handler(environ, start_response)
-        return self.app(environ, start_response)
-
-    def ping_handler(self, environ, start_response):
-        """Always returns "pong" to be able to easily check if an application
-        is up."""
-        start_response('200 OK', [('Content-Type', 'text/plain')])
-        return [b"pong"]
-
-    def threads_handler(self, environ, start_response):
-        start_response('200 OK', [('Content-Type', 'text/plain')])
-        frames = sys._current_frames()
-        yield ('%d threads found\n\n' % len(frames)).encode('utf-8')
-        for i, frame in frames.items():
-            s = 'Thread 0x%x:\n%s\n' % (i,
-                                        ''.join(traceback.format_stack(frame)))
-            yield s.encode('utf-8')