checking in before i change a regex pattern. this currently will grab commented out defaults, but we don't want that since it complicates things - so we hardcode in shipped defaults.

This commit is contained in:
2019-12-30 12:59:52 -05:00
parent 7f3b8b98aa
commit c22b473b49
9 changed files with 124 additions and 18 deletions

68
aif/pacman/__init__.py Normal file
View File

@@ -0,0 +1,68 @@
# We can manually bootstrap and alter pacman's keyring. But check the bootstrap tarball; we might not need to.
# TODO.
import configparser
import logging
import os
import re
##
import pyalpm
import gpg
##
from . import _common
_logger = logging.getLogger(__name__)
_skipconfline_re = re.compile(r'^[ \t]*#([ \t]+.*)?$')
class PackageManager(object):
def __init__(self, chroot_base):
self.chroot_base = chroot_base
self.pacman_dir = os.path.join(self.chroot_base, 'var', 'lib', 'pacman')
self.configfile = os.path.join(self.chroot_base, 'etc', 'pacman.conf')
self.config = None
self._parseConf()
def _parseConf(self):
_cf = []
with open(self.configfile, 'r') as fh:
for line in fh.read().splitlines():
if _skipconfline_re.search(line) or line.strip() == '':
continue
_cf.append(re.sub(r'^#', '', line))
self.config = configparser.ConfigParser(allow_no_value = True,
interpolation = None,
strict = False,
dict_type = _common.MultiOrderedDict)
self.config.optionxform = str
self.config.read_string('\n'.join(_cf))
self.opts = {'Architecture': 'auto',
'CacheDir': '/var/cache/pacman/pkg/',
'CheckSpace': None,
'CleanMethod': 'KeepInstalled',
# 'Color': None,
'DBPath': '/var/lib/pacman/',
'GPGDir': '/etc/pacman.d/gnupg/',
'HoldPkg': 'pacman glibc',
'HookDir': '/etc/pacman.d/hooks/',
'IgnoreGroup': '',
'IgnorePkg': '',
'LocalFileSigLevel': 'Optional',
'LogFile': '/var/log/pacman.log',
'NoExtract': '',
'NoUpgrade': '',
'RemoteFileSigLevel': 'Required',
'RootDir': '/',
'SigLevel': 'Required DatabaseOptional',
# 'TotalDownload': None,
# 'UseSyslog': None,
# 'VerbosePkgLists': None,
'XferCommand': '/usr/bin/curl -L -C - -f -o %o %u'
}
self.distro_repos = ['']
_opts = dict(self.config.items('options'))
self.opts.update(_opts)
self.config.remove_section('options')

19
aif/pacman/_common.py Normal file
View File

@@ -0,0 +1,19 @@
import configparser
import logging
from collections import OrderedDict
_logger = logging.getLogger('pacman:_common')
class MultiOrderedDict(OrderedDict):
# Thanks, dude: https://stackoverflow.com/a/38286559/733214
def __setitem__(self, key, value):
if key in self:
if isinstance(value, list):
self[key].extend(value)
return(None)
elif isinstance(value, str):
if len(self[key]) > 1:
return(None)
super(MultiOrderedDict, self).__setitem__(key, value)