Skip to content

Commit

Permalink
Added a nice APT library along with the supportrepo module (set-ups t…
Browse files Browse the repository at this point in the history
…he support repo present in latest snapshots)

modules/bootloader: inst: fetch bootloader from supportrepo, if we can

core/main: support for enums.
  • Loading branch information
g7 committed Jun 24, 2013
1 parent 850263a commit e7362ef
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 11 deletions.
5 changes: 4 additions & 1 deletion config/semplice-base
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[linstaller]
distribution = Semplice
modules = uefidetect.inst welcome.front language.front update.front timezone.front userhost.front partdisks.front bootloader.front bricks.front mirrorselect.front summary.front partdisks.inst unsquash.inst language.inst timezone.inst userhost.inst network.inst debian.inst semplice.inst bricks.inst mirrorselect.inst clean.inst bootloader.inst fstab.inst end.front
modules = uefidetect.inst welcome.front language.front update.front timezone.front userhost.front partdisks.front bootloader.front bricks.front mirrorselect.front summary.front partdisks.inst unsquash.inst language.inst timezone.inst userhost.inst network.inst debian.inst semplice.inst supportrepo.inst bricks.inst mirrorselect.inst clean.inst bootloader.inst fstab.inst end.front
special = partdisks.inst unsquash.inst

[module:language]
Expand Down Expand Up @@ -31,3 +31,6 @@ sets = debian semplice changes
[module:bootloader]
bootloader = grub

[module:supportrepo]
path = file:///lib/live/mount/medium/support
binarydir = ./
4 changes: 4 additions & 0 deletions config/semplice-nolive
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ image = /linstaller/source/live/filesystem.squashfs
[module:debian]
# This only works if using the mount_nolive.sh script
remove = /linstaller/source/live/filesystem.packages-remove

[module:supportrepo]
# This only works if using the mount_nolive.sh script
path = file:///linstaller/source/support
70 changes: 70 additions & 0 deletions linstaller/core/apt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
# linstaller core apt library - (C) 2013 Eugenio "g7" Paolantonio and the Semplice Team.
# All rights reserved. Work released under the GNU GPL license, version 3 or later.
#
# This is a module of linstaller, should not be executed as a standalone application.

import linstaller.core.main as m

import apt
import os

RepositoryType = m.enum("Trivial", "Automatic")

class Cache(apt.cache.Cache):

""" This class is intended to manage packages and repositories in target,
outside the chroot. """

def __init__(self, rootdir="/linstaller/target", memonly=True, sourceslist="/tmp/linstaller_sourceslist.list"):

# Just one catch: we need to specify rootdir as libraries cannot
# access the main_settings dictionary.
# The calling module should set rootdir to self.main_settings["target"].

apt.cache.Cache.__init__(self, progress=None, rootdir=rootdir, memonly=memonly)

self.sourceslist = sourceslist

def add_repository(self, mode, path, binarydir="./", distro=None, sections=None, withsrc=False):
""" Adds the repository to self.sourceslist.
path is the URI of the repository.
mode is the relevant repository type (see RepositoryType enum)
If mode is RepositoryType.TRIVIAL, binarydir is the only addition parameter (defaults to ./)
If mode is RepositoryType.AUTOMATIC, the additional - and required - parameters are distro and
sections (tuple), while withsrc is the only additional parameter. If True, it will set deb-src
repositories too. """

if os.path.exists(self.sourceslist):
openmode = "a"
else:
openmode = "w"

if mode == RepositoryType.TRIVIAL:
with open(self.sourceslist, openmode) as f:
f.write("deb %(path)s %(binarydir)s\n") % {"path":path, "binarydir":binarydir}
elif mode == RepositoryType.AUTOMATIC:
if None in (distro, sections):
raise TypeError("add_repository() in RepositoryType.AUTOMATIC mode needs distro and sections defined")

with open(self.sourceslist, openmode) as f:
f.write("deb %(path)s %(distro)s %(sections)s\n") % {"path":path, "distro":distro, "sections":" ".join(sections)}
if withsrc:
f.write("deb-src %(path)s %(distro)s %(sections)s\n") % {"path":path, "distro":distro, "sections":" ".join(sections)}

def update(self, fetch_progress=None, pulse_interval=0, raise_on_error=True):
""" Run the equivalent of apt-get update.
See apt.cache.update() for a detailed explanation.
This method will call update() with the sources_list overrided by self.sourceslist. """

apt.cache.update(self,
fetch_progress=fetch_progress,
pulse_interval=pulse_interval,
raise_on_error=raise_on_error,
sources_list=self.sources_list
)
7 changes: 7 additions & 0 deletions linstaller/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,10 @@ def handle_exception(function):
print("".join(traceback.format_exception(excp[0],excp[1],excp[2])))
verbose("".join(traceback.format_exception(excp[0],excp[1],excp[2])))
sys.exit(1)

def enum(*sequential, **named):

# Thanks to http://stackoverflow.com/a/1695250

enums = dict(zip(sequential, range(len(sequential))), **named)
return type('Enum', (), enums)
21 changes: 21 additions & 0 deletions linstaller/modules/bootloader/inst/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@
import sys, fileinput

class Install(module.Install):
def grub_pkgs_install(self):
""" Selects and install the bootloader from the supportrepo. """

if not self.moduleclass.cache:
# Older Semplice release, no repo, returning nicely
return

if "uefidetect.inst" in self.moduleclass.modules_settings and self.moduleclass.modules_settings["uefidetect.inst"]["uefi"] == True:
# UEFI
self.moduleclass.cache["grub-efi"].mark_install()
else:
# Normal BIOS or unable to detect
self.moduleclass.cache["grub-pc"].mark_install()

# COMMIT!
self.moduleclass.cache.commit()

def grub_install(self):
""" Installs grub. """

Expand Down Expand Up @@ -64,7 +81,11 @@ class Module(module.Module):
def start(self):
""" Start module """

if "supportrepo.inst" in self.modules_settings:
self.cache = self.modules_settings["supportrepo.inst"]["cache"]

self.install = Install(self)
self._pkgs_install = {"grub":self.install.grub_pkgs_install}
self._install = {"grub":self.install.grub_install}
self._update = {"grub":self.install.grub_update}

Expand Down
14 changes: 9 additions & 5 deletions linstaller/modules/bootloader/inst/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ def start(self):
verbose("Installing %s bootloader..." % bootloader)

# Get a progressbar
progress = self.progressbar(_("Installing bootloader:"), 2)
progress = self.progressbar(_("Installing bootloader:"), 3)

# Start progressbar
progress.start()

try:
# PASS 1: INSTALL
self.moduleclass._install[bootloader]()
# PASS 1: INSTALLING THE PACKAGES
self.moduleclass._pkgs_install[bootloader]()
progress.update(1)

# PASS 2: UPDATE
self.moduleclass._update[bootloader]()
# PASS 2: INSTALL
self.moduleclass._install[bootloader]()
progress.update(2)

# PASS 3: UPDATE
self.moduleclass._update[bootloader]()
progress.update(3)
finally:
# Exit
self.moduleclass.install.close()
Expand Down
15 changes: 10 additions & 5 deletions linstaller/modules/bootloader/inst/glade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ def progress(self):
m.verbose("Installing %s bootloader..." % bootloader)

try:
# PASS 1: INSTALL
# PASS 1: INSTALLING THE PACKAGES
self.parent.progress_set_text(_("Installing bootloader packages..."))
self.parent.moduleclass._pkgs_install[bootloader]()
self.parent.progress_set_percentage(1)

# PASS 2: INSTALL
self.parent.progress_set_text(_("Installing bootloader..."))
self.parent.moduleclass._install[bootloader]()
self.parent.progress_set_percentage(1)
self.parent.progress_set_percentage(2)

# PASS 2: UPDATE
# PASS 3: UPDATE
self.parent.progress_set_text(_("Generating bootloader configuration..."))
self.parent.moduleclass._update[bootloader]()
self.parent.progress_set_percentage(2)
self.parent.progress_set_percentage(3)
finally:
# Exit
self.parent.moduleclass.install.close()
Expand All @@ -42,7 +47,7 @@ def ready(self):

self.set_header("hold", _("Installing bootloader..."), _("Please wait during the installer is installing the bootloader..."))

self.progress_set_quota(2)
self.progress_set_quota(3)

def process(self):
""" Process install """
Expand Down
Empty file.
49 changes: 49 additions & 0 deletions linstaller/modules/supportrepo/inst/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
# linstaller supportrepo module install - (C) 2013 Eugenio "g7" Paolantonio and the Semplice Team.
# All rights reserved. Work released under the GNU GPL license, version 3 or later.
#
# This is a module of linstaller, should not be executed as a standalone application.

import linstaller.core.module as module
import linstaller.core.apt as aptl

import os

class Module(module.Module):
def _associate_(self):
""" Shut up associate as we do not have any frontend. """

pass

def start(self):
""" Start module. """

# We need to support older semplice-current releases (Semplice 4)
# which may get this linstaller by auto-update and will not be
# able to install the bootloader because it will try to install
# the packages from the CD (repositories have been added starting
# from Semplice 5)

if os.path.exists(self.settings["path"])
self.cache = aptl.Cache(rootdir=self.main_settings["target"])
self.cache.add_repository(aptl.RepositoryType.TRIVIAL, self.settings["path"], binarydir=self.settings["binarydir"])

# Update
self.cache.update()

# Cache the cache object. This will be used by whoever wants to use the supportrepo.
self.settings["cache"] = self.cache
else:
self.settings["cache"] = None

def revert(self):
""" Revert changes. """

# Is this really needed? (cache created with memonly and sources file in /tmp)
pass

def seedpre(self):
""" Cache settings """

self.cache("path")
self.cache("binarydir", "./")
3 changes: 3 additions & 0 deletions lvm_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import linstaller.core.libmodules.partdisks.lvm as lvm

print lvm.return_pv()

0 comments on commit e7362ef

Please sign in to comment.