SourceFile objects are the interface between the OS storage and the repolib Source object items. Files contain sources and comments and allow for loading sources from and saving them to disk. They also assign idents to sources in a way that ensures each source has a unique ident.
File objects contain the following attributes:
- The name of the file on disk. This does not include the file extension, as that is stored in file-format.
Pathlib.Pathobject representing this file’s actual path on disk. Note that the file may not actually exist on disk yet.
- The format this file should be saved in. Saved as a enum_sourceformat.
listcontaining, in order, every comment line and source in this file.
listcontaining, in order, only the sources in this file.
- SourceFile.add_source(source) -> None
- Adds a given source to the file. This correctly appends the source to both the file-contents and file-sources lists, and sets the source-file attribute of the source to this file.
The source to add to the file.
- SourceFile.remove_source(ident: str) -> None
- Removes the source with a specified ident from this file.
The ident of the source to remove from the file.
- SourceFile.get_source_by_ident(ident: str) ->
- Finds a source within this file given a specified ident and returns the Source object matching that ident. If the file does not contain a Source matching the given ident, raises a exc_sourcefileerror.
The ident to look up.
- SourceFile.reset_path() -> None
- Attempts to detect the full path to the file given the file-name
attribute for this file. If the
name.sourcesexists on disk, the path will be set to that, otherwise if the
name.listexists, it will be set to that instead. Failing both, the path will fallback to
name.sourcesas a default.
- SourceFile.load() -> None
- Loads the file specified by path from disk, creating sources and comments and appending them in order to the file-contents and file-sources lists as appropriate.
- SourceFile.save() -> None
- Saves the file and any sources currently configured to disk. This method must be called to commit changes to disk. If the file currently contains no sources, then the file will instead be deleted.
There are four attributes which contain the output of the files stored as strings and which are ready for full output in the specified format.
- Outputs the entire file as DEB822-formatted sources
- Outputs the entire file as one-line legacy-formatted deb lines
- Outputs the file in a format for output through a UI (e.g. for preview or external parsing.)
- Outputs the entire file in the format matching that configured in file-format.