File object¶
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.
Attributes¶
File objects contain the following attributes:
name¶
- SourceFile.name
- The name of the file on disk. This does not include the file extension, as that is stored in file-format.
path¶
- SourceFile.path
- A
Pathlib.Path
object representing this file’s actual path on disk. Note that the file may not actually exist on disk yet.
format¶
- SourceFile.format
- The format this file should be saved in. Saved as a enum_sourceformat.
contents¶
- SourceFile.contents
- A
list
containing, in order, every comment line and source in this file.
sources¶
- SourceFile.sources
- A
list
containing, in order, only the sources in this file.
Methods¶
add_source()¶
- 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.
source¶
The source to add to the file.
remove_source()¶
- SourceFile.remove_source(ident: str) -> None
- Removes the source with a specified ident from this file.
ident¶
The ident of the source to remove from the file.
get_source_by_ident()¶
- SourceFile.get_source_by_ident(ident: str) ->
Source
- 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.
ident¶
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.sources
exists on disk, the path will be set to that, otherwise if thename.list
exists, it will be set to that instead. Failing both, the path will fallback toname.sources
as a default.
load()¶
- 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.
save()¶
- 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.
Output¶
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.
deb822¶
- SourceFile.deb822
- Outputs the entire file as DEB822-formatted sources
legacy¶
- SourceFile.legacy
- Outputs the entire file as one-line legacy-formatted deb lines
ui¶
- SourceFile.ui
- Outputs the file in a format for output through a UI (e.g. for preview or external parsing.)
output¶
- SourceFile.output
- Outputs the entire file in the format matching that configured in file-format.