Module: Fontist::Utils::System
- Defined in:
- lib/fontist/utils/system.rb
Defined Under Namespace
Classes: PowerShellResult
Class Method Summary
collapse
Class Method Details
.case_sensitive_filesystem? ⇒ Boolean
88
89
90
|
# File 'lib/fontist/utils/system.rb', line 88
def self.case_sensitive_filesystem?
!%i[windows macos].include?(user_os)
end
|
.catalog_version_for_macos ⇒ Object
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/fontist/utils/system.rb', line 199
def self.catalog_version_for_macos
if platform_override?
parsed = parse_platform_override
return parsed[:framework] if parsed && parsed[:framework]
end
version = macos_version
return nil unless version
require_relative "../macos_framework_metadata"
MacosFrameworkMetadata.framework_for_macos(version)
end
|
.fontconfig_installed? ⇒ Boolean
117
118
119
120
121
122
123
|
# File 'lib/fontist/utils/system.rb', line 117
def self.fontconfig_installed?
Helpers.silence_stream($stderr) do
!!Helpers.run("fc-cache -V")
end
rescue Errno::ENOENT
false
end
|
.linux? ⇒ Boolean
76
77
78
|
# File 'lib/fontist/utils/system.rb', line 76
def self.linux?
user_os == :linux
end
|
.macos? ⇒ Boolean
72
73
74
|
# File 'lib/fontist/utils/system.rb', line 72
def self.macos?
user_os == :macos
end
|
.macos_version ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/fontist/utils/system.rb', line 125
def self.macos_version
if platform_override?
parsed = parse_platform_override
if parsed && parsed[:framework]
require_relative "../macos_framework_metadata"
return MacosFrameworkMetadata.min_macos_version(parsed[:framework])
end
end
return nil unless user_os == :macos
@macos_version ||= begin
output = Helpers.run("sw_vers -productVersion")
output&.strip
rescue Errno::ENOENT
nil
end
end
|
.match?(platform) ⇒ Boolean
113
114
115
|
# File 'lib/fontist/utils/system.rb', line 113
def self.match?(platform)
user_os_with_version.start_with?(platform)
end
|
.parse_macos_version(version_string) ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/fontist/utils/system.rb', line 145
def self.parse_macos_version(version_string)
return nil unless version_string
return nil if version_string.strip.empty?
parts = version_string.split(".").map(&:to_i)
major = parts[0] || 0
minor = parts[1] || 0
patch = parts[2] || 0
(major * 10000) + (minor * 100) + patch
end
|
Parse platform override (ONLY platform tag format) Returns: { os: Symbol, framework: Integer } or { os: Symbol } or nil
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/fontist/utils/system.rb', line 15
def self.parse_platform_override
override = platform_override
return nil unless override
if match = override.match(/^(macos|linux|windows)-font(\d+)$/)
return { os: match[1].to_sym, framework: match[2].to_i }
end
if override.match?(/^(macos|linux|windows)$/)
return { os: override.to_sym, framework: nil }
end
Fontist.ui.error(
"Invalid FONTIST_PLATFORM_OVERRIDE: #{override}\n" \
"Supported: 'macos-font<N>', 'linux', 'windows'",
)
nil
end
|
.path_separator ⇒ Object
84
85
86
|
# File 'lib/fontist/utils/system.rb', line 84
def self.path_separator
windows? ? "\\" : "/"
end
|
Platform override from environment (ONLY platform tags supported)
5
6
7
|
# File 'lib/fontist/utils/system.rb', line 5
def self.platform_override
ENV.fetch("FONTIST_PLATFORM_OVERRIDE", nil)
end
|
9
10
11
|
# File 'lib/fontist/utils/system.rb', line 9
def self.platform_override?
!platform_override.nil?
end
|
.reset_cache ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
Reset cached values for testing
63
64
65
66
|
# File 'lib/fontist/utils/system.rb', line 63
def self.reset_cache
@user_os = nil
@macos_version = nil
end
|
.run_powershell(command) ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/fontist/utils/system.rb', line 187
def self.run_powershell(command)
require "open3"
stdout, stderr, status = Open3.capture3(
"powershell.exe", "-NoProfile", "-NonInteractive", "-Command", command
)
PowerShellResult.new(stdout: stdout, stderr: stderr,
success: status.success?)
rescue Errno::ENOENT
PowerShellResult.new(stdout: "", stderr: "powershell.exe not found",
success: false)
end
|
.unix? ⇒ Boolean
80
81
82
|
# File 'lib/fontist/utils/system.rb', line 80
def self.unix?
user_os == :unix
end
|
.user_os ⇒ Object
rubocop:disable Metrics/MethodLength
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/fontist/utils/system.rb', line 37
def self.user_os if platform_override?
parsed = parse_platform_override
return parsed[:os] if parsed
end
@user_os ||= begin
host_os = RbConfig::CONFIG["host_os"]
case host_os
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
:windows
when /darwin|mac os/
:macos
when /linux/
:linux
when /solaris|bsd/
:unix
else
raise Fontist::Error, "unknown os: #{host_os.inspect}"
end
end
end
|
.user_os_with_version ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/fontist/utils/system.rb', line 92
def self.user_os_with_version
release = if windows?
begin
RbConfig::CONFIG["host_os"].match(/\d+/)[0]
rescue StandardError
"unknown"
end
else
begin
`uname -r`.strip
rescue Errno::ENOENT
"unknown"
end
end
"#{user_os}-#{release}"
end
|
.version_in_range?(min_version, max_version) ⇒ Boolean
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/fontist/utils/system.rb', line 160
def self.version_in_range?(min_version, max_version)
current = macos_version
return true unless current
current_parsed = parse_macos_version(current)
return true unless current_parsed
if min_version
min_parsed = parse_macos_version(min_version)
return false if min_parsed && current_parsed < min_parsed
end
if max_version
max_parsed = parse_macos_version(max_version)
return false if max_parsed && current_parsed > max_parsed
end
true
end
|
.windows? ⇒ Boolean
68
69
70
|
# File 'lib/fontist/utils/system.rb', line 68
def self.windows?
user_os == :windows
end
|