Source object

The Source object is the base class for all of the sources used within RepoLib. The Source class itself is a subclass of the deb822() class from the Python Debian module, which provides a dict-like interface for setting data as well as several methods for dumping data to files and other helpful functions.

class repolib.Source (file=None)

Create a new Source object.

The Source object has the following attributes:

  • ident - The system-identifier to use for this source.
  • name - The human-readable name of the source. (default: ‘’)
  • enabled - Whether the source is enabled or not at creation. (default: True)
  • types - A list of the types that the source should use. (default: [])
  • uris - A list of URIs from which to fetch software or check for updates. (default: [])
  • suites - Suites in which to narrow available software. (default: [])
  • components - Components of the source repository to enable. (default: [])
  • signed_by - The path to the signing key for this source
  • file - The File object for this source
  • key - The Key object for this source.
  • twin_source: - This source should be saved with both binary and source code types enabled.

The following decribe how each of these are used.

ident

The ident is the system-identifier for this source. This determines the filename the source will use on-disk as well as the way to specify a source to load.

name

This is a human-readable and nicely-formatted name to help a user recognize what this source is. Any unicode character is allowed in this field. If a source is opened which doesn’t have a name field, the filename will be used.

name is a string value, set to '' by default. If there is no name in a loaded source, it will be set to the same as the filename (minus the extension).

This field maps to the X-Repolib-Name: field in the .sources file, which is ignored by Apt and other standards-compliant sources parsers.

enabled

Apt sources can be disbaled without removing them entirely from the system. A disabled source is excluded from updates and new software installs, but it can be easily re-enabled at any time. It defaults to True.

This field maps to the Enabled: field in the .sources file. This is optional per the DEB822 standard, however if set to anything other than no, the source is considered enabled.

types

Debian archives may contain either binary packages or source code packages, and this value specifies which of those Apt should look for in the source. deb is used to look for binary packages, while deb-src looks for source code packages. RepoLib stores this value as a list of aptsourcetype-enum`s, and defaults to ``[AptSourceType.BINARY]`.

This field maps to the Types: field in the sources file.

uris

A list of string values describing the URIs from which to fetch package lists and software for updates and installs. The currently recognized URI types are:

  • file
  • cdrom
  • http
  • ftp
  • copy
  • rsh
  • ssh

DEB822 sources may directly contain an arbitrary number of URIs. Legacy sources may also have multiple URIs; however, these require writing a new deb line for each URI as the one-line format only allows a single URI per source.

Note

Although these are the currently-recognized official URI types, Apt can be extended with additional URI schemes through extension packages. Thus it is not recommended to parse URIs by type and instead rely on user input being correct and to throw exceptions when that isn’t the case.

suites

The Suite, also known as the distribution specifies a subdirectory of the main archive root in which to look for software. This is typically used to differentiate versions for the same OS, e.g. disco or cosmic for Ubuntu, or squeeze and unstable for Debian.

DEB822 Sources allow specifying an arbitrary number of suites. One-line sources also support multiple suites, but require an additional repo line for each as the one-line format only allows a single suite for each source.

This value maps to the Suites: field in the sources file.

components

This value is a list of strings describing the enabled distro components to download software from. Common values include main, restricted, nonfree, etc.

signed_by

The path to the keyring containing the signing key used to verify packages downloaded from this repository. This should generally match the key-path attribute for this source’s key object.

file

The File object for the file which contains this source.

key

The Key object for this source.

Methods

Source.get_description() -> str
Returns a str containing a UI-compatible description of the source.

reset_values()

Source.reset_values()
Initializes the Source’s attributes with default data in-order. This is recommended to ensure that the fields in the underlying deb822 Dict are in order and correctly capitalized.

load_from_data()

Source.load_from_data(data: list) -> None
Loads configuration information from a list of data, rather than using manual entry. The data can either be a list of strings with DEB822 data, or a single-element list containing a one-line legacy line.

data

The data load load into the source. If this contains a legacy-format one-line repository, it must be a single-element list. Otherwise, it should contain a list of strings, each being a line from a DEB822 configuration.

generate_default_ident()

Source.generate_default_ident(prefix: str = ‘’) -> str
Generates a suitable default ident, optionally with a prefix, and sets it. The generated ident is also returned for processing convenience.

prefix

The prefix to prepend to the ident.

generate_default_name()

Source.generate_default_name() ->
Generates a default name for the source and sets it. The generated name is also returned for convenience.

load_key()

Source.load_key(ignore_errors: bool = True) -> None
Finds the signing key for this source spefified in signed_by and loads a Key object for it.

ignore_errors

If False, raise a exc_sourceerror if the key can’t be loaded or doesn’t exist.

save()

Source.save()
Proxy method for the file-save method for this source’s File object.

There are three output properties which contain the current source data for output in a variety of formats.

deb822

Source.deb822
A representation of the source data as a DEB822-formatted string

legacy

Source.legacy
A one-line formatted string of the source. It twin_source is True, then there will additionally be a deb-src line following the primary line.

ui

Source.ui
A representation of the source with certain key names translated to better represent their use in a UI for display to a user.