# Management commands

The management commands are administration commands provided by Django, Pootle or any external Django app being used with Pootle. You will usually run these commands by issuing `pootle <command> [options]`.

For example, to get information about all available management commands, you will run:

    $ pootle help

Note

If you run Pootle from a repository checkout you can use the manage.py file found in the root of the repository.

## Managing Pootle projects

These commands will go through all existing projects performing maintenance tasks. The tasks are all available through the web interface but on a project by project or file by file basis.

The commands target can be limited in a more flexible way using the `--project` `--language` command line options. They can be repeated to indicate multiple languages or projects. If you use both options together it will only match the files that match both languages and projects selected.

For example, to refresh_stats for the tutorial project only, run:

    $ pootle refresh_stats --project=tutorial

To only refresh a the Zulu and Basque language files within the tutorial project, run:

    $ pootle refresh_stats --project=tutorial --language=zu --language=eu

`refresh_stats`

### refresh_stats

Refreshes all calculated statistics ensuring that they are up-to-date.

The refreshing of the statistics is done by a background job so that it doesn’t impact the normal operation of the server. It will flush existing cached statistics data and update the statistics cache.

Note

Disabled projects are processed.

Warning

Do not run this command if you have multiple workers running simultaneously. It should be run with a single worker process only.

It’s necessary to run this command after installing or upgrading Pootle. Also consider running this command when things might go out-of-sync: if you make changes directly in the database, if the cache backend has been restarted, etc.

The time it takes to complete the whole process will vary depending on the number of translations you have in the database. If a user hits a page that needs to display stats but they haven’t been calculated yet, a message will be displayed indicating that the stats are being recalculated.

The `--calculate-checks` option ensures that all quality checks are recalculated for all existing units in the database.

To only recalculate the `date_format` quality check, run:

    $ pootle refresh_stats --calculate-checks --check=date_format

When the `--calculate-wordcount` option is set, the source wordcount will be recalculated for all existing units in the database.

`refresh_stats_rq`

### refresh_stats_rq

New in version 2.7.

Refreshes all calculated statistics ensuring that they are up-to-date.

A background process will create a task for every file to make sure calculated statistics data is up to date. When the task for a file completes then further tasks will be created for the files parents.

Note

Files in disabled projects are processed.

Note

`refresh_stats` (the old command which works with a single worker) is roughly twice as fast compared to this version of the command. Your mileage might vary.

This command was added to allow statistics to be updated when using multiple RQ workers.

`retry_failed_jobs`

### retry_failed_jobs

New in version 2.7.

Requeue failed RQ jobs.

Background RQ jobs can fail for various reasons. To push them back into the queue you can run this command.

Examine the RQ worker logs for tracebacks before trying to requeue your jobs.

`calculate_checks`

### calculate_checks

New in version 2.7.

This command will create a background job to go through all units and recalculate quality checks.

Note

Disabled projects are processed.

`calculate_checks` will flush existing caches and update the quality checks cache.

It’s necessary to run this command after upgrading Pootle if new quality checks are added.

The time it takes to complete the whole process will vary depending on the number of units you have in the database. If a user hits a page that needs to display stats but they haven’t been calculated yet, then a message will be displayed indicating that the stats being calculated.

Use the `--check` option to force calculaton of a specified check. To recalculate only the `date_format` quality checks, run:

    $ pootle calculate_checks --check=date_format

`refresh_scores`

### refresh_scores

New in version 2.7.

Recalculates the scores for all users.

When the `--reset` option is used , all score log data is removed and zero score is set for all users.

`sync_stores`

### sync_stores

Changed in version 2.7.

Save all translations currently in the database to the file system, thereby bringing the files under the `POOTLE_TRANSLATION_DIRECTORY` directory in sync with the Pootle database.

Note

Disabled projects are skipped.

You must run this command before taking backups or running scripts that modify the translation files directly on the file system, otherwise you might miss out on translations that are in the database but not yet saved to disk. In other words, translations are saved to disk only when you explicitly do so using this command.

For every file being synced, the in-DB `Store` will be updated to reflect the latest revision across the units in the file at the time of syncing. This allows Pootle to make optimizations when syncing and updating files, ignoring files that haven’t change.

The default behavior of `sync_stores` can be altered by specifying these parameters:

`--force`
  Synchronizes files even if nothing changed in the database.
`--overwrite`
  Copies the current state of the DB stores (not only translations, but also metadata) regardless if they have been modified since the last sync or not. This operation will (over)write existing on-disk files.
`--skip-missing`
  Ignores files missing on disk, and no new files will be created.

`update_stores`

### update_stores

Changed in version 2.7.

The opposite of `sync_stores`, this will update the strings in the database to reflect what is on disk, as Pootle will not detect changes in the file system on its own.

Note

Disabled projects are skipped.

It also discovers new units, files and translation projects that were added on disk:

- Projects that exist in the DB but ceased to exist on disk will be disabled (not deleted). If a project is recovered on disk it can be enabled via the admin UI only.
- Translation projects will be scanned for new files and directories. In-DB files and directories that no longer exist on disk will be marked as obsolete. Also any in-DB directory will be marked as obsolete if this directory is empty or contains empty directories only.
- In-DB stores will be updated with the contents of the on-disk files. New units will be added to the store, units that ceased to exist will be marked as obsolete. Translations that were updated on-disk will be reflected in the DB.

You must run this command after running scripts that modify translation files directly on the file system.

`update_stores` accepts several options:

`--force`
  Updates in-DB translations even if the on-disk file hasn’t been changed since the last sync operation.
`--overwrite`
  Mirrors the on-disk contents of the file. If there have been changes in the database since the last sync operation, these will be overwritten.

Warning

If files on the file system are corrupt, translations might be deleted from the database. Handle with care!

`list_languages`

### list_languages

Lists all the language codes for languages hosted on the server. This can be useful for automation.

Accepts the `--modified-since` parameter to list only those languages modified since the revision given by `revision`.

`list_projects`

### list_projects

Lists all the project codes on the server. This might can be useful for automation.

Accepts the `--modified-since` parameter to list only those projects modified since the revision given by `revision`.

`revision`

### revision

New in version 2.7.

Print the latest revision number.

The revision is a common system-wide counter for units. It is incremented with every translation action made from the browser. Zero length units that have been auto-translated also increment the unit revision.

The revision counter is stored in the database but also in cache for faster retrieval. If for some reason the revision counter was removed or got corrupted, passing the `--restore` flag to the command will restore the counter’s value based on the revision data available on the relational DB backend. You shouldn’t need to ever run this, but if for instance you deleted your cache you will need to restore the counter to ensure correct operation.

`changed_languages`

### changed_languages

New in version 2.7.

Produces a comma-separated list of language codes that changed since the last sync operation.

When `--after-revision` is specified with a revision number as an argument, it will print the language codes for languages that have changed since the specified revision.

`test_checks`

### test_checks

New in version 2.7.

Tests any given string pair or unit against all or certain checks from the command line. This is useful for debugging and developing new checks.

String pairs can be specified by setting the values to be checked in the `--source=<"source_text">` and `--target="<target_text>"` command-line arguments.

Alternatively, `--unit=<unit_id>` can be used to reference an existing unit from the database.

By default, `test_checks` tests all existing checks. When `--check=<checkname>` is set, only specific checks will be tested against.

`dump`

### dump

New in version 2.7.

Prints data or stats data (depending on `--data` or `--stats` option) in specific format.

data:

    object_id:class_name
    8276:Directory        name=android    parent=/uk/     pootle_path=/uk/android/
    24394:Store   file=android/uk/strings.xml.po  translation_project=/uk/android/        pootle_path=/uk/android/strings.xml.po  name=strings.xml.pstate=2
    806705:Unit   source=Create Account   target=Створити аккаунт source_wordcount=2      target_wordcount=2      developer_comment=create_account        translator_commentlocations=File:\nstrings.xml\nID:\ne82a8ea14a0b9f92b1b67ebfde2c16e9   isobsolete=False        isfuzzy=False   istranslated=True
    115654:Suggestion     target_f=Необхідна електронна адреса    user_id=104481

stats:

    pootle_path total,translated,fuzzy,suggestions,criticals,is_dirty,last_action_unit_id,last_updated_unit_id
    /uk/android/strings.xml.po  11126,10597,383,231,0,False,4710214,4735242
    /uk/android/widget/strings.xml.po  339,339,0,26,0,False,2277376,3738609
    /uk/android/widget/  339,339,0,26,0,False,2277376,3738609
    /uk/android/  11465,10936,383,257,0,False,4710214,4735242

This command can be used by developers to check if all data kept after migrations or stats calculating algorithm was changed.

## Translation Memory

These commands allow you to setup and manage Translation Memory.

`update_tmserver`

### update_tmserver

New in version 2.7.

Updates the `default` server in `POOTLE_TM_SERVER`. The command reads translations from the current Pootle install and builds the TM resources in the TM server.

By default the command will only add new translations to the server. To rebuild the server from scratch use `--rebuild`, this will completely remove the TM and rebuild it. To ensure that the TM server remains available when you rebuild you can add `--overwrite`.

To see how many units will be loaded into the server use `--dry-run`, no actual data will be loaded.

## Virtual Folders

These commands allow you to perform tasks with virtual folders from the command line.

`add_vfolders`

### add_vfolders

New in version 2.7.

Creates virtual folders from a JSON file. If the specified virtual folders already exist then they are updated.

The vfolder format defines how to specify a virtual folder that fits your needs.

This command requires a mandatory filename argument.

    $ pootle add_vfolders virtual_folders.json

## Import and Export

Export and Import translation files in Pootle. The operation can be thought of best as offline operations to assist with offline translation, unlike `sync_stores` and `update_stores` the operations here are designed to cater for translators working outside of Pootle.

The `import` and `export` commands are designed to mimic the operations of Download and Upload from the Pootle UI.

`export`

### export

New in version 2.7.

Download a file for offline translation.

Note

This mimics the editor’s download functionality and its primary purpose is to test the operation of downloads from the command line.

A file or a .zip of files is provided as output. The file headers include a revision counter to assist Pootle to detetmine how to handle subsequent uploads of the file.

`import`

### import

New in version 2.7.

Upload a file that was altered offline.

Note

This mimics the editor’s upload functionality and its primary purpose is to test the operation of uploads from the command line.

A file or a .zip is submitted to Pootle and based on the revision counter of the `Store` on Pootle it will be uploaded or rejected. If the revision counter is older than on Pootle, that is someone has translated while the file was offline, then it will be rejected. Otherwise the translations in the file are accepted.

## Manually Installing Pootle

These commands expose the database installation and upgrade process from the command line.

### migrate

Changed in version 2.7.

Note

Since the addition of the setup management command it is not necessary to directly run this command. Please refer to the Upgrading or Installation instructions to see how to run the setup management command in those scenarios.

This is Django’s `migrate` command, which syncs the state of models with the DB and applies migrations for them.

`initdb`

### initdb

Initialises a new Pootle install.

This is part an optional part of Pootle’s install process, it creates the default admin user, populates the language table with several languages with their correct fields, initializes several terminology projects, and creates the tutorial project.

`initdb` can only be run after migrate.

Note

`initdb` will not import translations into the database, so the first visit to Pootle after `initdb` will be very slow. It is best to run `refresh_stats` immediately after initdb.

### collectstatic

Running the Django admin `collectstatic` command finds and extracts static content such as images, CSS and JavaScript files used by the Pootle server, so that they can be served separately from a static webserver. Typically, this is run with the `--clear` `--noinput` options, to flush any existing static data and use default answers for the content finders.

### assets

Pootle uses the Django app django-assets interface of webassets to minify and bundle CSS and JavaScript; this app has a management command that is used to make these preparations using the command `assets build`. This command is usually executed after the collectstatic one.

`webpack`

### webpack

New in version 2.7.

The webpack tool is used under the hood to bundle JavaScript scripts, and this management command is a convenient wrapper that sets everything up ready for production and makes sure to include any 3rd party customizations.

When the `--dev` flag is enabled, development builds will be created and the process will start a watchdog to track any client-side scripts for changes. Use this only when developing Pootle.

## Running WSGI servers

There are multiple ways to run Pootle, and some of them rely on running WSGI servers that can be reverse proxied to a proper HTTP web server such as nginx or lighttpd.

The Translate Toolkit offers a bundled CherryPy server but there are many more options such as gunicorn, flup, paste, etc.

`run_cherrypy`

### run_cherrypy

Run the CherryPy server bundled with the Translate Toolkit.

Available options:

`--host`

  The hostname to listen on.

  Default: `127.0.0.1`.

`--port`

  The TCP port on which the server should listen for new connections.

  Default: `8080`.

`--threads`

  The number of working threads to create.

  Default: `1`.

`--name`

  The name of the worker process.

  Default: `socket.gethostname()`.

`--queue`

  Specifies the maximum number of queued connections. This is the the `backlog` argument to `socket.listen()`.

  Default: `5`.

`--ssl_certificate`
  The filename of the server SSL certificate.
`--ssl_privatekey`
  The filename of the server’s private key file.

## Deprecated commands

The following are commands that have been removed or deprecated:

`last_change_id`

### last_change_id

Deprecated since version 2.7.

With the change to revisions the command you will want to use is `revision`, though you are unlikely to know a specific revision number as you needed to in older versions of `update_stores`.

`commit_to_vcs`

### commit_to_vcs

Deprecated since version 2.7.

Version Control support has been removed from Pootle and will reappear in a later release.

`update_from_vcs`

### update_from_vcs

Deprecated since version 2.7.

Version Control support has been removed from Pootle and will reappear in a later release.

## Running Commands in cron

If you want to schedule certain actions on your Pootle server, using management commands with cron might be a solution.

The management commands can perform certain batch commands which you might want to have executed periodically without user intervention.

For the full details on how to configure cron, read your platform documentation (for example `man crontab`). Here is an example that runs the `refresh_stats` command daily at 02:00 AM:

    00 02 * * * www-data /var/www/sites/pootle/manage.py refresh_stats

Test your command with the parameters you want from the command line. Insert it in the cron table, and ensure that it is executed as the correct user (the same as your web server) like www-data, for example. The user executing the command is specified in the sixth column. Cron might report errors through local mail, but it might also be useful to look at the logs in /var/log/cron/, for example.

If you are running Pootle from a virtualenv, or if you set any custom `PYTHONPATH` or similar, you might need to run your management command from a bash script that creates the correct environment for your command to run from. Call this script then from cron. It shouldn’t be necessary to specify the settings file for Pootle — it should automatically be detected.