forked from saltstack/salt
/
pip.py
140 lines (124 loc) · 4.39 KB
/
pip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'''
Management of python packages
=============================
A state module to manage system installed python packages
.. code-block:: yaml
virtualenvwrapper:
pip:
- installed
- version: 3.0.1
'''
def installed(name,
pip_bin=None,
requirements=None,
env=None,
bin_env=None,
log=None,
proxy=None,
timeout=None,
editable=None,
find_links=None,
index_url=None,
extra_index_url=None,
no_index=False,
mirrors=None,
build=None,
target=None,
download=None,
download_cache=None,
source=None,
upgrade=False,
force_reinstall=False,
ignore_installed=False,
no_deps=False,
no_install=False,
no_download=False,
install_options=None,
user=None):
'''
Make sure the package is installed
name
The name of the python package to install
pip_bin : None
Deprecated, use bin_env
env : None
Deprecated, use bin_env
bin_env : None
the pip executable or virtualenv to use
'''
if pip_bin and not bin_env:
bin_env = pip_bin
elif env and not bin_env:
bin_env = env
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
if name in __salt__['pip.list'](name, bin_env):
ret['result'] = True
ret['comment'] = 'Package already installed'
return ret
if __salt__['pip.install'](pkgs=name,
requirements=requirements,
bin_env=bin_env,
log=log,
proxy=proxy,
timeout=timeout,
editable=editable,
find_links=find_links,
index_url=index_url,
extra_index_url=extra_index_url,
no_index=no_index,
mirrors=mirrors,
build=build,
target=target,
download=download,
download_cache=download_cache,
source=source,
upgrade=upgrade,
force_reinstall=force_reinstall,
ignore_installed=ignore_installed,
no_deps=no_deps,
no_install=no_install,
no_download=no_download,
install_options=install_options,
runas=user):
pkg_list = __salt__['pip.list'](name, bin_env)
version = pkg_list.values()[0]
pkg_name = pkg_list.keys()[0]
ret['result'] = True
ret['changes']["{0}=={1}".format(pkg_name, version)] = 'Installed'
ret['comment'] = 'Package was successfully installed'
else:
ret['result'] = False
ret['comment'] = 'Could not install package'
return ret
def removed(name,
packages=None,
requirements=None,
bin_env=None,
log=None,
proxy=None,
timeout=None):
"""
Make sure that a package is not installed.
name
The name of the package to uninstall
bin_env : None
the pip executable or virtualenenv to use
"""
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
if name not in __salt__["pip.list"](packages=name, bin_env=bin_env):
ret["result"] = True
ret["comment"] = "Pacakge is not installed."
return ret
if __salt__["pip.uninstall"](packages=name,
requirements=requirements,
bin_env=bin_env,
log=log,
proxy=proxy,
timeout=timeout):
ret["result"] = True
ret["changes"][name] = "Removed"
ret["comment"] = "Package was successfully removed."
else:
ret["result"] = False
ret["comment"] = "Could not remove package."
return ret