mini_buildd.models.base module

Generic module for models of the django app mini_buildd.

Naming conventions

Model class and field names

All model class names and all field names must be human readable with no abbreviations (as django, per default, displays the internal names intelligently to the end user).

Model class names must be in CamelCase.

Field names must be all lowercase and seperatedy by underscores.

For example, don’t try to do sort of “grouping” using names like:

email_notify
email_allow_regex

This should rather read:

notify
allow_emails_to

To group fields together for the end user, use AdminModel’s fieldset option.

Methods

Any methods that represent mini-buildd logic should go into the models directly, but must be prefixed with “mbd_”. This avoids conflicts with method names form the django model’s class, but still keeps the logic where it belongs.

class mini_buildd.models.base.Model(*args, **kwargs)

Bases: django.db.models.base.Model

Abstract father model for all mini-buildd models.

This just makes sure no config is changed or deleted while the daemon is running.

extra_options

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

pickled_data

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class Meta

Bases: object

abstract = False
app_label = 'mini_buildd'
class Admin(model, admin_site)

Bases: django.contrib.admin.options.ModelAdmin

save_model(request, obj, form, change)

Given a model instance save it to the database.

delete_model(request, obj)

Given a model instance delete it from the database.

media
classmethod mbd_get_daemon()
mbd_get_extra_options()
mbd_get_extra_option(key, default=None)
mbd_get_pickled_data(default=None)
mbd_set_pickled_data_pickled(pickled_data)
mbd_set_pickled_data(data)
classmethod mbd_validate_regex(regex, value, field_name)
mbd_get_dependencies()
mbd_get_reverse_dependencies()
classmethod mbd_get_or_create(msglog, **kwargs)

Like get_or_create, but adds a info message.

class mini_buildd.models.base.StatusModel(*args, **kwargs)

Bases: mini_buildd.models.base.Model

Abstract model class for all models that carry a status. See Manual: Configuration.

STATUS_REMOVED = 0
STATUS_PREPARED = 1
STATUS_ACTIVE = 2
STATUS_CHOICES = ((0, 'Removed'), (1, 'Prepared'), (2, 'Active'))
STATUS_COLORS = {0: {'bg': 'red', 'fg': 'black'}, 1: {'bg': 'yellow', 'fg': 'black'}, 2: {'bg': 'green', 'fg': 'white'}}
status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

CHECK_NONE = datetime.datetime(1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
CHECK_CHANGED = datetime.datetime(1, 1, 2, 0, 0, tzinfo=datetime.timezone.utc)
CHECK_FAILED = datetime.datetime(1, 1, 3, 0, 0, tzinfo=datetime.timezone.utc)
CHECK_REACTIVATE = datetime.datetime(1, 1, 4, 0, 0, tzinfo=datetime.timezone.utc)
CHECK_STRINGS = {datetime.datetime(1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc): {'char': '-', 'string': 'Unchecked -- please run check'}, datetime.datetime(1, 1, 2, 0, 0, tzinfo=datetime.timezone.utc): {'char': '*', 'string': 'Changed -- please prepare again'}, datetime.datetime(1, 1, 3, 0, 0, tzinfo=datetime.timezone.utc): {'char': 'x', 'string': 'Failed -- please fix and check again'}, datetime.datetime(1, 1, 4, 0, 0, tzinfo=datetime.timezone.utc): {'char': 'A', 'string': 'Failed in active state -- will auto-activate when check succeeds again'}}
last_checked

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

LETHAL_DEPENDENCIES = True
auto_reactivate

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class Meta

Bases: mini_buildd.models.base.Meta

abstract = False
class Admin(model, admin_site)

Bases: mini_buildd.models.base.Admin

save_model(request, obj, form, change)

Given a model instance save it to the database.

classmethod mbd_prepare(request, obj)
classmethod mbd_check(request, obj, force=False, needs_activation=False)
classmethod mbd_activate(request, obj)
classmethod mbd_deactivate(request, obj)
classmethod mbd_remove(request, obj)
classmethod mbd_action(request, queryset, action, **kwargs)

Try to run action on each object in queryset.

Emit error message on failure, but don’t fail ourself.

mbd_action_prepare(request, queryset)
mbd_action_check(request, queryset)
mbd_action_activate(request, queryset)
mbd_action_deactivate(request, queryset)
mbd_action_remove(request, queryset)
mbd_action_pc(request, queryset)
mbd_action_pca(request, queryset)
classmethod mbd_meta_pca_all(msglog)

Run prepare, check, and activate for all objects of this model.

colored_status(obj)
actions = [<function StatusModel.Admin.mbd_action_prepare>, <function StatusModel.Admin.mbd_action_check>, <function StatusModel.Admin.mbd_action_pc>, <function StatusModel.Admin.mbd_action_activate>, <function StatusModel.Admin.mbd_action_pca>, <function StatusModel.Admin.mbd_action_deactivate>, <function StatusModel.Admin.mbd_action_remove>]
list_display = ['colored_status', '__str__']
media
days_until_recheck

Field temporarily implemented as extra_option.

Note

Currently using 6 days as default value – as it copes better with the current setup to restart mini-buildd weekly (via cron.weekly) to actually achieve automated checking.

mbd_set_changed(request)
mbd_is_prepared()
mbd_is_active()
mbd_is_checked()
mbd_needs_check()
mbd_is_changed()
classmethod mbd_get_active()
classmethod mbd_get_active_or_auto_reactivate()
classmethod mbd_get_prepared()
mbd_get_check_display(typ='string')
mbd_get_status_display(typ='string')
get_next_by_last_checked(*, field=<django.db.models.fields.DateTimeField: last_checked>, is_next=True, **kwargs)
get_previous_by_last_checked(*, field=<django.db.models.fields.DateTimeField: last_checked>, is_next=False, **kwargs)
get_status_display(*, field=<django.db.models.fields.IntegerField: status>)