Completed
Pull Request — master (#2542)
by Zatreanu
01:52 queued 10s
created

DistributionRequirement.__init__()   A

Complexity

Conditions 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
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
Bug introduced by
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[
43
                platform.linux_distribution()[0]] in self.package.keys()):
44
45
            manager = manager_dict[platform.linux_distribution()[0]]
46
            result = "{} install {}".format(manager.replace("_", "-"),
47
                                            self.package[manager])
48
            return result
49
        else:
50
            package_possibilites = (
51
                {package for package in self.package.values()})
52
            print('The package could not be automatically installed on your '
53
                  'operating system. Please try installing it manually. It'
54
                  ' should look like this: ' + repr(package_possibilites))
55
            return ""
56