pipark 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/pipark/host.rb +97 -0
- data/lib/pipark/version.rb +11 -0
- data/lib/pipark.rb +10 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 16a953e0d6a1e73e4e56e474b2c3a4b255e8ef9446f4527134458032f86b03f3
|
4
|
+
data.tar.gz: af53d006e3cebeafab803d148b7ba17d9c1fa47bf44ffe76fe7f25835b4d2450
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ecfe6db4a9348b8ac98b4ae2582f2630b80c6e5f82ee8e496ea2b6c4b9a7cff74ccf5cebe21f555199acf8fb3b1903b9fd4b595b420aeee57056052925f588c8
|
7
|
+
data.tar.gz: 3dfa7daf5829382f162a40b41d80d1e5b74318a0161ae6ad911a913d06f09a1236fff4f8f467dfb055cac222be434ded578dce175621025d79121c2d115d02de
|
data/lib/pipark/host.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
module Pipark
|
2
|
+
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# Creates a Host object for the address.
|
6
|
+
def host(address)
|
7
|
+
Host.new(address)
|
8
|
+
end
|
9
|
+
|
10
|
+
alias pi host
|
11
|
+
|
12
|
+
# Creates a Host object for localhost.
|
13
|
+
def localhost
|
14
|
+
host 'localhost'
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns true if the address can be pinged.
|
18
|
+
def pingable?(address)
|
19
|
+
system "ping -c 1 #{address} > /dev/null 2>&1"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
class Host
|
26
|
+
|
27
|
+
attr_reader :address
|
28
|
+
|
29
|
+
def initialize(address)
|
30
|
+
@address = address
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns a programmer-friendly representation of the host.
|
34
|
+
def inspect
|
35
|
+
%Q(Pipark::Host "#{address}")
|
36
|
+
end
|
37
|
+
|
38
|
+
# Flushes cached attributes.
|
39
|
+
def flush
|
40
|
+
@cache = {}
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns true if the host is localhost.
|
44
|
+
def localhost?
|
45
|
+
@localhost ||= %w(localhost 127.0.0.1 ::1).include? address
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns true if the host can be pinged.
|
49
|
+
def pingable?
|
50
|
+
Pipark.pingable? address
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns the host's hostname.
|
54
|
+
def hostname
|
55
|
+
cache['hostname'] ||= file_read('/etc/hostname').chomp
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns the host's Raspberry Pi model.
|
59
|
+
def model
|
60
|
+
cache['model'] ||= file_read('/proc/device-tree/model').chop
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns the hosts's CPU temperature.
|
64
|
+
def cpu_temperature
|
65
|
+
file_read('/sys/class/thermal/thermal_zone0/temp').chomp.to_i
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns information about the host's operating system.
|
69
|
+
def os_release
|
70
|
+
cache['os-release'] ||=
|
71
|
+
file_read('/etc/os-release').lines.map { |l| l.chomp.split('=') }.map { |k,v| [k,v.chomp.gsub('"','')] }.to_h
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def cache
|
77
|
+
@cache ||= {}
|
78
|
+
end
|
79
|
+
|
80
|
+
def file_read(file)
|
81
|
+
if localhost?
|
82
|
+
File.read(file)
|
83
|
+
else
|
84
|
+
`ssh #{address} cat #{file}`
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def _view_21x8
|
89
|
+
view = 'RPi ' + hostname.rjust(17) + "\n\n"
|
90
|
+
view << os_release['NAME'].center(21) + "\n"
|
91
|
+
view << os_release['VERSION'].center(21) + "\n\n"
|
92
|
+
view << " CPU %2d °C\n" % (cpu_temperature*0.001)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/lib/pipark.rb
ADDED
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pipark
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- lllist.eu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/pipark.rb
|
20
|
+
- lib/pipark/host.rb
|
21
|
+
- lib/pipark/version.rb
|
22
|
+
homepage: https://github.com/lllisteu/pipark
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata:
|
26
|
+
homepage_uri: https://github.com/lllisteu/pipark
|
27
|
+
changelog_uri: https://github.com/lllisteu/pipark/blob/master/History.md
|
28
|
+
documentation_uri: https://www.rubydoc.info/gems/pipark
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.5.0
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubygems_version: 3.3.11
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Pea-brained control of Raspberry Pi's
|
48
|
+
test_files: []
|