Commit b481c3ad authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Revert "wheezy: Remove setup_environ"

This reverts commit a813a25117f3db14d5517f630d6d0e163a58b0f8. This
commit is reverted because it breaks compatibility with Django 1.2. This
should be applied for Synnefo 0.15.
parent 0231b41f
......@@ -36,15 +36,15 @@ and implements the message wait and dispatch loops. Actual messages are
handled in the dispatched functions.
"""
from django.core.management import setup_environ
# Fix path to import synnefo settings
import sys
import os
path = os.path.normpath(os.path.join(os.getcwd(), '..'))
sys.path.append(path)
from synnefo import settings as snf_settings
from django.conf import settings
settings.configure(**snf_settings.__dict__)
from synnefo import settings
setup_environ(settings)
from django.db import close_connection
......@@ -113,7 +113,7 @@ class Dispatcher:
self.client.connect()
# Declare queues and exchanges
exchange = snf_settings.EXCHANGE_GANETI
exchange = settings.EXCHANGE_GANETI
exchange_dl = queues.convert_exchange_to_dead(exchange)
self.client.exchange_declare(exchange=exchange,
type="topic")
......
......@@ -59,13 +59,22 @@ For G, the operating state is True if the machine is up, False otherwise.
import logging
import sys
import itertools
from django.core.management import setup_environ
try:
from synnefo import settings
except ImportError:
raise Exception("Cannot import settings, make sure PYTHONPATH contains "
"the parent directory of the Synnefo Django project.")
setup_environ(settings)
from datetime import datetime, timedelta
from synnefo.db.models import (VirtualMachine, pooled_rapi_client)
from synnefo.logic.rapi import GanetiApiError
from synnefo.logic.backend import get_ganeti_instances, get_backends
from synnefo.logic import utils
from django.conf import settings
log = logging.getLogger()
......@@ -329,3 +338,12 @@ def hanging_networks(backend, GNets):
if group_list != groups:
hanging[id] = groups - group_list
return hanging
# Only for testing this module individually
def main():
print get_instances_from_ganeti()
if __name__ == "__main__":
sys.exit(main())
......@@ -48,11 +48,12 @@ The extended class provides the following:
- override of --version command to display the snf-webproject version
"""
from django.core.management import ManagementUtility, \
from django.core.management import ManagementUtility, setup_environ, \
BaseCommand, LaxOptionParser, handle_default_options, find_commands, \
load_command_class
from django.core import management
from django.utils.importlib import import_module
from optparse import Option, make_option
from synnefo.util.version import get_component_version
from synnefo.lib.dictconfig import dictConfig
......@@ -173,6 +174,14 @@ def get_commands():
except (AttributeError, EnvironmentError, ImportError):
apps = []
# Find the project directory
try:
from django.conf import settings
module = import_module(settings.SETTINGS_MODULE)
project_directory = setup_environ(module, settings.SETTINGS_MODULE)
except (AttributeError, EnvironmentError, ImportError, KeyError):
project_directory = None
# Find and load the management module for each installed app.
for app_name in apps:
try:
......@@ -182,11 +191,17 @@ def get_commands():
except ImportError:
pass # No management module - ignore this app
if apps:
if project_directory:
# Remove the "startproject" command from self.commands, because
# that's a django-admin.py command, not a manage.py command.
del _commands['startproject']
# Override the startapp command so that it always uses the
# project_directory, not the current working directory
# (which is default).
#from django.core.management.commands.startapp import ProjectCommand
#_commands['startapp'] = ProjectCommand(project_directory)
return _commands
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment