bpo.db package

Submodules

bpo.db.migrate module

Full migration libraries like alembic are overkill for this simple program. Instead of creating a dedicated script for migrating back and forth with each change, only add three lines for each change below, and add a comment in bpo/db/__init__.py to the original db layout to indicate what has changed. This means we can only migrate forward, but that’s fine for our use case. Whenever a new database file is created, it starts with the layout 0 defined in bpo/db/__init__.py and then applies all upgrades from here.

bpo.db.migrate.upgrade()
bpo.db.migrate.version_get()
bpo.db.migrate.version_set(version)

Module contents

Database code, using sqlalchemy ORM.

Usage example:

session = bpo.db.session() log = bpo.db.Log(action=”db_init”, details=”hello world”) session.add(logled) session.commit()

class bpo.db.Image(device, branch, ui)

Bases: Base

branch
date
device
dir_name
id
job_id
last_update
retry_count
status
ui
class bpo.db.ImageStatus(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

building = 1
failed = 4
published = 3
queued = 0
class bpo.db.Log(action, payload=None, arch=None, branch=None, pkgname=None, version=None, job_id=None, retry_count=None, device=None, ui=None, dir_name=None, depend_pkgname=None, commit=None, count=None)

Bases: Base

action
arch
branch
commit
count
date
depend_pkgname
device
dir_name
id
job_id
payload
pkgname
retry_count
ui
version
class bpo.db.Package(arch, branch, pkgname, version, status=PackageStatus.queued)

Bases: Base

arch
branch
date
depends_built()
depends_missing_list()
id
job_id
last_update
pkgname
repo
retry_count
status
version
class bpo.db.PackageStatus(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

building = 1
built = 2
failed = 4
published = 3
queued = 0
class bpo.db.RepoBootstrap(arch, branch, dir_name='/')

Bases: Base

arch
branch
dir_name
id
job_id
retry_count
status
class bpo.db.RepoBootstrapStatus(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

building = 1
built = 2
failed = 4
published = 3
queued = 0
bpo.db.get_failed_packages_count_relevant(session)
Returns:

count of failed packages, without the branches where ignore_errors is set

(it’s always set for staging branches, and usually for branches we build for the first time as we prepare a new release).

bpo.db.get_image(session, branch, device, ui, job_id=None)

Get a branch:device:ui specific image, that is currently being processed (status is not finished). Unlike packages, we keep more than just the latest entry in the database.

bpo.db.get_package(session, pkgname, arch, branch, job_id=None)
bpo.db.get_recent_images_by_status(session)
Returns:

{“failed”: imglist1, “building”: imglist2, …}, imglist is a list of bpo.db.Image objects

bpo.db.get_recent_packages_by_status(session)
Returns:

a dict like this (pkglist is a list of bpo.db.Package objects):

{“queued”: pkglist1, “building”: pkglist2,

“built”: pkglist3, “published”: pkglist4, “failed”: pkglist5, “built_synced”: {“master_staging_test”: {“x86_64”: 5, “aarch64”: 3}}, “published_synced”: {…}} # same format as built_synced

bpo.db.get_repo_bootstrap(session, arch, branch, dir_name='/', job_id=None)
bpo.db.init()

Initialize db

bpo.db.init_relationships()
bpo.db.package_has_version(session, pkgname, arch, branch, version)
bpo.db.set_image_status(session, image, status, job_id=None, dir_name=None, date=None)
Parameters:
  • image – bpo.db.Image object

  • status – bpo.db.ImageStatus value

  • job_id – job ID (i.e. job number from sourcehut builds)

  • dir_name – directory that holds the image files

  • date – new date (once the image is built, the previous date from when the image was queued gets updated to the date when the image was published)

bpo.db.set_package_status(session, package, status, job_id=None)
Parameters:
  • package – bpo.db.Package object

  • status – bpo.db.PackageStatus value

bpo.db.set_repo_bootstrap_status(session, rb, status, job_id=None)
bpo.db.validate_job_id(db_result, job_id)
Parameters:
  • db_result – either None or a db object with job_id param (Package, Image)

  • job_id – either None or the job ID passed from an API call, that the job service (sourcehut, local) assigned to the job

Returns:

True if the job_id matches, False if either db_result or job_id are None