Files
@ 569feabd3c9d
Branch filter:
Location: kallithea/kallithea/lib/paster_commands/common.py - annotation
569feabd3c9d
3.7 KiB
text/x-python
utils: rename add_cache to setup_cache_regions
Rename method 'add_cache' to something that better describes what it
actually does.
Rename method 'add_cache' to something that better describes what it
actually does.
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 104 105 106 107 108 109 110 111 112 113 | e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e 569feabd3c9d e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e e0f31c7d0f5e 569feabd3c9d e0f31c7d0f5e e0f31c7d0f5e | # -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
kallithea.lib.paster_commands.common
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Common code for Paster commands.
This file was forked by the Kallithea project in July 2014.
Original author and date, and relevant copyright and licensing information is below:
:created_on: Apr 18, 2010
:author: marcink
:copyright: (c) 2013 RhodeCode GmbH, and others.
:license: GPLv3, see LICENSE.md for more details.
"""
import os
import logging
import paste
from paste.script.command import Command, BadCommand
from kallithea.lib.utils import setup_cache_regions
def ask_ok(prompt, retries=4, complaint='Yes or no please!'):
while True:
ok = raw_input(prompt)
if ok in ('y', 'ye', 'yes'):
return True
if ok in ('n', 'no', 'nop', 'nope'):
return False
retries = retries - 1
if retries < 0:
raise IOError
print complaint
class BasePasterCommand(Command):
"""
Abstract Base Class for paster commands.
The celery commands are somewhat aggressive about loading
celery.conf, and since our module sets the `CELERY_LOADER`
environment variable to our loader, we have to bootstrap a bit and
make sure we've had a chance to load the pylons config off of the
command line, otherwise everything fails.
"""
min_args = 1
min_args_error = "Please provide a paster config file as an argument."
takes_config_file = 1
requires_config_file = True
def run(self, args):
"""
Overrides Command.run
Checks for a config file argument and loads it.
"""
if len(args) < self.min_args:
raise BadCommand(
self.min_args_error % {'min_args': self.min_args,
'actual_args': len(args)})
# Decrement because we're going to lob off the first argument.
# @@ This is hacky
self.min_args -= 1
self.bootstrap_config(args[0])
self.update_parser()
return super(BasePasterCommand, self).run(args[1:])
def update_parser(self):
"""
Abstract method. Allows for the class's parser to be updated
before the superclass's `run` method is called. Necessary to
allow options/arguments to be passed through to the underlying
celery command.
"""
raise NotImplementedError("Abstract Method.")
def bootstrap_config(self, conf):
"""
Loads the pylons configuration.
"""
from pylons import config as pylonsconfig
self.path_to_ini_file = os.path.realpath(conf)
conf = paste.deploy.appconfig('config:' + self.path_to_ini_file)
pylonsconfig.init_app(conf.global_conf, conf.local_conf)
def _init_session(self):
"""
Inits SqlAlchemy Session
"""
logging.config.fileConfig(self.path_to_ini_file)
from pylons import config
from kallithea.model import init_model
from kallithea.lib.utils2 import engine_from_config
setup_cache_regions(config)
engine = engine_from_config(config, 'sqlalchemy.db1.')
init_model(engine)
|