class Archey
Constants
- ARCHEY_BIN
- ENTRY_LABELS
- IRC_CTRL
- IRC_RESET
- NOT_DETECTED
- NO_ADDRESS
- STYLE_TITLE
Public Class Methods
Source
# File plugins/archey.rb, line 163 def self.blocks_to_human_readable(blocks_kib) blocks = blocks_kib.to_f unit = "Ki" %w[Ki Mi Gi Ti Pi Ei Zi Yi].each do |candidate| unit = candidate break if blocks < 1024.0 blocks /= 1024.0 end format("%.1f", blocks) + " #{unit}B" end
Source
# File plugins/archey.rb, line 54 def self.default_run lambda do |argv| Open3.capture3(*argv) end end
Source
# File plugins/archey.rb, line 236 def self.entry_value(label, data) case label when "User" then data["User"].to_s.strip when "Hostname" then data["Hostname"].to_s.strip when "Model" then data["Model"].to_s.strip when "Distro" then format_distro(data["Distro"]) when "Kernel" then format_kernel(data["Kernel"]) when "Uptime" then format_uptime(data["Uptime"]) when "Load Average" then format_load(data["Load Average"]) when "Processes" then data["Processes"]&.to_s when "Window Manager" then format_window_manager(data["Window Manager"]) when "Desktop Environment" then format_desktop_environment(data["Desktop Environment"]) when "Shell" then data["Shell"].to_s.strip when "Terminal" then data["Terminal"].to_s.strip when "Packages" then format_packages(data["Packages"]) when "Temperature" then format_temperature(data["Temperature"]) when "CPU" then format_cpu(data["CPU"]) when "GPU" then format_gpu(data["GPU"]) when "RAM" then format_ram(data["RAM"]) when "Disk" then format_disk_total(data["Disk"]) when "LAN IP" then format_ip_list(data["LAN IP"]) when "WAN IP" then format_ip_list(data["WAN IP"]) end end
Source
# File plugins/archey.rb, line 144 def self.format_cpu(cpus) return NOT_DETECTED unless cpus.is_a?(Array) && !cpus.empty? entries = cpus.filter_map do |entry| next unless entry.is_a?(Hash) && !entry.empty? model, count = entry.first count.to_i > 1 ? "#{count.to_i} x #{model}" : model.to_s end entries.empty? ? NOT_DETECTED : entries.join(", ") end
Source
# File plugins/archey.rb, line 197 def self.format_desktop_environment(value) return NOT_DETECTED if value.nil? || value.to_s.strip.empty? value.to_s end
Source
# File plugins/archey.rb, line 177 def self.format_disk_total(disks) return nil unless disks.is_a?(Hash) && !disks.empty? used = disks.values.sum { |entry| entry["used_blocks"].to_f } total = disks.values.sum { |entry| entry["total_blocks"].to_f } return nil unless total.positive? "#{blocks_to_human_readable(used)} / #{blocks_to_human_readable(total)}" end
Source
# File plugins/archey.rb, line 105 def self.format_distro(distro) return NOT_DETECTED unless distro.is_a?(Hash) name = distro["name"].to_s.strip arch = distro["arch"].to_s.strip return NOT_DETECTED if name.empty? && arch.empty? return arch if name.empty? return name if arch.empty? "#{name} #{arch}" end
Source
# File plugins/archey.rb, line 232 def self.format_entry_line(label, value) "#{label}: #{value}" end
Source
# File plugins/archey.rb, line 220 def self.format_gpu(gpus) return NOT_DETECTED unless gpus.is_a?(Array) && !gpus.empty? list = gpus.map(&:to_s).reject(&:empty?) list.empty? ? NOT_DETECTED : list.join(", ") end
Source
# File plugins/archey.rb, line 227 def self.format_ip_list(ips) list = Array(ips).map(&:to_s).reject(&:empty?) list.empty? ? NO_ADDRESS : list.join(", ") end
Source
# File plugins/archey.rb, line 117 def self.format_kernel(kernel) return NOT_DETECTED unless kernel.is_a?(Hash) name = kernel["name"].to_s.strip release = kernel["release"].to_s.strip return NOT_DETECTED if name.empty? && release.empty? [name, release].reject(&:empty?).join(" ") end
Source
# File plugins/archey.rb, line 127 def self.format_load(load) return nil unless load.is_a?(Array) && !load.empty? load.map { |value| value.to_f.round(2).to_s }.join(" ") end
Source
# File plugins/archey.rb, line 157 def self.format_packages(packages) return NOT_DETECTED unless packages.is_a?(Hash) && !packages.empty? packages.map { |manager, count| "(#{manager}) #{count}" }.join(", ") end
Source
# File plugins/archey.rb, line 133 def self.format_ram(ram) return nil unless ram.is_a?(Hash) used = ram["used"] total = ram["total"] unit = ram["unit"].to_s.strip return nil if used.nil? || total.nil? || unit.empty? "#{used.to_i} #{unit} / #{total.to_i} #{unit}" end
Source
# File plugins/archey.rb, line 280 def self.format_report(payload) data = payload["data"] || {} meta = payload["meta"] || {} header = IrcFormat.report_header(tag: "ARCHEY", title: banner_title(data), style: STYLE_TITLE) body = report_body_lines(data) footer_parts = ["archey4 #{meta_version(meta)}"] count = meta["count"] footer_parts << "#{count} entries" unless count.nil? footer = IrcFormat.report_footer(*footer_parts) ([header] + body + [footer]).join("\n") end
Source
# File plugins/archey.rb, line 203 def self.format_temperature(temp) return NOT_DETECTED if temp.nil? return temp.to_s unless temp.is_a?(Hash) reading = temp["temperature"] return NOT_DETECTED if reading.nil? unit = temp.fetch("unit", "C") separator = temp.fetch("char_before_unit", " ") text = "#{reading}#{separator}#{unit}" max_reading = temp["max_temperature"] text += " (Max. #{max_reading}#{separator}#{unit})" unless max_reading.nil? text end
Source
# File plugins/archey.rb, line 72 def self.format_uptime(uptime) return nil unless uptime.is_a?(Hash) days = uptime["days"].to_i hours = uptime["hours"].to_i minutes = uptime["minutes"].to_i text = +"" if days.positive? text << "#{days} day" text << "s" if days > 1 if hours.positive? || minutes.positive? text << (hours.positive? == minutes.positive? ? ", " : " and ") end end if hours.positive? text << "#{hours} hour" text << "s" if hours > 1 text << " and " if minutes.positive? end if minutes.positive? text << "#{minutes} minute" text << "s" if minutes > 1 elsif !days.positive? && !hours.positive? text << "< 1 minute" end text.empty? ? nil : text end
Source
# File plugins/archey.rb, line 187 def self.format_window_manager(wm) return NOT_DETECTED unless wm.is_a?(Hash) name = wm["name"] return NOT_DETECTED if name.nil? || name.to_s.strip.empty? protocol = wm["display_server_protocol"] protocol.nil? || protocol.to_s.strip.empty? ? name.to_s : "#{name} (#{protocol})" end
Source
# File plugins/archey.rb, line 273 def self.meta_version(meta) version = Array(meta["version"]) return nil if version.empty? version.first(3).join(".") end
Source
# File plugins/archey.rb, line 64 def self.parse_json_output(stdout, stderr) combined = [stdout, stderr].join("\n") json_line = combined.lines.reverse.map(&:strip).find { |line| line.start_with?("{") } raise JSON::ParserError, "no JSON object found" unless json_line JSON.parse(json_line) end
Source
# File plugins/archey.rb, line 295 def self.report(run: default_run) stdout, stderr, status = run.call(build_argv) return "Unable to run archey4." unless status.success? payload = parse_json_output(stdout, stderr) format_report(payload) rescue JSON::ParserError "Unable to parse archey4 output." rescue StandardError "Unable to run archey4." end
Source
# File plugins/archey.rb, line 261 def self.report_body_lines(data) ENTRY_LABELS.map do |label| format_entry_line(label, entry_value(label, data)) end end
Public Instance Methods
Source
# File plugins/archey.rb, line 307 def execute(m) themed_flood_safe_reply(m, self.class.report) end