Source code for plainbox.impl.applogic

# This file is part of Checkbox.
# Copyright 2013 Canonical Ltd.
# Written by:
#   Zygmunt Krynicki <>
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.

# Checkbox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Checkbox.  If not, see <>.

:mod:`plainbox.impl.applogic` -- application logic

.. warning::


import os

from import IJobResult
from plainbox.i18n import gettext as _
from plainbox.impl.result import MemoryJobResult
from import config
from import select_jobs
from plainbox.impl.session import SessionManager
from import InhibitionCause

# Deprecated, use instead
[docs]def get_matching_job_list(job_list, qualifier): """ Get a list of jobs that are designated by the specified qualifier. This is intended to be used with :class:`CompositeQualifier` but works with any :class:`IJobQualifier` subclass. """ return select_jobs(job_list, [qualifier])
[docs]def run_job_if_possible(session, runner, config, job, update=True, ui=None): """ Coupling point for session, runner, config and job :returns: (job_state, job_result) """ job_state = session.job_state_map[] if job_state.can_start(): job_result = runner.run_job(job, job_state, config, ui) else: # Set the outcome of jobs that cannot start to # OUTCOME_NOT_SUPPORTED _except_ if any of the inhibitors point to # a job with an OUTCOME_SKIP outcome, if that is the case mirror # that outcome. This makes 'skip' stronger than 'not-supported' outcome = IJobResult.OUTCOME_NOT_SUPPORTED for inhibitor in job_state.readiness_inhibitor_list: if inhibitor.cause != InhibitionCause.FAILED_DEP: continue related_job_state = session.job_state_map[] if related_job_state.result.outcome == IJobResult.OUTCOME_SKIP: outcome = IJobResult.OUTCOME_SKIP job_result = MemoryJobResult({ 'outcome': outcome, 'comments': job_state.get_readiness_description() }) assert job_result is not None if update: session.update_job_result(job, job_result) return job_state, job_result
[docs]class PlainBoxConfig(config.Config): """ Configuration for PlainBox itself """ environment = config.Section( help_text=_("Environment variables for scripts and jobs")) class Meta: # TODO: properly depend on xdg and use real code that also handles # XDG_CONFIG_HOME. filename_list = [ '/etc/xdg/plainbox.conf', os.path.expanduser('~/.config/plainbox.conf')]
[docs]def get_all_exporter_names(): """ Get the identifiers (names) of all the supported session state exporters. :returns: A list of session exporter names (identifiers) available from all the providers. This function creates a temporary session associated with the local device and adds all of the available providers to it. Finally, it returns the list of exporter names. The session is transparently destroyed. """ with SessionManager.get_throwaway_manager() as manager: return list(manager.exporter_map.keys())
comments powered by Disqus