Skip to content

Instantly share code, notes, and snippets.

@groner
Created May 19, 2011 16:58
Show Gist options
  • Save groner/981224 to your computer and use it in GitHub Desktop.
Save groner/981224 to your computer and use it in GitHub Desktop.
pyramid paster command template
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