rsensors 0.2.82 → 0.2.949

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/rsensors.rb +108 -72
  3. metadata +10 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4bda4f2f025e38d76c150ff9f87285bd6006e628
4
- data.tar.gz: 525a419abaeb6c922292449e62f1f2aaeb6e06db
2
+ SHA256:
3
+ metadata.gz: 98aefec70543f8c42b08d86030903d960da449822905815f0ed538576957f623
4
+ data.tar.gz: b3ec121fadd2abf5778b4c2410927e67112cc7c84ba8c15dc701fe0b4380eac2
5
5
  SHA512:
6
- metadata.gz: 0c266fd6e5ed4fe33d75819698d7afe133785488d0beaac1c0395b35778cb272f7cce3ba49179eb5f64ee3459b05dfe61d9792add1f0a0cd6326a56887349ae8
7
- data.tar.gz: 28b3fab9601c48b4e507c2aa33502b8496cc90722c3e367db40844f600b8002a34272d3fdf56bba15f09888e2c3504f3088bd18917ea23afad671ff89bfbaae8
6
+ metadata.gz: bb1df3ad4a4b7b7d0cb35569a110d837e38992fed5ff429c2a212f28a4d49a1284acba5aeca78831226f4d722645aaa96ed85bfacdb959e814542313b881bc0c
7
+ data.tar.gz: b6d476f79ca0c0fdf93977e75c3b25caae38e1a47ae0363fb3ba671e540589dbeffbd3532cfca6ef9b96a3631126a9da5b5401439ea162477336bb21fcb27cc6
@@ -1,20 +1,20 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #!/usr/bin/ruby
3
3
 
4
- # @title Rsensors module
5
- # A module to provide info about system temperatures, and cronify and triggers if conditions are fulfilled
4
+ # @title Rsensors module
5
+ # A module to provide info about system temperatures, and cronify and triggers if conditions are fulfilled
6
6
  # Available submodules:
7
7
  # Sensor : Return all requested info from system sensors: CPU(s) and hard disk(s) temperatures
8
8
  # Notification : Launch temperature notification on GUI and console text
9
- # Cronify : Schedule notification by a crontab on selected conditions and limits
9
+ # Cronify : Schedule notification by a crontab on selected conditions and limits
10
10
 
11
11
  #Gem name Require statement Main class or module
12
12
  #rsensors require 'libnotify' Rsensors
13
13
  # more info Rsensors = Ruby Sensors https://github.com/jacob-mf/rsensors
14
- # @version 0.2.8 @date 15-3-2018
14
+ # @version 0.2.945 @date 19-2-2020 # 0.2.8 @date 15-3-2018
15
15
  # @author Luis Jacob Mariscal Fernández
16
16
  # Currently works/tests only over Linux, on kernel above 3
17
-
17
+
18
18
  require 'libnotify'
19
19
 
20
20
  module Rsensors
@@ -22,24 +22,32 @@ module Rsensors
22
22
 
23
23
  module Sensor
24
24
  # == Returns:
25
- # A float value of the system's temperature
25
+ # A float value of the system's temperature (one CPU value available)
26
+ # @param void
27
+ # @return [Float] cpu temperature or [False] if not available
28
+ # @raise none
29
+ # @advice good to check other sources on next developments
26
30
  def self.temperature1
27
31
  if File.exists?('/sys/class/hwmon/hwmon0/temp1_input')
28
32
  File.read('/sys/class/hwmon/hwmon0/temp1_input').to_f / 1000
29
33
  else false
30
- end
34
+ end
31
35
  end
32
- def self.temperature2
36
+ def self.temperature2
33
37
  if File.exists?('/sys/class/hwmon/hwmon0/device/temp2_input')
34
38
  File.read('/sys/class/hwmon/hwmon0/device/temp2_input').to_f / 1000
39
+ elsif File.exists?('/sys/class/hwmon/hwmon0/temp2_input')
40
+ File.read('/sys/class/hwmon/hwmon0/temp2_input').to_f / 1000
35
41
  else false
36
- end
42
+ end
37
43
  end
38
44
  def self.temperature4
39
- if File.exists?('/sys/class/hwmon/hwmon0/device/temp4_input')
45
+ if File.exists?('/sys/class/hwmon/hwmon0/device/temp4_input')
40
46
  File.read('/sys/class/hwmon/hwmon0/device/temp4_input').to_f / 1000
47
+ elsif File.exists?('/sys/class/hwmon/hwmon0/temp4_input')
48
+ File.read('/sys/class/hwmon/hwmon0/temp4_input').to_f / 1000
41
49
  else false
42
- end
50
+ end
43
51
  end
44
52
  def self.temperature_hd # need superuser or privileges with apps
45
53
  # 1st try hddtemp
@@ -50,7 +58,7 @@ module Rsensors
50
58
  end #dtemp -n /dev/?d? ) # good for one line, one hard disk
51
59
  return temp
52
60
  end
53
- def self.format_hdparm (text)
61
+ def self.format_hdparm(text)
54
62
  sol = ""
55
63
  text.each_line { |line|
56
64
  if /^\/dev/.match(line) # hard disk detected
@@ -60,8 +68,8 @@ module Rsensors
60
68
  elsif /^ Model=(\w+),*/.match(line) # model detected
61
69
  m1 = /^ Model=(\w+\s+\w+),*/.match(line)
62
70
  #p m1
63
- sol += m1[1]
64
- end
71
+ sol += m1[1]
72
+ end
65
73
  }
66
74
  return sol # return
67
75
  end
@@ -79,29 +87,45 @@ module Rsensors
79
87
  return temp if temp.is_a? Array
80
88
  return temp.to_f
81
89
  end
82
- def self.formatHdparm(entry)
83
- sol = []
84
- ok_sense = true
85
- entry.each_line { |line|
86
- if /^\/dev/.match(line) # hard disk detected
87
- ok_sense = true # activate sense
88
- elsif m1 = /^ drive temperature \(celsius\) is:\s+(d+)/.match(line) # info detected
89
- sol << m1[1] if ok_sense
90
- elsif /^SG_IO: bad\/missing sense data/.match(line) # sense problem detected
91
- ok_sense = false
92
- end
93
- }
94
- return sol[0].to_f if sol.size == 1
90
+ def self.hdparmInfoOk(line)
91
+ /^ drive temperature \(celsius\) is:\s+(d+)/.match(line) # info detected
92
+ end
93
+ def self.hdparmProblem(line)
94
+ /^SG_IO: bad\/missing sense data/.match(line) # sense problem detected
95
+ end
96
+ def self.hdDetect(line)
97
+ return /^\/dev/.match(line) # hard disk detected
98
+ end
99
+ def self.hdParmOutput(sol)
100
+ return sol[0].to_f if sol.size == 1
95
101
  return sol
96
102
  end
103
+ def self.hdparmLine(line, ol, ok_sense)
104
+ if hdDetect(line)
105
+ ok_sense = true # activate sense
106
+ elsif m1= hdParmInfoOk(line) # info detected
107
+ sol << m1[1] if ok_sense
108
+ elsif hdparmProblem(line) # sense problem detected
109
+ ok_sense = false
110
+ end
111
+ return sol, ok_sense
112
+ end
113
+ def self.formatHdparm(entry)
114
+ sol = []
115
+ ok_sense = true
116
+ entry.each_line { |line|
117
+ sol, ok_sense = hdparmLine(line,sol,ok_sense)
118
+ }
119
+ hdParmOutput(sol)
120
+ end
97
121
  def self.formatHddtemp(entry)
98
122
  sol = []
99
123
  entry.each_line { |line|
100
124
  if m1 = /\w+(\/?d?\/):(\w+) not available/.match(line) # error detected
101
- puts "**warning** drive /dev/#{m1[1]} sensor not available"
125
+ puts "**warning** drive /dev/#{m1[1]} sensor not available"
102
126
  elsif m1 = /^(d+)/.match(line) # info detected
103
- sol << m1[1]
104
- end
127
+ sol << m1[1]
128
+ end
105
129
  }
106
130
  return sol[0].to_f if sol.size == 1
107
131
  return sol
@@ -109,64 +133,64 @@ module Rsensors
109
133
  def self.maxTemperatureHd
110
134
  temp = temperatureHd # float or array of temperatures
111
135
  return temp if temp.is_a? Float
112
- return temp.max
113
- end
136
+ return temp.max # return max temp from available hard disks
137
+ end
114
138
  def self.temperature
115
- if temperature1
139
+ if temperature1
116
140
  return temperature1
117
141
  elsif temperature2
118
142
  return temperature2
119
143
  elsif temperature4
120
- return temperature4
144
+ return temperature4
121
145
  else return 0 # to perform float test, give a correct answer
122
- end
146
+ end
123
147
  end
124
148
  end
125
149
 
126
150
  # Uses system notification to notify of current temperature.
127
151
  # Currently works/tested only on Linux
128
- module Notification
129
- def self.notify (max_temp_cpu = 77, max_temp_hd = 46) # optional max_temperature CPU hard disk values
130
- temp = Sensor.temperature1
131
- temp2 = Sensor.temperature2
132
- temp4 = Sensor.temperature4
133
- temp_hd = Sensor.temperature_hd
134
- # p Sensor.maxTemperatureHd
135
- if temp2 && temp4
136
- sentence = "Your computer's temperature is now:\n Core 2 #{temp2} °C, Core 4: #{temp4} °C\n Average temperature: #{(temp4+temp2)/2} °C\n" + temp_hd
137
- n = Libnotify.new(
138
- summary: 'Temperature',
139
- body: sentence ,
140
- timeout: 2.5,
141
- append: true
152
+ module Notification
153
+ def self.create_notification()
154
+ return Libnotify.new(
155
+ summary: 'Temperature',
156
+ timeout: 2.5,
157
+ append: true
142
158
  )
159
+ end
160
+ def self.text4cores(t2, t4, t_hd)
161
+ return "Your computer's temperature is now:\n Core 2 #{t2} °C, Core 4: #{t4} °C\n Average temperature: #{(t4+t2)/2} °C\n" + t_hd
162
+ end
163
+ def self.text1cpu(t, t_hd)
164
+ return "Your computer's temperature is now: #{t} °C\n" + t_hd
165
+ end
166
+ def self.textHdOnly(t_hd)
167
+ return "Your computer's temperature is currently unknown by this app, sorry. Wait for a brilliant update. Peace\n" + temp_hd
168
+ end
169
+ def self.notifyOutput(n)
170
+ puts n.body #sentence # check exit, now nothing on console
171
+ puts "URGENT!" if n.urgency == :critical
172
+ puts "Normal temperatures" if n.urgency == :normal
173
+ n.show!
174
+ end
175
+ def self.notifyInit
176
+ return Sensor.temperature1, Sensor.temperature2, Sensor.temperature4, Sensor.temperature_hd, create_notification()
177
+ end
178
+ def self.notify(max_temp_cpu = 77, max_temp_hd = 46) # optional max_temperature CPU hard disk values
179
+ # change to multiple assignation
180
+ temp, temp2, temp4, temp_hd, n = notifyInit
181
+ n.urgency = Sensor.maxTemperatureHd > max_temp_hd ? :critical : :normal # temp_hd[1] store number
182
+ if temp2 && temp4
183
+ n.body = text4cores(temp2, temp4, temp_hd) #code climate refactor
143
184
  n.urgency = temp2 > max_temp_cpu ? :critical : :normal
144
185
  n.urgency = temp4 > max_temp_cpu ? :critical : :normal
145
- n.urgency = Sensor.maxTemperatureHd > max_temp_hd ? :critical : :normal
146
186
  elsif temp
147
- sentence = "Your computer's temperature is now: #{temp} °C\n" + temp_hd
148
- n = Libnotify.new(
149
- summary: 'Temperature',
150
- body: sentence ,
151
- timeout: 2.5,
152
- append: true
153
- )
154
- n.urgency = temp > max_temp ? :critical : :normal
155
- n.urgency = Sensor.maxTemperatureHd > max_temp_hd ? :critical : :normal
187
+ n.body = text1cpu(temp, temp_hd)
188
+ n.urgency = temp > max_temp ? :critical : :normal
156
189
  else
157
- sentence = "Your computer's temperature is currently unknown by this app, sorry. Wait for a brilliant update. Peace\n" + temp_hd
158
- n = Libnotify.new(
159
- summary: 'Temperature',
160
- body: sentence ,
161
- timeout: 2.5,
162
- append: true
163
- )
164
- n.urgency = Sensor.maxTemperatureHd > max_temp_hd ? :critical : :normal # temp_hd[1] store number
190
+ n.body = textHdOnly(temp_hd)
165
191
  end
166
- puts sentence # check exit, now nothing on console
167
- puts "URGENT!" if n.urgency
168
- n.show!
169
- exit(0)
192
+ notifyOutput(n)
193
+ exit (0)
170
194
  end
171
195
  end
172
196
 
@@ -175,7 +199,7 @@ module Rsensors
175
199
  # Tries to write the crontab and exits with the appropiate code
176
200
  # you can edit the file with command $ crontab -e
177
201
  def self.schedule(max_cpu = 76, max_hd = 44, cron_value = "22,44 * * * *") # first cron_value = 0,10,20,30,40,50 * * * *
178
- cron = <<-END.gsub(/^ {8}/, '') # Heredoc try
202
+ cron = <<-END.gsub(/^ {8}/, '') # Heredoc try
179
203
  # Rsensors temperature notification
180
204
  #{cron_value} /bin/bash -l -c 'rsensors job #{max_cpu} #{max_hd}'
181
205
  # End Rsensors temperature notification
@@ -200,5 +224,17 @@ module Rsensors
200
224
  exit(1)
201
225
  end
202
226
  end
227
+
228
+ def self.reset
229
+ if system("crontab -r")
230
+ puts 'INFO: Erase rsensors on the crontab file'
231
+ file.unlink
232
+ exit(0)
233
+ else
234
+ warn 'ERROR: Failed to delete rsensors on crontab'
235
+ file.unlink
236
+ exit(1)
237
+ end
238
+ end
203
239
  end
204
240
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsensors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.82
4
+ version: 0.2.949
5
5
  platform: ruby
6
6
  authors:
7
7
  - L. Jacob Mariscal Fernández
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-15 00:00:00.000000000 Z
11
+ date: 2020-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libnotify
@@ -38,23 +38,9 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.3'
41
- - !ruby/object:Gem::Dependency
42
- name: rubocop
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.47.1
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.47.1
55
41
  description: Show a notification of your computer's temperature. It can be programmed
56
- as a cronjob, so you can be notified when the temperature is high | Muestra la temperatura
57
- del sistema, puede igual actuar en segundo plano para alertar de alta temperatura
42
+ as a cronjob, so you can be notified when the temperature is high | Muestra la temperaturas
43
+ del sistema, puede igual actuar en segundo plano para alertar de altas temperaturas
58
44
  email: l.jacob.m.f@gmail.com
59
45
  executables:
60
46
  - rsensors
@@ -67,16 +53,16 @@ homepage: https://github.com/jacob-mf/rsensors
67
53
  licenses:
68
54
  - GPL-3.0
69
55
  metadata: {}
70
- post_install_message: Gracias por probar la gema rsensors | Thanks for installing
71
- and trying rsensors gem
56
+ post_install_message: "Gracias por probar la gema rsensors | \nThanks for installing
57
+ and trying the rsensors gem"
72
58
  rdoc_options: []
73
59
  require_paths:
74
60
  - lib
75
61
  required_ruby_version: !ruby/object:Gem::Requirement
76
62
  requirements:
77
- - - ">="
63
+ - - "~>"
78
64
  - !ruby/object:Gem::Version
79
- version: '0'
65
+ version: '2.0'
80
66
  required_rubygems_version: !ruby/object:Gem::Requirement
81
67
  requirements:
82
68
  - - ">="
@@ -84,9 +70,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
70
  version: '0'
85
71
  requirements: []
86
72
  rubyforge_project:
87
- rubygems_version: 2.5.2
73
+ rubygems_version: 2.7.6
88
74
  signing_key:
89
75
  specification_version: 4
90
- summary: 'A gem to display system hardware temperature | Gema para mostrar la termperatura
76
+ summary: 'A gem to display system hardware temperatures | Gema para mostrar la termperatura
91
77
  del sistema: microprocesador(es) y disco(s) duro(s)'
92
78
  test_files: []