Skip to content

commands.utils ​

Overview ​

Utilities for group migration management commands.

call_management_command ​

Run args through Django's call_command, capturing its output.

command is the BaseCommand instance invoking this (needs .dry_run, .style, .stdout). A trailing --dry-run is appended automatically when command.dry_run is set and the command being run is makemigrations. Exits the process with status 2 if the command wrote to stderr.

Signature ​

call_management_command(command, args)

Parameters ​

NameTypeRequiredDefaultDescription
commandyes
argsno

Source ​

server/vueda/user/management/commands/utils.py:268

create_group_change ​

Create a group_change_model row from change, keep its original when timestamp, and return its pk.

Generated group migrations copy this function into their source.

Signature ​

create_group_change(change, group_change_model)

Parameters ​

NameTypeRequiredDefaultDescription
changeyes
group_change_modelyes

Source ​

server/vueda/user/management/commands/utils.py:231

get_matching_record ​

Return GroupChange.pk if a record matching this change exists, None otherwise.

Signature ​

get_matching_record(change, group_change_model)

Parameters ​

NameTypeRequiredDefaultDescription
changeyes
group_change_modelyes

Source ​

server/vueda/user/management/commands/utils.py:215

get_migration_names_from_show_migrations ​

Return the migration names for app_label by running showmigrations through command.

Returns None when showmigrations prints nothing.

Signature ​

get_migration_names_from_show_migrations(command, app_label)

Parameters ​

NameTypeRequiredDefaultDescription
commandyes
app_labelyes

Source ​

server/vueda/user/management/commands/utils.py:323

get_migrations_path ​

Return the directory of the migrations package for app_config, honoring MIGRATION_MODULES.

Returns None when migrations are disabled, the module cannot be imported, or it is a single module.

Signature ​

get_migrations_path(app_config)

Parameters ​

NameTypeRequiredDefaultDescription
app_configyes

Source ​

server/vueda/user/management/commands/utils.py:335

has_direct_runpython_import ​

Return True if lines imports RunPython directly, e.g. from django.db.migrations import RunPython, rather than only accessing it via migrations.RunPython.

lines is a list of strings, as returned by readlines(). Only module-level from ... import statements are considered, so a RunPython import nested inside a copied function source is never matched.

Signature ​

has_direct_runpython_import(lines)

Parameters ​

NameTypeRequiredDefaultDescription
linesyes

Source ​

server/vueda/user/management/commands/utils.py:252

locate_empty_migration_slots ​

Locate the line numbers of the key components of a freshly generated, empty migration.

lines is a list of strings, as returned by readlines(), for a migration file created while migrations.Migration.operations was forced to a known, findable shape (two RunPython calls using dict/type and str/int as placeholder code/reverse_code values). Returns a dict of 0-based line numbers: class_index (the class Migration line), dependencies_index (the dependencies = [...] assignment), import_start/import_end (the import block), and the four placeholder keyword-value locations (p_forwards_index, p_reverse_index, forwards_index, reverse_index). Raises RuntimeError if any of them can't be found, e.g. because Django changed the shape of the empty-migration template it emits.

Signature ​

locate_empty_migration_slots(lines)

Parameters ​

NameTypeRequiredDefaultDescription
linesyes

Source ​

server/vueda/user/management/commands/utils.py:360

parse_date_from_django_comment ​

Return the UTC date in a migration's "Generated by Django ... on" comment, converted to local time.

Signature ​

parse_date_from_django_comment(django_comment)

Parameters ​

NameTypeRequiredDefaultDescription
django_commentyes

Source ​

server/vueda/user/management/commands/utils.py:314

parse_migrations_from_show_migrations ​

Return the migration names listed in showmigrations output lines, without their applied markers.

Signature ​

parse_migrations_from_show_migrations(lines)

Parameters ​

NameTypeRequiredDefaultDescription
linesyes

Source ​

server/vueda/user/management/commands/utils.py:301

Source ​

server/vueda/user/management/commands/utils.py