From 567fd590ab40b7036b8813504e27285a7405bfda Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 7 May 2016 17:07:18 +0530 Subject: [PATCH] setup: Run first time setup with apt Due to problems with running PackageKit inside foriegn binary Qemu, this is a fallback solution to use apt-get directly instead. --- plinth/package.py | 23 +++++++++++++++++++++++ plinth/setup.py | 9 +++++++++ 2 files changed, 32 insertions(+) diff --git a/plinth/package.py b/plinth/package.py index 8a46401ca..c4fad50e8 100644 --- a/plinth/package.py +++ b/plinth/package.py @@ -21,6 +21,7 @@ Framework for installing and updating distribution packages from django.utils.translation import ugettext as _ import logging +import subprocess from plinth.utils import import_from_gi glib = import_from_gi('GLib', '2.0') @@ -166,3 +167,25 @@ class Transaction(object): else: logger.info('Unhandle packagekit progress callback - %s, %s', progress, progress_type) + + +class AptTransaction(object): + """Install a package using Apt.""" + def __init__(self, package_names): + """Initialize transaction object.""" + self.package_names = package_names + + def install(self): + """Run a PackageKit transaction to install given packages. + + Plinth needs to be running as root when calling this. + Currently, this is meant to be only during first time setup + when --setup is argument is passed. + """ + try: + subprocess.run(['apt-get', 'update']) + subprocess.run(['apt-get', '-y', 'install'] + self.package_names, + check=True) + except subprocess.CalledProcessError as exception: + logger.exception('Error installing package: %s', exception) + raise diff --git a/plinth/setup.py b/plinth/setup.py index c8fd747d2..d283272d5 100644 --- a/plinth/setup.py +++ b/plinth/setup.py @@ -27,6 +27,8 @@ import plinth logger = logging.getLogger(__name__) +running_initial_setup = False + class Helper(object): """Helper routines for modules to show progress.""" @@ -91,6 +93,11 @@ class Helper(object): """Install a set of packages marking progress.""" logger.info('Running install for module - %s, packages - %s', self.module_name, package_names) + if running_initial_setup: + transaction = package.AptTransaction(package_names) + transaction.install() + return + transaction = package.Transaction(package_names) self.current_operation = { 'step': 'install', @@ -153,6 +160,8 @@ def init(module_name, module): def setup_all_modules(essential=False): """Run setup on all essential modules and exit.""" logger.info('Running setup for all modules, essential - %s', essential) + global running_initial_setup + running_initial_setup = True for module_name, module in plinth.module_loader.loaded_modules.items(): if essential and not getattr(module, 'is_essential', False): continue