mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +00:00
Add support for adding APT preferences
This commit is contained in:
parent
2532c588a8
commit
8d399dade5
6 changed files with 115 additions and 0 deletions
|
@ -83,6 +83,9 @@ class BootstrapInformation(object):
|
|||
# so that tasks may add to that list without having to fiddle with apt source list files.
|
||||
from pkg.sourceslist import SourceLists
|
||||
self.source_lists = SourceLists(self.manifest_vars)
|
||||
# Keep a list of apt preferences
|
||||
from pkg.preferenceslist import PreferenceLists
|
||||
self.preference_lists = PreferenceLists(self.manifest_vars)
|
||||
# Keep a list of packages that should be installed, tasks can add and remove things from this list
|
||||
from pkg.packagelist import PackageList
|
||||
self.packages = PackageList(self.manifest_vars, self.source_lists)
|
||||
|
|
|
@ -57,6 +57,33 @@
|
|||
"additionalProperties": false,
|
||||
"minItems": 1
|
||||
},
|
||||
"preferences": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[^\/\\0]+$": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"pin": {
|
||||
"type": "string"
|
||||
},
|
||||
"package": {
|
||||
"type": "string"
|
||||
},
|
||||
"pin-priority": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": ["pin", "package", "pin-priority"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"minItems": 1
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
"minItems": 1
|
||||
},
|
||||
"trusted-keys": {
|
||||
"type": "array",
|
||||
"items": { "$ref": "#/definitions/absolute_path" },
|
||||
|
|
49
bootstrapvz/base/pkg/preferenceslist.py
Normal file
49
bootstrapvz/base/pkg/preferenceslist.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
|
||||
|
||||
class PreferenceLists(object):
|
||||
"""Represents a list of preferences lists for apt
|
||||
"""
|
||||
|
||||
def __init__(self, manifest_vars):
|
||||
"""
|
||||
Args:
|
||||
manifest_vars (dict): The manifest variables
|
||||
"""
|
||||
# A dictionary with the name of the file in preferences.d as the key
|
||||
# That values are lists of Preference objects
|
||||
self.preferences = {}
|
||||
# Save the manifest variables, we need the later on
|
||||
self.manifest_vars = manifest_vars
|
||||
|
||||
def add(self, name, preferences):
|
||||
"""Adds a preference to the apt preferences list
|
||||
|
||||
Args:
|
||||
name (str): Name of the file in preferences.list.d, may contain manifest vars references
|
||||
preferences (object): The preferences
|
||||
"""
|
||||
name = name.format(**self.manifest_vars)
|
||||
self.preferences[name] = [Preference(p) for p in preferences]
|
||||
|
||||
|
||||
class Preference(object):
|
||||
"""Represents a single preference
|
||||
"""
|
||||
|
||||
def __init__(self, preference):
|
||||
"""
|
||||
Args:
|
||||
preference (dict): A apt preference dictionary
|
||||
|
||||
Raises:
|
||||
PreferenceError
|
||||
"""
|
||||
self.preference = preference
|
||||
|
||||
def __str__(self):
|
||||
"""Convert the object into a preference block
|
||||
|
||||
Returns:
|
||||
string.
|
||||
"""
|
||||
return "Package: {package}\nPin: {pin}\nPin-Priority: {pin-priority}\n".format(**self.preference)
|
|
@ -63,6 +63,9 @@ def get_apt_set(manifest):
|
|||
base.append(apt.AddManifestSources)
|
||||
if 'trusted-keys' in manifest.packages:
|
||||
base.append(apt.InstallTrustedKeys)
|
||||
if 'preferences' in manifest.packages:
|
||||
base.append(apt.AddManifestPreferences)
|
||||
base.append(apt.WritePreferences)
|
||||
if 'install' in manifest.packages:
|
||||
base.append(packages.AddManifestPackages)
|
||||
if manifest.packages.get('install_standard', False):
|
||||
|
|
|
@ -33,6 +33,16 @@ class AddDefaultSources(Task):
|
|||
info.source_lists.add('main', 'deb-src {apt_mirror} {system.release}-updates ' + sections)
|
||||
|
||||
|
||||
class AddManifestPreferences(Task):
|
||||
description = 'Adding preferences from the manifest'
|
||||
phase = phases.preparation
|
||||
|
||||
@classmethod
|
||||
def run(cls, info):
|
||||
for name, preferences in info.manifest.packages['preferences'].iteritems():
|
||||
info.preference_lists.add(name, preferences)
|
||||
|
||||
|
||||
class InstallTrustedKeys(Task):
|
||||
description = 'Installing trusted keys'
|
||||
phase = phases.package_installation
|
||||
|
@ -63,6 +73,23 @@ class WriteSources(Task):
|
|||
source_list.write('{line}\n'.format(line=str(source)))
|
||||
|
||||
|
||||
class WritePreferences(Task):
|
||||
description = 'Writing aptitude preferences to disk'
|
||||
phase = phases.package_installation
|
||||
predecessors = [WriteSources]
|
||||
|
||||
@classmethod
|
||||
def run(cls, info):
|
||||
for name, preferences in info.preference_lists.preferences.iteritems():
|
||||
if name == 'main':
|
||||
list_path = os.path.join(info.root, 'etc/apt/preferences')
|
||||
else:
|
||||
list_path = os.path.join(info.root, 'etc/apt/preferences.d/', name)
|
||||
with open(list_path, 'w') as preference_list:
|
||||
for preference in preferences:
|
||||
preference_list.write('{preference}\n'.format(preference=str(preference)))
|
||||
|
||||
|
||||
class DisableDaemonAutostart(Task):
|
||||
description = 'Disabling daemon autostart'
|
||||
phase = phases.package_installation
|
||||
|
|
|
@ -15,6 +15,12 @@ Sources list
|
|||
:members:
|
||||
:private-members:
|
||||
|
||||
Preferences list
|
||||
------------
|
||||
.. automodule:: bootstrapvz.base.pkg.preferenceslist
|
||||
:members:
|
||||
:private-members:
|
||||
|
||||
Exceptions
|
||||
----------
|
||||
.. automodule:: bootstrapvz.base.pkg.exceptions
|
||||
|
|
Loading…
Add table
Reference in a new issue