~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to checkbox-ng/checkbox_ng/tools.py

  • Committer: Zygmunt Krynicki
  • Date: 2013-05-29 07:50:30 UTC
  • mto: This revision was merged to the branch mainline in revision 2153.
  • Revision ID: zygmunt.krynicki@canonical.com-20130529075030-ngwz245hs2u3y6us
checkbox: move current checkbox code into checkbox-old

This patch cleans up the top-level directory of the project into dedicated
sub-project directories. One for checkbox-old (the current checkbox and all the
associated stuff), one for plainbox and another for checkbox-ng.

There are some associated changes, such as updating the 'source' mode of
checkbox provider in plainbox, and fixing paths in various test scripts that we
have.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# This file is part of Checkbox.
2
 
#
3
 
# Copyright 2012-2015 Canonical Ltd.
4
 
# Written by:
5
 
#   Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
6
 
#
7
 
# Checkbox is free software: you can redistribute it and/or modify
8
 
# it under the terms of the GNU General Public License version 3,
9
 
# as published by the Free Software Foundation.
10
 
#
11
 
# Checkbox is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
18
 
 
19
 
"""
20
 
:mod:`checkbox_ng.tools` -- top-level command line tools
21
 
========================================================
22
 
"""
23
 
 
24
 
import logging
25
 
import os
26
 
 
27
 
from plainbox.impl.clitools import SingleCommandToolMixIn
28
 
from plainbox.impl.clitools import ToolBase
29
 
from plainbox.impl.commands.cmd_selftest import SelfTestCommand
30
 
from plainbox.public import get_providers
31
 
 
32
 
from checkbox_ng import __version__ as version
33
 
from checkbox_ng.config import CheckBoxConfig
34
 
from checkbox_ng.tests import load_unit_tests
35
 
 
36
 
 
37
 
logger = logging.getLogger("checkbox.ng.tools")
38
 
 
39
 
 
40
 
class CheckboxToolBase(ToolBase):
41
 
    """
42
 
    Base class for all checkbox-ng tools.
43
 
 
44
 
    This class contains some shared code like configuration, providers, i18n
45
 
    and version handling.
46
 
    """
47
 
 
48
 
    def _load_config(self):
49
 
        return self.get_config_cls().get()
50
 
 
51
 
    def _load_providers(self):
52
 
        return get_providers()
53
 
 
54
 
    @classmethod
55
 
    def get_exec_version(cls):
56
 
        """
57
 
        Get the version of the checkbox-ng package
58
 
        """
59
 
        return cls.format_version_tuple(version)
60
 
 
61
 
    @classmethod
62
 
    def get_config_cls(cls):
63
 
        """
64
 
        Get particular sub-class of the Config class to use
65
 
        """
66
 
        return CheckBoxConfig
67
 
 
68
 
    def get_gettext_domain(self):
69
 
        """
70
 
        Get the 'checkbox-ng' gettext domain
71
 
        """
72
 
        return "checkbox-ng"
73
 
 
74
 
    def get_locale_dir(self):
75
 
        """
76
 
        Get an optional development locale directory specific to checkbox-ng
77
 
        """
78
 
        return os.getenv("CHECKBOX_NG_LOCALE_DIR", None)
79
 
 
80
 
 
81
 
class CheckboxTool(CheckboxToolBase):
82
 
    """
83
 
    Tool that implements the new checkbox command.
84
 
 
85
 
    This tool has two sub-commands:
86
 
 
87
 
        checkbox sru - to run stable release update testing
88
 
        checkbox check-config - to validate and display system configuration
89
 
    """
90
 
 
91
 
    @classmethod
92
 
    def get_exec_name(cls):
93
 
        return "checkbox"
94
 
 
95
 
    def add_subcommands(self, subparsers, early_ns=None):
96
 
        from checkbox_ng.commands.launcher import LauncherCommand
97
 
        from checkbox_ng.commands.sru import SRUCommand
98
 
        from checkbox_ng.commands.submit import SubmitCommand
99
 
        from plainbox.impl.commands.cmd_check_config import CheckConfigCommand
100
 
        SRUCommand(
101
 
            self._load_providers, self._load_config
102
 
        ).register_parser(subparsers)
103
 
        CheckConfigCommand(
104
 
            self._load_config
105
 
        ).register_parser(subparsers)
106
 
        SubmitCommand(
107
 
            self._load_config
108
 
        ).register_parser(subparsers)
109
 
        LauncherCommand(
110
 
            self._load_providers, self._load_config
111
 
        ).register_parser(subparsers)
112
 
        SelfTestCommand(load_unit_tests).register_parser(subparsers)
113
 
 
114
 
 
115
 
class CheckboxSubmitTool(SingleCommandToolMixIn, CheckboxToolBase):
116
 
    """
117
 
    A tool class that implements checkbox-submit.
118
 
 
119
 
    This tool implements the submit feature to send test results to the
120
 
    Canonical certification website
121
 
    """
122
 
 
123
 
    @classmethod
124
 
    def get_exec_name(cls):
125
 
        return "checkbox-submit"
126
 
 
127
 
    def get_command(self):
128
 
        from checkbox_ng.commands.submit import SubmitCommand
129
 
        return SubmitCommand(self._load_config)
130
 
 
131
 
 
132
 
class CheckboxLauncherTool(SingleCommandToolMixIn, CheckboxToolBase):
133
 
    """
134
 
    A tool class that implements checkbox-launcher.
135
 
 
136
 
    This tool implements configurable text-mode-graphics launchers that perform
137
 
    a pre-defined testing session based on the launcher profile.
138
 
    """
139
 
 
140
 
    @classmethod
141
 
    def get_exec_name(cls):
142
 
        return "checkbox-launcher"
143
 
 
144
 
    def get_command(self):
145
 
        from checkbox_ng.commands.launcher import LauncherCommand
146
 
        return LauncherCommand(self._load_providers, self._load_config)