2

OK, before 1.4 release we had paster where we can add our own commands, for example for drop cache or load database initial data. Right now, how I understand, pyramid deal with Console Scripts but documentation is poor about this new feature. I want load initial database data. In old-style I write separate command for paster and register it when I will can load data like this:

paster loaddbdata

How I can do that now?

Denis
  • 7,127
  • 8
  • 37
  • 58
  • When you register a script, it creates an executable in the /bin of your virtualenv. You can read the docs here http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/commandline.html#making-your-script-into-a-console-script and also see the tutorial example here http://docs.pylonsproject.org/projects/pyramid/en/latest/tutorials/wiki2/definingmodels.html#changing-scripts-initializedb-py – Antoine Leclair Mar 13 '13 at 13:58
  • @AntoineLeclair. Thanks for your help. But this tutor about pshell (wrapper around python interpreter). And I do it with pshell and so it's looks how you start shell and you have your own command in shell context. It works fine, but I am embarrassed, this is a not proper way to load initial data I think. Can I do this through setup.py? – Denis Mar 14 '13 at 05:28

1 Answers1

2

Pyramid provides the pyramid.paster.bootstrap() to make it easy to create a script with your application. Turning a script into a command isn't done through any complicated construct provided by Pyramid, but rather you should just use setuptools entry points. This involves adding a [console_scripts] section to your setup.py entry_points, re-running develop, and your script should be installed into the bin directory.

setup(
   # ...
   entry_points={
    'paste.app_factory': [
        'main = myapp:main',
    ],
    'console_scripts': [
        'myscript = myapp.scripts.myscript:main',
    ],
)
Michael Merickel
  • 23,153
  • 3
  • 54
  • 70