Revision 27724645

b/snf-cyclades-app/synnefo/logic/dispatcher.py
36 36
handled in the dispatched functions.
37 37

  
38 38
"""
39
from django.core.management import setup_environ
39 40

  
40 41
# Fix path to import synnefo settings
41 42
import sys
42 43
import os
43 44
path = os.path.normpath(os.path.join(os.getcwd(), '..'))
44 45
sys.path.append(path)
45
from synnefo import settings as snf_settings
46
from django.conf import settings
47
settings.configure(**snf_settings.__dict__)
46
from synnefo import settings
47
setup_environ(settings)
48 48

  
49 49
from django.db import close_connection
50 50

  
......
113 113
        self.client.connect()
114 114

  
115 115
        # Declare queues and exchanges
116
        exchange = snf_settings.EXCHANGE_GANETI
116
        exchange = settings.EXCHANGE_GANETI
117 117
        exchange_dl = queues.convert_exchange_to_dead(exchange)
118 118
        self.client.exchange_declare(exchange=exchange,
119 119
                                     type="topic")
b/snf-cyclades-app/synnefo/logic/reconciliation.py
59 59
import logging
60 60
import sys
61 61
import itertools
62

  
63
from django.core.management import setup_environ
64
try:
65
    from synnefo import settings
66
except ImportError:
67
    raise Exception("Cannot import settings, make sure PYTHONPATH contains "
68
                    "the parent directory of the Synnefo Django project.")
69
setup_environ(settings)
70

  
71

  
62 72
from datetime import datetime, timedelta
63 73

  
64 74
from synnefo.db.models import (VirtualMachine, pooled_rapi_client)
65 75
from synnefo.logic.rapi import GanetiApiError
66 76
from synnefo.logic.backend import get_ganeti_instances, get_backends
67 77
from synnefo.logic import utils
68
from django.conf import settings
69 78

  
70 79

  
71 80
log = logging.getLogger()
......
329 338
        if group_list != groups:
330 339
            hanging[id] = groups - group_list
331 340
    return hanging
341

  
342

  
343
# Only for testing this module individually
344
def main():
345
    print get_instances_from_ganeti()
346

  
347

  
348
if __name__ == "__main__":
349
    sys.exit(main())
b/snf-webproject/synnefo/webproject/manage.py
48 48
- override of --version command to display the snf-webproject version
49 49
"""
50 50

  
51
from django.core.management import ManagementUtility, \
51
from django.core.management import ManagementUtility, setup_environ, \
52 52
BaseCommand, LaxOptionParser, handle_default_options, find_commands, \
53 53
load_command_class
54 54

  
55 55
from django.core import management
56
from django.utils.importlib import import_module
56 57
from optparse import Option, make_option
57 58
from synnefo.util.version import get_component_version
58 59
from synnefo.lib.dictconfig import dictConfig
......
173 174
        except (AttributeError, EnvironmentError, ImportError):
174 175
            apps = []
175 176

  
177
        # Find the project directory
178
        try:
179
            from django.conf import settings
180
            module = import_module(settings.SETTINGS_MODULE)
181
            project_directory = setup_environ(module, settings.SETTINGS_MODULE)
182
        except (AttributeError, EnvironmentError, ImportError, KeyError):
183
            project_directory = None
184

  
176 185
        # Find and load the management module for each installed app.
177 186
        for app_name in apps:
178 187
            try:
......
182 191
            except ImportError:
183 192
                pass  # No management module - ignore this app
184 193

  
185
        if apps:
194
        if project_directory:
186 195
            # Remove the "startproject" command from self.commands, because
187 196
            # that's a django-admin.py command, not a manage.py command.
188 197
            del _commands['startproject']
189 198

  
199
            # Override the startapp command so that it always uses the
200
            # project_directory, not the current working directory
201
            # (which is default).
202
            #from django.core.management.commands.startapp import ProjectCommand
203
            #_commands['startapp'] = ProjectCommand(project_directory)
204

  
190 205
    return _commands
191 206

  
192 207

  

Also available in: Unified diff