コード例 #1
0
    def __init__(self, **kwargs):
        # Fetches passed arguments.
        self._format_to_json = kwargs.get('format_to_json')

        try:
            # If set, force the distribution to `preferred_distribution` argument.
            self._distribution = Distributions(
                kwargs.get('preferred_distribution'))
        except ValueError:
            # If not (or unknown), run distribution detection.
            self._distribution = Distributions.run_detection()

        # Fetch the colors palette related to this distribution.
        self._colors_palette = COLORS_DICT[self._distribution]

        # If `os-release`'s `ANSI_COLOR` option is set, honor it.
        ansi_color = Distributions.get_ansi_color()
        if ansi_color and Configuration().get(
                'colors_palette')['honor_ansi_color']:
            # Replace each Archey integrated colors by `ANSI_COLOR`.
            self._colors_palette = len(self._colors_palette) * \
                [Colors.escape_code_from_attrs(ansi_color)]

        # Each entry will be added to this list
        self._entries = []
        # Each class output will be added in the list below afterwards
        self._results = []
コード例 #2
0
ファイル: output.py プロジェクト: pombredanne/archey4
    def __init__(self, **kwargs):
        # Fetches passed arguments.
        self._format_to_json = kwargs.get('format_to_json')  # type: int

        try:
            # If set, force the distribution to `preferred_distribution` argument.
            self._distribution = Distributions(kwargs.get('preferred_distribution'))
        except ValueError:
            # If not (or unknown), run distribution detection.
            self._distribution = Distributions.run_detection()

        # Retrieve distribution's logo module before copying and DRY-ing its attributes.
        logo_module = lazy_load_logo_module(self._distribution.value)
        self._logo, self._colors = logo_module.LOGO.copy(), logo_module.COLORS.copy()

        # If `os-release`'s `ANSI_COLOR` option is set, honor it.
        ansi_color = Distributions.get_ansi_color()
        if ansi_color and Configuration().get('honor_ansi_color'):
            # Replace each Archey integrated colors by `ANSI_COLOR`.
            self._colors = len(self._colors) * [Colors.escape_code_from_attrs(ansi_color)]

        # Each entry will be added to this list
        self._entries = []
        # Each class output will be added in the list below afterwards
        self._results = []
コード例 #3
0
 def test_run_detection_distro_like_second(self, _, __, ___):
     """Test distribution matching from the `os-release`'s `ID_LIKE` option (second candidate)"""
     self.assertEqual(Distributions.run_detection(), Distributions.ARCH)
コード例 #4
0
 def test_run_detection_known_distro_like(self, _, __, ___):
     """Test distribution matching from the `os-release`'s `ID_LIKE` option"""
     self.assertEqual(Distributions.run_detection(), Distributions.UBUNTU)
コード例 #5
0
 def test_run_detection_unknown_distro_id(self, _, __, ___, ____):
     """Test unknown distribution output"""
     self.assertEqual(Distributions.run_detection(), Distributions.LINUX)
コード例 #6
0
 def test_run_detection_windows_subsystem(self, _):
     """Test output for Windows Subsystem Linux"""
     self.assertEqual(Distributions.run_detection(), Distributions.WINDOWS)
コード例 #7
0
 def test_run_detection_windows(self):
     """Test output for Windows"""
     self.assertEqual(Distributions.run_detection(), Distributions.WINDOWS)
コード例 #8
0
 def test_run_detection_specific_android(self, _, __):
     """Test Android specific detection"""
     self.assertEqual(Distributions.run_detection(), Distributions.ANDROID)
コード例 #9
0
 def test_run_detection_specific_crunchbang(self, _, __, ___):
     """Test CrunchBang specific detection"""
     self.assertEqual(Distributions.run_detection(),
                      Distributions.CRUNCHBANG)
コード例 #10
0
 def test_run_detection_both_distro_calls_fail(self, _, __, ___, ____):
     """Test distribution fall-back when `distro` soft-fail two times"""
     self.assertEqual(Distributions.run_detection(), Distributions.LINUX)