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