From beeee29617d64f67f8eec2991f6b413351393c9e Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Tue, 26 Jun 2018 00:30:17 -0700 Subject: rename script to align with cookiecutter default --- docs/tutorials/wiki2/definingmodels.rst | 14 +++--- .../src/models/tutorial/scripts/initialize_db.py | 57 ++++++++++++++++++++++ .../src/models/tutorial/scripts/initializedb.py | 57 ---------------------- 3 files changed, 64 insertions(+), 64 deletions(-) create mode 100644 docs/tutorials/wiki2/src/models/tutorial/scripts/initialize_db.py delete mode 100644 docs/tutorials/wiki2/src/models/tutorial/scripts/initializedb.py (limited to 'docs') diff --git a/docs/tutorials/wiki2/definingmodels.rst b/docs/tutorials/wiki2/definingmodels.rst index d76959e30..9ed84ce76 100644 --- a/docs/tutorials/wiki2/definingmodels.rst +++ b/docs/tutorials/wiki2/definingmodels.rst @@ -158,11 +158,11 @@ the following: Here we align our imports with the names of the models, ``Page`` and ``User``. -Edit ``scripts/initializedb.py`` -================================ +Edit ``scripts/initialize_db.py`` +================================= We haven't looked at the details of this file yet, but within the ``scripts`` -directory of your ``tutorial`` package is a file named ``initializedb.py``. +directory of your ``tutorial`` package is a file named ``initialize_db.py``. Code in this file is executed whenever we run the ``initialize_tutorial_db`` command, as we did in the installation step of this tutorial. @@ -171,15 +171,15 @@ command, as we did in the installation step of this tutorial. The command is named ``initialize_tutorial_db`` because of the mapping defined in the ``[console_scripts]`` entry point of our project's ``setup.py`` file. Since we've changed our model, we need to make changes to our -``initializedb.py`` script. In particular, we'll replace our import of +``initialize_db.py`` script. In particular, we'll replace our import of ``MyModel`` with those of ``User`` and ``Page``. We'll also change the very end of the script to create two ``User`` objects (``basic`` and ``editor``) as well as a ``Page``, rather than a ``MyModel``, and add them to our ``dbsession``. -Open ``tutorial/scripts/initializedb.py`` and edit it to look like the +Open ``tutorial/scripts/initialize_db.py`` and edit it to look like the following: -.. literalinclude:: src/models/tutorial/scripts/initializedb.py +.. literalinclude:: src/models/tutorial/scripts/initialize_db.py :linenos: :language: python :emphasize-lines: 18,44-57 @@ -192,7 +192,7 @@ Installing the project and re-initializing the database Because our model has changed, and in order to reinitialize the database, we need to rerun the ``initialize_tutorial_db`` command to pick up the changes -we've made to both the models.py file and to the initializedb.py file. See +we've made to both the models.py file and to the initialize_db.py file. See :ref:`initialize_db_wiki2` for instructions. Success will look something like this: diff --git a/docs/tutorials/wiki2/src/models/tutorial/scripts/initialize_db.py b/docs/tutorials/wiki2/src/models/tutorial/scripts/initialize_db.py new file mode 100644 index 000000000..f3c0a6fef --- /dev/null +++ b/docs/tutorials/wiki2/src/models/tutorial/scripts/initialize_db.py @@ -0,0 +1,57 @@ +import os +import sys +import transaction + +from pyramid.paster import ( + get_appsettings, + setup_logging, + ) + +from pyramid.scripts.common import parse_vars + +from ..models.meta import Base +from ..models import ( + get_engine, + get_session_factory, + get_tm_session, + ) +from ..models import Page, User + + +def usage(argv): + cmd = os.path.basename(argv[0]) + print('usage: %s [var=value]\n' + '(example: "%s development.ini")' % (cmd, cmd)) + sys.exit(1) + + +def main(argv=sys.argv): + if len(argv) < 2: + usage(argv) + config_uri = argv[1] + options = parse_vars(argv[2:]) + setup_logging(config_uri) + settings = get_appsettings(config_uri, options=options) + + engine = get_engine(settings) + Base.metadata.create_all(engine) + + session_factory = get_session_factory(engine) + + with transaction.manager: + dbsession = get_tm_session(session_factory, transaction.manager) + + editor = User(name='editor', role='editor') + editor.set_password('editor') + dbsession.add(editor) + + basic = User(name='basic', role='basic') + basic.set_password('basic') + dbsession.add(basic) + + page = Page( + name='FrontPage', + creator=editor, + data='This is the front page', + ) + dbsession.add(page) diff --git a/docs/tutorials/wiki2/src/models/tutorial/scripts/initializedb.py b/docs/tutorials/wiki2/src/models/tutorial/scripts/initializedb.py deleted file mode 100644 index f3c0a6fef..000000000 --- a/docs/tutorials/wiki2/src/models/tutorial/scripts/initializedb.py +++ /dev/null @@ -1,57 +0,0 @@ -import os -import sys -import transaction - -from pyramid.paster import ( - get_appsettings, - setup_logging, - ) - -from pyramid.scripts.common import parse_vars - -from ..models.meta import Base -from ..models import ( - get_engine, - get_session_factory, - get_tm_session, - ) -from ..models import Page, User - - -def usage(argv): - cmd = os.path.basename(argv[0]) - print('usage: %s [var=value]\n' - '(example: "%s development.ini")' % (cmd, cmd)) - sys.exit(1) - - -def main(argv=sys.argv): - if len(argv) < 2: - usage(argv) - config_uri = argv[1] - options = parse_vars(argv[2:]) - setup_logging(config_uri) - settings = get_appsettings(config_uri, options=options) - - engine = get_engine(settings) - Base.metadata.create_all(engine) - - session_factory = get_session_factory(engine) - - with transaction.manager: - dbsession = get_tm_session(session_factory, transaction.manager) - - editor = User(name='editor', role='editor') - editor.set_password('editor') - dbsession.add(editor) - - basic = User(name='basic', role='basic') - basic.set_password('basic') - dbsession.add(basic) - - page = Page( - name='FrontPage', - creator=editor, - data='This is the front page', - ) - dbsession.add(page) -- cgit v1.2.3