Add config-free "standalone" option to the 'paster run' command.

This commit is contained in:
Max Goodman
2011-06-20 12:10:25 -07:00
parent 6c7a5bc18b
commit 9a88e97b22
3 changed files with 38 additions and 30 deletions

View File

@@ -51,16 +51,20 @@ class RunCommand(command.Command):
help="execute command in module")
def command(self):
config_name = 'config:%s' % self.args[0]
here_dir = os.getcwd()
conf = appconfig(config_name, relative_to=here_dir)
conf.global_conf['running_as_script'] = True
conf.update(dict(app_conf=conf.local_conf,
global_conf=conf.global_conf))
paste.deploy.config.CONFIG.push_thread_config(conf)
if self.args[0].lower() == 'standalone':
load_environment(setup_globals=False)
else:
config_name = 'config:%s' % self.args[0]
load_environment(conf.global_conf, conf.local_conf)
conf = appconfig(config_name, relative_to=here_dir)
conf.global_conf['running_as_script'] = True
conf.update(dict(app_conf=conf.local_conf,
global_conf=conf.global_conf))
paste.deploy.config.CONFIG.push_thread_config(conf)
load_environment(conf.global_conf, conf.local_conf)
# Load locals and populate with objects for use in shell
sys.path.insert(0, here_dir)

View File

@@ -37,7 +37,7 @@ import r2.config as reddit_config
from r2.templates import tmpl_dirs
def load_environment(global_conf={}, app_conf={}):
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
map = make_map(global_conf, app_conf)
# Setup our paths
root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -51,7 +51,11 @@ def load_environment(global_conf={}, app_conf={}):
config.init_app(global_conf, app_conf, package='r2',
template_engine='mako', paths=paths)
config['pylons.g'] = app_globals.Globals(global_conf, app_conf, paths)
g = config['pylons.g'] = app_globals.Globals(global_conf, app_conf, paths)
if setup_globals:
g.setup(global_conf)
reddit_config.cache = g.cache
config['pylons.h'] = r2.lib.helpers
config['routes.map'] = map
@@ -74,8 +78,6 @@ def load_environment(global_conf={}, app_conf={}):
# Add your own template options config options here,
# note that all config options will override
# any Pylons config options
g = config['pylons.g']
reddit_config.cache = g.cache
# Return our loaded config object
#return config.Config(tmpl_options, map, paths)

View File

@@ -161,9 +161,28 @@ class Globals(object):
% (k, v, self.choice_props[k]))
v = self.choice_props[k][v]
setattr(self, k, v)
self.paths = paths
self.running_as_script = global_conf.get('running_as_script', False)
# turn on for language support
if not hasattr(self, 'lang'): self.lang = 'en'
self.languages, self.lang_name = \
get_active_langs(default_lang= self.lang)
all_languages = self.lang_name.keys()
all_languages.sort()
self.all_languages = all_languages
# set default time zone if one is not set
tz = global_conf.get('timezone', 'UTC')
self.tz = pytz.timezone(tz)
dtz = global_conf.get('display_timezone', tz)
self.display_tz = pytz.timezone(dtz)
def setup(self, global_conf):
if hasattr(signal, 'SIGUSR1'):
# not all platforms have user signals
signal.signal(signal.SIGUSR1, thread_dump)
@@ -227,13 +246,6 @@ class Globals(object):
self.thing_cache = CacheChain((localcache_cls(),))
self.cache_chains.append(self.thing_cache)
# set default time zone if one is not set
tz = global_conf.get('timezone')
dtz = global_conf.get('display_timezone', tz)
self.tz = pytz.timezone(tz)
self.display_tz = pytz.timezone(dtz)
#load the database info
self.dbm = self.load_db_params(global_conf)
@@ -264,20 +276,10 @@ class Globals(object):
self.REDDIT_MAIN = bool(os.environ.get('REDDIT_MAIN'))
# turn on for language support
self.languages, self.lang_name = \
get_active_langs(default_lang= self.lang)
all_languages = self.lang_name.keys()
all_languages.sort()
self.all_languages = all_languages
self.paths = paths
self.secure_domains = set([urlparse(self.payment_domain).netloc])
# load the md5 hashes of files under static
static_files = os.path.join(paths.get('static_files'), 'static')
static_files = os.path.join(self.paths.get('static_files'), 'static')
self.static_md5 = {}
if os.path.exists(static_files):
for f in os.listdir(static_files):
@@ -320,7 +322,7 @@ class Globals(object):
#read in our CSS so that it can become a default for subreddit
#stylesheets
stylesheet_path = os.path.join(paths.get('static_files'),
stylesheet_path = os.path.join(self.paths.get('static_files'),
self.static_path.lstrip('/'),
self.stylesheet)
with open(stylesheet_path) as s: