bootstrap-vz/base/pkg/sourceslist.py
Anders Ingemann 1c93094833 Integrated package plugin with base system
New phase introduced "package installation" (fixes #114)
Apt source lines are now parsed, this allows to verify the target release of added packages.
All packages (except locales) are now installed *after* bootstrapping (fixes #123)
Added env argument to log_(check_)call
HostDependencies have been refactored a little
2013-12-29 20:58:06 +01:00

63 lines
2.2 KiB
Python

class SourceLists(object):
def __init__(self, manifest):
self.sources = {}
self.manifest_vars = {'release': manifest.system['release'],
'architecture': manifest.system['architecture'],
'apt_mirror': 'http://http.debian.net/debian'}
if 'sources' in manifest.packages:
for name, lines in manifest.packages['sources'].iteritems():
for line in lines:
self.add_source(name, '{line}\n'.format(line=line.format(**self.manifest_vars)))
def add_source(self, name, line):
name = name.format(**self.manifest_vars)
if name not in self.sources:
self.sources[name] = []
self.sources[name].append(Source(line))
def target_exists(self, target):
for lines in self.sources.itervalues():
if target in (source.distribution for source in lines):
return True
return False
class Source(object):
def __init__(self, line):
import re
regexp = re.compile('^(?P<type>deb|deb-src)\s+'
'(\[\s*(?P<options>.+\S)?\s*\]\s+)?'
'(?P<uri>\S+)\s+'
'(?P<distribution>\S+)'
'(\s+(?P<components>.+\S))?\s*$')
match = regexp.match(line).groupdict()
if match is None:
from exceptions import SourceError
raise SourceError('Unable to parse source line `{line}\''.format(line=line))
self.type = match['type']
self.options = []
if match['options'] is not None:
self.options = re.sub(' +', ' ', match['options']).split(' ')
self.uri = match['uri']
self.distribution = match['distribution']
self.components = []
if match['components'] is not None:
self.components = re.sub(' +', ' ', match['components']).split(' ')
def __str__(self):
options = ''
if len(self.options) > 0:
options = ' [{options}]'.format(options=' '.join(self.options))
components = ''
if len(self.components) > 0:
components = ' {components}'.format(components=' '.join(self.components))
return ('{type}{options} {uri}'
' {distribution}{components}').format(type=self.type, options=options,
uri=self.uri, distribution=self.distribution,
components=components)