linux_stat 1.0.2 → 1.2.1
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/README.md +250 -92
- data/ext/sysconf/sysconf.c +11 -0
- data/lib/linux_stat.rb +2 -1
- data/lib/linux_stat/net.rb +6 -2
- data/lib/linux_stat/os.rb +57 -20
- data/lib/linux_stat/pci.rb +363 -0
- data/lib/linux_stat/usb.rb +68 -13
- data/lib/linux_stat/version.rb +1 -1
- metadata +3 -2
data/lib/linux_stat/usb.rb
CHANGED
@@ -14,13 +14,13 @@ module LinuxStat
|
|
14
14
|
#
|
15
15
|
# It can have information like:
|
16
16
|
#
|
17
|
-
# id, vendor id, product id, manufacturer, serial, bus number, dev number,
|
17
|
+
# path, id, vendor id, product id, manufacturer, serial, bus number, dev number,
|
18
18
|
# b_max_power, b_max_packet_size, etc.
|
19
19
|
#
|
20
20
|
# An example of the returned sample from a test machine is:
|
21
21
|
# LinuxStat::USB.devices_stat
|
22
22
|
#
|
23
|
-
# [{:path=>"/sys/bus/usb/devices/1-1.2/", :id=>"04d9:1203", :vendor_id=>"04d9", :product_id=>"1203", :bus_num=>1, :dev_num=>4, :hwdata=>{:vendor=>"Holtek Semiconductor, Inc.", :product=>"Keyboard"}, :authorized=>true, :b_max_power=>"100mA", :b_max_packet_size0=>8}
|
23
|
+
# => [{:path=>"/sys/bus/usb/devices/1-1.2/", :id=>"04d9:1203", :vendor_id=>"04d9", :product_id=>"1203", :bus_num=>1, :dev_num=>4, :hwdata=>{:vendor=>"Holtek Semiconductor, Inc.", :product=>"Keyboard"}, :authorized=>true, :b_max_power=>"100mA", :b_max_packet_size0=>8}
|
24
24
|
#
|
25
25
|
# Right, it's an array of Hashes.
|
26
26
|
#
|
@@ -73,7 +73,7 @@ module LinuxStat
|
|
73
73
|
manufacturer = File.readable?(manufacturer_file) ? IO.read(manufacturer_file).strip : ''.freeze
|
74
74
|
|
75
75
|
removable_file = File.join(x, 'removable'.freeze)
|
76
|
-
removable = File.readable?(removable_file) ? IO.read(removable_file).strip : ''.freeze
|
76
|
+
removable = File.readable?(removable_file) ? IO.read(removable_file).strip.downcase : ''.freeze
|
77
77
|
|
78
78
|
authorized_file = File.join(x, 'authorized'.freeze)
|
79
79
|
authorized = File.readable?(authorized_file) ? IO.read(authorized_file).to_i : ''.freeze
|
@@ -86,7 +86,6 @@ module LinuxStat
|
|
86
86
|
|
87
87
|
query = hwdata ? query_hwdata(id_vendor, id_product) : {}
|
88
88
|
|
89
|
-
removable.downcase!
|
90
89
|
is_removable = if removable == 'removable'.freeze
|
91
90
|
true
|
92
91
|
elsif removable == 'unknown'.freeze
|
@@ -114,6 +113,8 @@ module LinuxStat
|
|
114
113
|
|
115
114
|
ret.merge!(b_max_power: b_max_power) unless b_max_power.empty?
|
116
115
|
ret.merge!(b_max_packet_size0: b_max_packet_size0) if b_max_packet_size0
|
116
|
+
|
117
|
+
ret
|
117
118
|
}.tap(&:compact!)
|
118
119
|
end
|
119
120
|
|
@@ -141,11 +142,63 @@ module LinuxStat
|
|
141
142
|
}
|
142
143
|
end
|
143
144
|
|
145
|
+
##
|
146
|
+
# hwdata_file = file
|
147
|
+
#
|
148
|
+
# Lets you set the hwdata_file about usb.ids.
|
149
|
+
#
|
150
|
+
# The hwdata file about usb.ids contains vendor name and product name information about
|
151
|
+
# devices. This is then mapped by the other methods that utilizes hwdata/usb.ids.
|
152
|
+
#
|
153
|
+
# Do note that this method is intended to run only once, at the beginning.
|
154
|
+
# If you use any other method that utilizes hwdata/usb.ids, before
|
155
|
+
# calling this method, this method will not work.
|
156
|
+
def hwdata_file=(file)
|
157
|
+
@@hwdata_file ||= file.freeze
|
158
|
+
end
|
159
|
+
|
160
|
+
##
|
161
|
+
# Checks if hwdata_file is already initialized or not.
|
162
|
+
# Once it's initialized, calling hwdata_file = 'something/usb.ids' is futile.
|
163
|
+
def hwdata_file_set?
|
164
|
+
@@hwdata_file ||= nil
|
165
|
+
!!@@hwdata_file
|
166
|
+
end
|
167
|
+
|
168
|
+
##
|
169
|
+
# Returns the hwdata_file as string.
|
170
|
+
#
|
171
|
+
# If hwdata_file isn't set, it will return an empty frozen string.
|
172
|
+
#
|
173
|
+
# Once it's set, it can't be changed.
|
174
|
+
def hwdata_file
|
175
|
+
@@hwdata_file ||= nil
|
176
|
+
@@hwdata_file ? @@hwdata_file : ''.freeze
|
177
|
+
end
|
178
|
+
|
179
|
+
##
|
180
|
+
# Initializes hwdata
|
181
|
+
#
|
182
|
+
# hwdata can take upto 0.1 to 0.2 seconds to get initialized.
|
183
|
+
#
|
184
|
+
# Calling this method will load hwdata for future use.
|
185
|
+
#
|
186
|
+
# Once it's initialized, hwdata_file can't be changed.
|
187
|
+
#
|
188
|
+
# If this method initializes hwdata, it will return true
|
189
|
+
# Othewise this method will return false.
|
190
|
+
def initialize_hwdata
|
191
|
+
@@hwdata ||= nil
|
192
|
+
init = !@@hwdata
|
193
|
+
hwdata
|
194
|
+
init
|
195
|
+
end
|
196
|
+
|
144
197
|
alias count_devices count
|
145
198
|
|
146
199
|
private
|
147
200
|
def hwdata
|
148
|
-
@@hwdata_file ||= "/usr/share/hwdata/usb.ids"
|
201
|
+
@@hwdata_file ||= "/usr/share/hwdata/usb.ids".freeze
|
149
202
|
|
150
203
|
@@hwdata ||= if File.readable?(@@hwdata_file)
|
151
204
|
file_data = IO.readlines(@@hwdata_file, encoding: 'ASCII-8BIT')
|
@@ -158,17 +211,19 @@ module LinuxStat
|
|
158
211
|
x = file_data[i]
|
159
212
|
|
160
213
|
_lstripped = x.lstrip
|
161
|
-
next if _lstripped == ?#.freeze || _lstripped.empty?
|
214
|
+
next if _lstripped[0] == ?#.freeze || _lstripped.empty?
|
215
|
+
|
216
|
+
if x[0] == ?\t.freeze
|
217
|
+
next unless vendor_id
|
162
218
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
device = data[device_id.length..-1].to_s.strip
|
219
|
+
x.strip!
|
220
|
+
device_id = x[/\A.*?\s/].to_s.strip
|
221
|
+
device = x[device_id.length..-1].to_s.strip
|
167
222
|
ret[vendor_id][1][device_id] = device
|
168
223
|
else
|
169
|
-
|
170
|
-
vendor_id =
|
171
|
-
vendor =
|
224
|
+
x.strip!
|
225
|
+
vendor_id = x[/\A.*?\s/].to_s.strip
|
226
|
+
vendor = x[vendor_id.length..-1].to_s.strip
|
172
227
|
ret[vendor_id] = [vendor, {}]
|
173
228
|
end
|
174
229
|
end
|
data/lib/linux_stat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linux_stat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sourav Goswami
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Linux only, efficient linux system utilization reporting and system monitoring
|
14
14
|
gem
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/linux_stat/mounts.rb
|
48
48
|
- lib/linux_stat/net.rb
|
49
49
|
- lib/linux_stat/os.rb
|
50
|
+
- lib/linux_stat/pci.rb
|
50
51
|
- lib/linux_stat/prettify_bytes.rb
|
51
52
|
- lib/linux_stat/process.rb
|
52
53
|
- lib/linux_stat/process_info.rb
|