-
-
Notifications
You must be signed in to change notification settings - Fork 376
Expand file tree
/
Copy pathpython_version.rb
More file actions
31 lines (27 loc) · 735 Bytes
/
python_version.rb
File metadata and controls
31 lines (27 loc) · 735 Bytes
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
# Make python versions available as facts
def get_python_version(executable)
if Facter::Util::Resolution.which(executable) # rubocop:disable Style/GuardClause
results = Facter::Util::Resolution.exec("#{executable} -V 2>&1").match(%r{^.*(\d+\.\d+\.\d+\+?(?:rc\d+)?)$})
results[1] if results
end
end
Facter.add('python_version') do
setcode do
get_python_version 'python'
end
end
Facter.add('python2_version') do
setcode do
default_version = get_python_version 'python'
if default_version.nil? || !default_version.start_with?('2')
get_python_version 'python2'
else
default_version
end
end
end
Facter.add('python3_version') do
setcode do
get_python_version 'python3'
end
end