Parent: [c1c9d7] (diff)

Child: [d6cec7] (diff)

Download this file

base.py    104 lines (87 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
import os
import sys
import logging
from multiprocessing import Process
from pkg_resources import iter_entry_points
import pylons
from paste.script import command
from paste.deploy import appconfig
from paste.registry import Registry
import ming
from allura.config.environment import load_environment
log = None
class EmptyClass(object): pass
class Command(command.Command):
min_args = 0
max_args = 1
usage = '[<ini file>]'
group_name = 'Allura'
@ming.utils.LazyProperty
def registry(self):
return Registry()
@ming.utils.LazyProperty
def globals(self):
import allura.lib.app_globals
return allura.lib.app_globals.Globals()
@ming.utils.LazyProperty
def config(self):
import tg
return tg.config
def basic_setup(self):
global log, M
if self.args:
# Probably being called from the command line - load the config file
self.config = conf = appconfig('config:%s' % self.args[0],relative_to=os.getcwd())
# Configure logging
try:
# ... logging does not understand section#subsection syntax
logging_config = self.args[0].split('#')[0]
logging.config.fileConfig(logging_config, disable_existing_loggers=False)
except Exception: # pragma no cover
print >> sys.stderr, (
'Could not configure logging with config file %s' % self.args[0])
log = logging.getLogger('allura.command')
log.info('Initialize command with config %r', self.args[0])
load_environment(conf.global_conf, conf.local_conf)
self.setup_globals()
from allura import model
M=model
ming.configure(**conf)
pylons.c.user = M.User.anonymous()
else:
# Probably being called from another script (websetup, perhaps?)
log = logging.getLogger('allura.command')
conf = pylons.config
self.tools = []
for ep in iter_entry_points('allura'):
try:
self.tools.append((ep.name, ep.load()))
except ImportError:
log.warning('Canot load entry point %s', ep)
for ep in iter_entry_points('allura.command_init'):
log.info('Running command_init for %s', ep.name)
ep.load()(conf)
log.info('Loaded tools')
def setup_globals(self):
import allura.lib.app_globals
self.registry.prepare()
self.registry.register(pylons.c, EmptyClass())
self.registry.register(pylons.g, self.globals)
self.registry.register(allura.credentials, allura.lib.security.Credentials())
pylons.c.queued_messages = None
def teardown_globals(self):
self.registry.cleanup()
class RestartableProcess(object):
def __init__(self, log, *args, **kwargs):
self._log = log
self._args, self._kwargs = args, kwargs
self.reinit()
def reinit(self):
self._process = Process(*self._args, **self._kwargs)
def check(self):
if not self.is_alive():
self._log.error('Process %d has died, restarting', self.pid)
self.reinit()
self.start()
def __getattr__(self, name):
return getattr(self._process, name)