Completed
Pull Request — master (#2542)
by Zatreanu
01:53
created

DistributionRequirement   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 15 1
B install_command() 0 27 3
1
from coalib.bears.requirements.PackageRequirement import PackageRequirement
2
import platform
3
4
5
class DistributionRequirement(PackageRequirement):
6
    """
7
    This class is a subclass of ``PackageRequirement``, and helps specifying
8
    distribution specific requirements, without using the manager name.
9
    """
10
11
    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...
12
        """
13
        Constructs a new ``DistributionRequirement``, using the
14
        ``PackageRequirement`` constructor.
15
16
        >>> dr =  DistributionRequirement(aptget='libclang', dnf='libclangg')
17
        >>> dr.package['aptget']
18
        'libclang'
19
        >>> dr.package['dnf']
20
        'libclangg'
21
22
        :param package: A string with the name of the package to be installed.
23
        :param version: A version string. Leave empty to specify latest version.
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.
32
        """
33
        manager_dict = {'Fedora': 'dnf',
34
                        'Ubuntu': 'aptget',
35
                        'Debian': 'aptget',
36
                        'SuSE': 'zypper',
37
                        'redhat': 'yum',
38
                        'arch': 'pacman'}
39
40
        manager = manager_dict[platform.linux_distribution()[0]]
41
        if manager in self.package.keys():  # pragma: no cover
42
            if manager == 'aptget':  # can't give hyphen as parameter to class
43
                package = self.package[manager]
44
                manager = 'apt-get'
45
                result = "{} install {}".format(manager, package)
46
                return result  # pragma: no cover
47
            result = "{} install {}".format(manager, self.package[manager])
48
            return result  # pragma: no cover
49
        else:  # pragma: no cover
50
            print('The package could not be automatically installed on your'
51
                  'operating system. Please try installing '
52
                  + self.package + 'manually.')
53
            return ""
54