grml cleaned up, testing

This commit is contained in:
2021-01-21 11:34:06 -05:00
parent 7c8f25ea03
commit 0e8d460565
6 changed files with 300 additions and 25 deletions

View File

@@ -13,6 +13,9 @@ class BaseUpdater(object):
_tpl_dir = os.path.join(os.path.dirname(os.path.abspath(os.path.expanduser(__file__))), 'tpl')
_tpl_file = None
_date_fmt = '%a, %d %b %Y %H:%M:%S %z'
_tpl_vars = {}
arch = None
variant = None
def __init__(self,
dest_dir,
@@ -49,6 +52,19 @@ class BaseUpdater(object):
self.dest_iso = os.path.join(self.dest_dir, self.dest_file)
self.dest_ver = os.path.join(self.dest_dir, self.ver_file)
def _init_tplvars(self):
self.getUUID()
self._tpl_vars['iso_path'] = os.path.abspath(
os.path.expanduser(
os.path.join(self.grub_iso_dir,
self.dest_file))).lstrip('/')
self._tpl_vars['disk_uuid'] = self.boot_uuid
self._tpl_vars['version'] = self.new_ver
self._tpl_vars['arch'] = self.arch
self._tpl_vars['ver_str'] = str(self.new_ver).replace('.', '')
self._tpl_vars['variant'] = self.variant
return(None)
def main(self):
if self.getRunning():
return(None)
@@ -61,6 +77,7 @@ class BaseUpdater(object):
self.do_update = True
self.download()
if self.do_grub:
self._init_tplvars()
self.grub()
self.touchVer()
self.unlock()
@@ -133,17 +150,12 @@ class BaseUpdater(object):
return(None)
def grub(self):
self.getUUID()
import jinja2
loader = jinja2.FileSystemLoader(searchpath = self._tpl_dir)
tplenv = jinja2.Environment(loader = loader)
tpl = tplenv.get_template(self._tpl_file)
with open(self.grub_cfg, 'w') as fh:
fh.write(tpl.render(iso_path = os.path.abspath(
os.path.expanduser(
os.path.join(self.grub_iso_dir,
self.dest_file))).lstrip('/'),
disk_uuid = self.boot_uuid))
fh.write(tpl.render(**self._tpl_vars))
os.chmod(self.grub_cfg, 0o0755)
cmd = subprocess.run(['grub-mkconfig',
'-o', '{0}/grub/grub.cfg'.format(self.boot_dir)],