Skip to main content

Apt Preferences

Description

Python package to modify apt preferences files in line with https://manpages.debian.org/buster/apt/apt_preferences.5.en.html.

I don't like using awk and sed for updating preferences cause it's got messier the bigger amount of preferences is connected to a package. If regexes are used in packages names then it's even harder. This package along with re should make more complex preferences scenarios easy to automate.

And I wanted to learn LARK so that is also a big pron of the project.

Table of Contents

Installation

Create virtual environment

make venv

Activate virtual environment

. .venv/bin/activate

Install package

make install

Usage

from apt_preferences.data_structures import AptPreference
from apt_preferences.render_preferences_files import render_preferences_files

# lets assume this is a parsed preferences file
my_prefs_l = [AptPreference(package="*", pin="release n=jammy", pin_priority=700, file_path="/etc/apt/preferences", explanations={})]

# we would like to change pin priority for one of file preferences
my_pref = my_prefs_l[0]

# pin priority is modified
my_pref.pin_priority = 100

# preference with modified pin priority is saved to the file
render_preferences_files(my_prefs_l)

For more examples look into /examples directory.

Run example

python examples/read_preferences.py

Features:

  • Parse apt preferences' files into Python objects list.
  • Generate new apt preferences' files based on Python objects list.

Planned features:

  • Support multiple pins in single preference.
  • Comment out objects via AptPreference method.

Limitations:

  • If a line starts with # it will be ignored by the parser.
  • The generator doesn't allow creating lines starting with #.

Credits

Me, Myself and I.

License

MIT License

Copyright (c) [2023] [Jakub Buczyński]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Metadata

Release files for apt-preferences 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apt-preferences 0.0.1
File Size Uploaded Provenance
apt_preferences-0.0.1.tar.gz 13.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for apt-preferences 0.0.1
File Interpreter ABI Platform
apt_preferences-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.3 kB

Release files / apt_preferences-0.0.1.tar.gz

Download URL apt_preferences-0.0.1.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
11370d9a10039e7d7500b591c4b08e8a87b553608957a2fb07a596a011294114
BLAKE2b-256 checksum
How to use checksums
fed65f24aaa1d9885fa7f7ff91befa28b131ce4eb87ec4b22aeb6bba49ba0c77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / apt_preferences-0.0.1-py3-none-any.whl

Download URL apt_preferences-0.0.1-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbee6a14b5c75c44b89be56b0621039a23ff38bd0b13c2b6aa79daa6798e4b4e
BLAKE2b-256 checksum
How to use checksums
0a6914bf12988a153d659f6c718c72cffc69f959d333809cc03783f9b40a1014
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Security for apt-preferences 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page