Total Complexity | 3 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | from coalib.bears.requirements.PackageRequirement import PackageRequirement |
||
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) |
||
|
|||
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 |