"Fossies" - the Fresh Open Source Software Archive 
Member "salt-3002.2/salt/states/aptpkg.py" (18 Nov 2020, 1438 Bytes) of package /linux/misc/salt-3002.2.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "aptpkg.py" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
3002.1_vs_3002.2.
1 """
2 Package management operations specific to APT- and DEB-based systems
3 ====================================================================
4 """
5
6
7 import logging
8
9 import salt.utils.data
10
11 log = logging.getLogger(__name__)
12
13
14 # Define the module's virtual name
15 __virtualname__ = "apt"
16
17
18 def __virtual__():
19 """
20 Only work on apt-based platforms with pkg.get_selections
21 """
22 if "pkg.get_selections" in __salt__:
23 return True
24 return (False, "apt module could not be loaded")
25
26
27 def held(name):
28 """
29 Set package in 'hold' state, meaning it will not be upgraded.
30
31 name
32 The name of the package, e.g., 'tmux'
33 """
34 ret = {"name": name, "changes": {}, "result": False, "comment": ""}
35 state = __salt__["pkg.get_selections"](pattern=name,)
36 if not state:
37 ret.update(comment="Package {} does not have a state".format(name))
38 elif not salt.utils.data.is_true(state.get("hold", False)):
39 if not __opts__["test"]:
40 result = __salt__["pkg.set_selections"](selection={"hold": [name]})
41 ret.update(
42 changes=result[name],
43 result=True,
44 comment="Package {} is now being held".format(name),
45 )
46 else:
47 ret.update(result=None, comment="Package {} is set to be held".format(name))
48 else:
49 ret.update(result=True, comment="Package {} is already held".format(name))
50
51 return ret