Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12944397
python.py
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
python.py
View Options
# -------------------------------------------------------------
# Salt — Python execution module
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: As grains can now describe the Python interpreter
# installed by SaltStack, this module allows querying
# information about the global Python.
# License: BSD-2-Clause
# -------------------------------------------------------------
import
os
import
subprocess
def
get_interpreter
()
->
str
:
if
__grains__
[
"os"
]
==
"FreeBSD"
:
return
"/usr/local/bin/python3"
else
:
return
"/usr/bin/python3"
def
get_version
()
->
str
:
result
=
subprocess
.
run
([
get_interpreter
(),
"--version"
],
capture_output
=
True
)
full_version
=
result
.
stdout
.
decode
()
.
strip
()
# "Python 3.13.7" -> "3.13"
return
"."
.
join
(
full_version
.
split
()[
1
]
.
split
(
"."
)[
0
:
2
])
def
get_site_packages_directory
()
->
str
:
python_version
=
get_version
()
if
__grains__
[
"os"
]
==
"FreeBSD"
:
return
f
"/usr/local/lib/python{python_version}/site-packages"
else
:
return
f
"/usr/lib/python{python_version}/site-packages"
def
is_package_installed
(
package_name
:
str
)
->
bool
:
package_directory
=
os
.
path
.
join
(
get_site_packages_directory
(),
package_name
)
return
os
.
path
.
exists
(
package_directory
)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 18, 17:17 (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3156446
Default Alt Text
python.py (1 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment