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, package, version=""): |
12
|
|
|
""" |
13
|
|
|
Constructs a new ``DistributionRequirement``, using the |
14
|
|
|
``PackageRequirement`` constructor. |
15
|
|
|
|
16
|
|
|
>>> dr = DistributionRequirement('apt', 'libclang') |
17
|
|
|
>>> dr.manager |
18
|
|
|
'apt' |
19
|
|
|
>>> dr.package |
20
|
|
|
'libclang' |
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
|
|
|
PackageRequirement.__init__(self, manager, package, version) |
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': '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: # pragma: no cover |
41
|
|
|
self.manager = manager_dict[platform.linux_distribution()] |
42
|
|
|
else: # pragma: no cover |
43
|
|
|
print('The package could not be automatically installed on your' |
44
|
|
|
'operating system. Please try installing ' |
45
|
|
|
+ self.package + 'manually.') |
46
|
|
|
|
47
|
|
|
result = "{} install {}".format(self.manager, self.package) |
48
|
|
|
return result # pragma: no cover |
49
|
|
|
|