okay, some minor changes to the XML stuff. getting there

This commit is contained in:
2019-12-10 06:59:47 -05:00
parent c7ce23ff0f
commit 06c99221d2
8 changed files with 103 additions and 1244 deletions

View File

@@ -11,8 +11,9 @@ _locale_def_re = re.compile(r'([^.]*)[^@]*(.*)')
class Locale(object):
def __init__(self, locales_xml):
def __init__(self, chroot_base, locales_xml):
self.xml = locales_xml
self.chroot_base = chroot_base
self.syslocales = {}
self.userlocales = []
self.rawlocales = None
@@ -31,8 +32,8 @@ class Locale(object):
self.userlocales = ['en_US', 'en_US.UTF-8']
return()
def _verify(self, chroot_base):
localegen = os.path.join(chroot_base, 'etc', 'locale.gen') # This *should* be brand new.
def _verify(self):
localegen = os.path.join(self.chroot_base, 'etc', 'locale.gen') # This *should* be brand new.
with open(localegen, 'r') as fh:
self.rawlocales = fh.read().splitlines()
for idx, line in enumerate(self.rawlocales[:]):
@@ -50,12 +51,12 @@ class Locale(object):
raise ValueError('non-existent locale specified')
return()
def writeConf(self, chroot_base):
def writeConf(self):
# We basically recreate locale-gen in python here, more or less.
self._verify(chroot_base)
localegen = os.path.join(chroot_base, 'etc', 'locale.gen')
localedbdir = os.path.join(chroot_base, 'usr', 'lib', 'locale')
localesrcdir = os.path.join(chroot_base, 'usr', 'share', 'i18n')
self._verify()
localegen = os.path.join(self.chroot_base, 'etc', 'locale.gen')
localedbdir = os.path.join(self.chroot_base, 'usr', 'lib', 'locale')
localesrcdir = os.path.join(self.chroot_base, 'usr', 'share', 'i18n')
with open(localegen, 'w') as fh:
fh.write('# Generated by AIF-NG.\n\n')
fh.write('\n'.join(self.rawlocales))
@@ -86,12 +87,12 @@ class Locale(object):
# '--charmap={0}'.format(os.path.join(localesrcdir, 'charmaps', charset)),
'--inputfile={0}'.format(ldef_name),
'--charmap={0}'.format(charset),
'--alias-file={0}'.format(os.path.join(chroot_base,
'--alias-file={0}'.format(os.path.join(self.chroot_base,
'usr', 'share', 'locale', 'locale.alias')),
'--prefix={0}'.format(chroot_base),
'--prefix={0}'.format(self.chroot_base),
locale],
env = env)
cfg = os.path.join(chroot_base, 'etc', 'locale.conf')
cfg = os.path.join(self.chroot_base, 'etc', 'locale.conf')
# And now we write the variables.
# We have to strip out the section from the ini.
cfgbuf = io.StringIO()
@@ -108,19 +109,20 @@ class Locale(object):
class Timezone(object):
def __init__(self, timezone):
def __init__(self, chroot_base, timezone):
self.tz = timezone.strip().replace('.', '/')
self.chroot_base = chroot_base
def _verify(self, chroot_base):
def _verify(self):
tzfilebase = os.path.join('usr', 'share', 'zoneinfo', self.tz)
tzfile = os.path.join(chroot_base, tzfilebase)
tzfile = os.path.join(self.chroot_base, tzfilebase)
if not os.path.isfile(tzfile):
raise ValueError('Invalid timezone')
return(tzfilebase)
def apply(self, chroot_base):
tzsrcfile = os.path.join('/', self._verify(chroot_base))
tzdestfile = os.path.join(chroot_base, 'etc', 'localtime')
def apply(self):
tzsrcfile = os.path.join('/', self._verify())
tzdestfile = os.path.join(self.chroot_base, 'etc', 'localtime')
if os.path.isfile(tzdestfile):
os.remove(tzdestfile)
os.symlink(tzsrcfile, tzdestfile)