Issues (70)

bears/requirements/DistributionRequirement.py (1 issue)

Labels
Severity
1
import platform
2
3
from coalib.bears.requirements.PackageRequirement import PackageRequirement
4
5
6
class DistributionRequirement(PackageRequirement):
7
    """
8
    This class is a subclass of ``PackageRequirement``, and helps specifying
9
    distribution specific requirements, without using the manager name.
10
    """
11
12
    def __init__(self, **manager_commands):
0 ignored issues
show
The __init__ method of the super-class PackageRequirement is not called.

It is generally advisable to initialize the super-class by calling its __init__ method:

class SomeParent:
    def __init__(self):
        self.x = 1

class SomeChild(SomeParent):
    def __init__(self):
        # Initialize the super class
        SomeParent.__init__(self)
Loading history...
13
        """
14
        Constructs a new ``DistributionRequirement``, using the
15
        ``PackageRequirement`` constructor.
16
17
        >>> dr = DistributionRequirement(apt_get='libclang', dnf='libclangg')
18
        >>> dr.package['apt_get']
19
        'libclang'
20
        >>> dr.package['dnf']
21
        'libclangg'
22
23
        :param manager_commands: comma separated (manager='package') pairs.
24
        """
25
        self.package = manager_commands
26
27
    def install_command(self):
28
        """
29
        Creates the installation command for the instance of the class.
30
31
        :param return: A string with the installation command. An empty string
32
                       if the command could not be supplied.
33
        """
34
        manager_dict = {'Fedora': 'dnf',
35
                        'Ubuntu': 'apt_get',
36
                        'Debian': 'apt_get',
37
                        'SuSE': 'zypper',
38
                        'redhat': 'yum',
39
                        'arch': 'pacman'}
40
41
        if (platform.linux_distribution()[0] in manager_dict.keys() and
42
                manager_dict[platform.linux_distribution()[0]]
43
                in self.package.keys()):
44
            manager = manager_dict[platform.linux_distribution()[0]]
45
            return [manager.replace("_", "-"),
46
                    'install', self.package[manager]]
47
        else:
48
            package_possibilites = (
49
                {package for package in self.package.values()})
50
            print('The package could not be automatically installed on your '
51
                  'operating system. Please try installing it manually. It'
52
                  ' should look like this: ' + repr(package_possibilites))
53
            raise OSError
54