Created
May 19, 2011 16:58
-
-
Save groner/981224 to your computer and use it in GitHub Desktop.
pyramid paster command template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import os.path as path | |
from paste.script.command import Command, BadCommand | |
from paste.deploy import loadapp | |
from pyramid.threadlocal import manager as threadlocal_manager | |
log_ = logging.getLogger(__name__) | |
class SomethingCommand(Command): | |
summary = 'Do something with something or other' | |
usage = 'CONFIG-FILE' | |
group_name = 'app' | |
min_args = 1 | |
max_args = 1 | |
parser = Command.standard_parser() | |
def command(self): | |
if self.verbose == 0: | |
logging.basicConfig(level=logging.INFO) | |
else: | |
logging.basicConfig(level=logging.DEBUG) | |
config_file, = self.args | |
# This causes necessary database configuration | |
app = loadapp('config:%s' % config_file, relative_to=path.abspath('.')) | |
registry = app.registry | |
try: | |
threadlocal_manager.push({'registry':registry}) | |
# This is where it all happens! | |
finally: | |
threadlocal_manager.pop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment