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

DistributionRequirement   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A install_command() 0 22 2
A __init__() 0 10 1
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, package, version=""):
12
        """
13
        Constructs a new ``DistributionRequirement``, using the
14
        ``PackageRequirement`` constructor.
15
16
        :param package: A string with the name of the package to be installed.
17
        :param version: A version string. Leave empty to specify latest version.
18
        """
19
        PackageRequirement.__init__(self, manager, package, version)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'manager'
Loading history...
20
        self.manager = ""
21
22
    def install_command(self):
23
        """
24
        Creates the installation command for the instance of the class.
25
26
        :param return: A string with the installation command.
27
        """
28
        manager_dict = {'Fedora': 'dnf',
29
                        'Ubuntu': 'apt-get',
30
                        'Debian': 'apt-get',
31
                        'SuSE': 'zypper',
32
                        'redhat': 'yum',
33
                        'arch': 'pacman'}
34
35
        if platform.linux_distribution()[0] in manager_dict:
36
            self.manager = manager_dict[platform.linux_distribution()]
37
        else:
38
            print('The package could not be automatically installed on your'
39
                  'operating system. Please try installing '
40
                  + self.package + 'manually.')
41
42
        result = "{} install {}".format(self.manager, self.package)
43
        return result
44