lino : Lino core functionality

The lino package is automatically installed as a plugin on every Lino site. It adds no database models, but a series of admin commands as well as the translations for messages of the lino package.

A tested document

This is a tested document. The following instructions are used for initialization:

>>> import lino
>>> lino.startup('lino_book.projects.min1.settings.doctests')
>>> from atelier.sheller import Sheller
>>> shell = Sheller()

Django admin commands added by the lino plugin

The source code of these commands is in the lino.management.commands package.

Useful commands

linod

Run a Lino daemon for this site. See The Lino Daemon.

run

Run a Python script within the Django environment for this site.

>>> shell("django-admin run --help")  
usage: django-admin run [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color] ...

Run a Python script within the Django environment for this site.

positional arguments:
  filename              The script to run.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output
  --settings SETTINGS   The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used.
  --pythonpath PYTHONPATH
                        A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".
  --traceback           Raise on CommandError exceptions
  --no-color            Don't colorize the command output.
  --force-color         Force colorization of the command output.

manage.py run myscript.py is almost the same as redirecting stdin of Django's shell command (i.e. doing manage.py shell < myscript.py), but with the possibility of using command line arguments.

For example if you have a file myscript.py with the following content...

import sys
from myapp.models import Partner
print(Partner.objects.get(pk=sys.args[1]))

... then you can run this script using:

$ python manage.py run myscript.py 101
Bäckerei Ausdemwald

This command modifies sys.args, __file__ and __name__ so that the invoked script sees them as if it had been called directly.

It is similar to the runscript command which comes with django-extensions.

This is yet another answer to the frequently asked Django question about how to run standalone Django scripts ([1], [2]).

install

Run 'pip install --upgrade' for all Python packages required by this site.

>>> shell("django-admin install --help")  
usage: django-admin install [-h] [--noinput] [-l] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback] [--no-color] [--force-color]

Run 'pip install --upgrade' for all Python packages required by this site.

optional arguments:
  -h, --help            show this help message and exit
  --noinput             Do not prompt for input of any kind.
  -l, --list            Just list the requirements, don't install them.
  --version             show program's version number and exit
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output
  --settings SETTINGS   The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used.
  --pythonpath PYTHONPATH
                        A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".
  --traceback           Raise on CommandError exceptions
  --no-color            Don't colorize the command output.
  --force-color         Force colorization of the command output.
prep

Flush the database and load the default demo fixtures.

Calls initdb using the site's lino.core.site.Site.demo_fixtures.

Introduction see Your first local Lino project.

initdb

Flush the database and load the specified fixtures.

See the page about initdb in the Developer's Guide.

The command performs three actions in one:

  • it flushes the database specified in your settings.py, i.e. issues a DROP TABLE for every table used by your application.

  • it runs Django's migrate command to re-create all tables,

  • it runs Django's loaddata command to load the specified fixtures.

This also adds a warning filter to ignore Django's warnings about empty fixtures. (See Django ticket #18213).

This reimplements a simplified version of Django's reset command, without the possibility of deleting only some data (the thing which caused so big problems that Django 1.3. decided to deprecate this command.

Deleting all data and table definitions from a database is not always trivial. It is not tested on PostgreSQL. In MySQL we use a somewhat hackerish and MySQL-specific DROP DATABASE and CREATE DATABASE because even with constraint_checks_disabled we had sporadic errors. See 2015-03-28

Note that Lino does not use Django's migration framework, so initdb runs Django's migrate command with the --run-syncdb option which "allows creating tables for apps without migrations". The Django docs add that "While this isn’t recommended, the migrations framework is sometimes too slow on large projects with hundreds of models." Yes, we go the way which is not recommended.

dump2py

Write a Python dump of this site. See About Python dumps.

qtclient

Run a Qt client for this site. See The Qt front end.

diag

Write a diagnostic status report about this site.

This is a command-line shortcut for calling lino.core.site.Site.diagnostic_report_rst().

This is deprecated. You should use status instead.

show

Show the content of a specified table to standard output.

resetsequences

Reset the database sequences for all plugins.

This is required (and automatically called) on a postgres after restoring from a snapshot (restore.py) because this operation specifies explicit primary keys.

Unlike Django's sqlsequencereset command this does not just output the SQL statements, it also executes them. And it works always on all plugins so you don't need to specify their names.

This is functionally equivalent to the following:

python manage.py sqlsequencereset APP1 APP2... | python manage.py shell

On SQLite or MySQL this command does nothing.

In PostgreSQL, Sequence objects are special single-row tables created with CREATE SEQUENCE. Sequence objects are commonly used to generate unique identifiers for rows of a table (exceprt from PostgreSQL docs).

See 2017-09-07, 2017-09-30.

makemigdump

Create a dump for migration tests.

Calls dump2py to create python dump in a tests/dumps/<version> directory. See Migration tests

Experimental commands

mergedata

Takes the full name of a python module as argument. It then imports this module and expects it to define a function objects in its global namespace. It calls this function and expects it to yield a series of Django instance objects which have not yet been saved. It then compares these objects with the "corresponding data" in the database and prints a summary to stdout. It then suggests to merge the new data into the database.

  • It never deletes any stored records.

  • All incoming objects either replace an existing (stored) object, or will be added to the database.

  • If an incoming object has a non-empty primary key, then it replaces the corresponding stored object. Otherwise, if the model has unique fields, then these cause potential replacement.

Currently the command is only partly implemented, it doesn't yet update existing records. But it detects whether records are new, and adds only those.

monitor

Experimental work. Don't use this. Writes a status report about this Site. Used to monitor a production database.

Historical commands

configure

Old name for install.

initdb_demo

Old name for prep.