Switch to unified view

a/Allura/allura/command/base.py b/Allura/allura/command/base.py
...
...
4
from pkg_resources import iter_entry_points
4
from pkg_resources import iter_entry_points
5
5
6
import pylons
6
import pylons
7
from paste.script import command
7
from paste.script import command
8
from paste.deploy import appconfig
8
from paste.deploy import appconfig
9
from paste.registry import Registry
9
10
10
import ming
11
import ming
11
from allura.config.environment import load_environment
12
from allura.config.environment import load_environment
12
from allura.lib.custom_middleware import MagicalC, environ
13
from allura.lib import security
14
13
15
class EmptyClass(object): pass
14
class EmptyClass(object): pass
16
15
17
class Command(command.Command):
16
class Command(command.Command):
18
    min_args = 0
17
    min_args = 0
19
    max_args = 1
18
    max_args = 1
20
    usage = 'NAME [<ini file>]'
19
    usage = 'NAME [<ini file>]'
21
    group_name = 'Allura'
20
    group_name = 'Allura'
22
21
22
    @ming.utils.LazyProperty
23
    def registry(self):
24
        return Registry()
25
26
    @ming.utils.LazyProperty
27
    def globals(self):
28
        import allura.lib.app_globals
29
        return allura.lib.app_globals.Globals()
30
23
    def basic_setup(self):
31
    def basic_setup(self):
24
        global log, M
32
        global log, M
25
        if self.args:
33
        if self.args:
34
            # Probably being called from the command line - load the config file
26
            conf = appconfig('config:%s' % self.args[0],relative_to=os.getcwd())
35
            conf = appconfig('config:%s' % self.args[0],relative_to=os.getcwd())
36
            # Configure logging
27
            try:
37
            try:
28
                if self.setup_global_config:
29
                    logging.config.fileConfig(self.args[0], disable_existing_loggers=False)
30
            except Exception:
31
                try:
32
                    # logging does not understand section#subsection syntax,
38
                # ... logging does not understand section#subsection syntax
33
                    # so strip away the #subsection and try again.
39
                logging_config = self.args[0].split('#')[0]
34
                    logging.config.fileConfig(self.args[0].split('#')[0], disable_existing_loggers=False)
40
                logging.config.fileConfig(logging_config, disable_existing_loggers=False)
35
                except Exception: # pragma no cover
41
            except Exception: # pragma no cover
36
                    print >> sys.stderr, (
42
                print >> sys.stderr, (
37
                        'Could not configure logging with config file %s' % self.args[0])
43
                    'Could not configure logging with config file %s' % self.args[0])
44
            log = logging.getLogger('allura.command')
45
            log.info('Initialize reactor with config %r', self.args[0])
46
            load_environment(conf.global_conf, conf.local_conf)
47
            self.setup_globals()
38
            from allura import model
48
            from allura import model
39
            M=model
49
            M=model
40
            log = logging.getLogger('allura.command')
41
            log.info('Initialize reactor with config %r', self.args[0])
42
            environ.set_environment({
43
                    'allura.credentials':security.Credentials()
44
                    })
45
            load_environment(conf.global_conf, conf.local_conf)
46
            try:
47
                pylons.c._current_obj()
48
            except TypeError:
49
                pylons.c._push_object(MagicalC(EmptyClass(), environ))
50
            from allura.lib.app_globals import Globals
51
            pylons.g._push_object(Globals())
52
            ming.configure(**conf)
50
            ming.configure(**conf)
53
        else:
51
        else:
52
            # Probably being called from another script (websetup, perhaps?)
54
            log = logging.getLogger('allura.command')
53
            log = logging.getLogger('allura.command')
55
            conf = pylons.config
54
            conf = pylons.config
56
        self.tools = []
55
        self.tools = []
57
        for ep in iter_entry_points('allura'):
56
        for ep in iter_entry_points('allura'):
58
            try:
57
            try:
...
...
62
        for ep in iter_entry_points('allura.command_init'):
61
        for ep in iter_entry_points('allura.command_init'):
63
            log.info('Running reactor_init for %s', ep.name)
62
            log.info('Running reactor_init for %s', ep.name)
64
            ep.load()(conf)
63
            ep.load()(conf)
65
        log.info('Loaded tools')
64
        log.info('Loaded tools')
66
65
66
    def setup_globals(self):
67
        import allura.lib.app_globals
68
        self.registry.prepare()
69
        self.registry.register(pylons.c, EmptyClass())
70
        self.registry.register(pylons.g, self.globals)
71
        self.registry.register(allura.credentials, allura.lib.security.Credentials())
72
        pylons.c.queued_messages = None
73
74
    def teardown_globals(self):
75
        self.registry.cleanup()