pipark 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pipark/host.rb +69 -0
- data/lib/pipark/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ef25701d6f7c1331843542c55035b9be6818e714f5a60da446d12f36b7334ff
|
4
|
+
data.tar.gz: 0fe78b693ccf16beb4009a77e93b27c0402ea6947bfef8a69920ad30ac62e524
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 398e4add97a1605f39191559ab9bdaf161dcfd9545001e539f347b641f93b88c74c50d955ce620c6bc5a502cca97fd29a1ea7191fd8b49d4204a1ea72e1d6f94
|
7
|
+
data.tar.gz: '092a6468c752956b9c929ceca6e77a1945229fae1412e5da72c81b9165059853a01ab211d74b5496141070f10db7eec7cd542f3340d29b57661d853545cafb39'
|
data/lib/pipark/host.rb
CHANGED
@@ -82,6 +82,60 @@ module Pipark
|
|
82
82
|
cache['serial-number'] ||= file_read('/proc/device-tree/serial-number').chop
|
83
83
|
end
|
84
84
|
|
85
|
+
# Returns version information for the Ruby installed on the host.
|
86
|
+
#
|
87
|
+
# Nil if no Ruby is found.
|
88
|
+
def ruby
|
89
|
+
cache['ruby'] ||=
|
90
|
+
if localhost?
|
91
|
+
RUBY_DESCRIPTION
|
92
|
+
else
|
93
|
+
(result = sh 'ruby -v').empty? ? nil : result.chomp
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Experimental: returns the status of the host's LEDs.
|
98
|
+
#
|
99
|
+
# Only supported for localhost.
|
100
|
+
def leds
|
101
|
+
dir = '/sys/class/leds'
|
102
|
+
if localhost?
|
103
|
+
Dir[dir + '/led[0-9]'].map do |f|
|
104
|
+
if f.match(dir + '/(led\d)')
|
105
|
+
[ $1, get_led_status($1).first ]
|
106
|
+
end
|
107
|
+
end.to_h
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Experimental: returns info for the installed HAT, or false if no HAT is found.
|
112
|
+
#
|
113
|
+
# Only supported for localhost.
|
114
|
+
def hat
|
115
|
+
if localhost?
|
116
|
+
dir = '/sys/firmware/devicetree/base/hat'
|
117
|
+
if File.exist? dir
|
118
|
+
%w(product vendor).map do |k|
|
119
|
+
file = "#{dir}/#{k}"
|
120
|
+
[ k, File.readable?(file) ? File.read(file).chop : nil ]
|
121
|
+
end.to_h
|
122
|
+
else
|
123
|
+
false
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Returns the host's state.
|
129
|
+
def state
|
130
|
+
result = { 'update_time' => Time.now.gmtime }
|
131
|
+
result.merge %w(
|
132
|
+
address hostname model serial_number
|
133
|
+
os_release boot_time
|
134
|
+
ruby
|
135
|
+
cpu_temperature
|
136
|
+
).map { |m| [m, send(m)] }.to_h
|
137
|
+
end
|
138
|
+
|
85
139
|
private
|
86
140
|
|
87
141
|
def cache
|
@@ -96,6 +150,21 @@ module Pipark
|
|
96
150
|
end
|
97
151
|
end
|
98
152
|
|
153
|
+
def sh(command)
|
154
|
+
if localhost?
|
155
|
+
`#{command}`
|
156
|
+
else
|
157
|
+
`ssh #{address} "#{command}"`
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def get_led_status(led)
|
162
|
+
file = "/sys/class/leds/#{led}/trigger"
|
163
|
+
if File.readable? file
|
164
|
+
[ File.read(file).sub(/\[(.*)\]/, '\1').split, $1 ].reverse
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
99
168
|
def _view_21x8
|
100
169
|
view = 'RPi ' + hostname.rjust(17) + "\n\n"
|
101
170
|
view << os_release['NAME'].center(21) + "\n"
|
data/lib/pipark/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lllist.eu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|