"Fossies" - the Fresh Open Source Software Archive 
Member "salt-3002.2/salt/utils/idem.py" (18 Nov 2020, 1250 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 "idem.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 Idem Support
3 ============
4
5 This util provides access to an idem-ready hub
6
7 .. versionadded:: 3002
8 """
9 import logging
10 import sys
11
12 try:
13 import pop.hub
14
15 HAS_POP = True, None
16 except ImportError as e:
17 HAS_POP = False, str(e)
18
19 log = logging.getLogger(__name__)
20
21 __virtualname__ = "idem"
22
23
24 def __virtual__():
25 if sys.version_info < (3, 6):
26 return False, "idem only works on python3.6 and later"
27 if not HAS_POP[0]:
28 return HAS_POP
29 return __virtualname__
30
31
32 def hub():
33 """
34 Create a hub with idem ready to go and completely loaded
35 """
36 if "idem.hub" not in __context__:
37 log.debug("Creating the POP hub")
38 hub = pop.hub.Hub()
39
40 log.debug("Initializing the loop")
41 hub.pop.loop.create()
42
43 log.debug("Loading subs onto hub")
44 hub.pop.sub.add(dyne_name="config")
45 # We aren't collecting grains at all but some exec modules depend on the sub being on the hub
46 hub.pop.sub.add(dyne_name="grains")
47 hub.pop.sub.add(dyne_name="idem")
48
49 log.debug("Reading idem config options")
50 hub.config.integrate.load(["acct", "idem"], "idem", parse_cli=False, logs=False)
51
52 __context__["idem.hub"] = hub
53
54 return __context__["idem.hub"]