class HardwareInformation
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
require 'hardware_information/class/menu.rb'
#¶ ↑
#¶ ↑
#¶ ↑
require 'hardware_information/class/obtain.rb'
#¶ ↑
#¶ ↑
require 'hardware_information/class/reset.rb'
#¶ ↑
#¶ ↑
require 'hardware_information/class/run.rb'
#¶ ↑
#¶ ↑
HardwareInformation::GUI::Gtk::PurchasedHardwareModule
¶ ↑
#¶ ↑
require 'hardware_information/gui/shared_code/purchased_hardware/purchased_hardware_module.rb' include ::HardwareInformation::GUI::Gtk::PurchasedHardwareModule
#¶ ↑
#¶ ↑
HardwareInformation::GUI::Gtk::ShowInputDevicesModule
¶ ↑
#¶ ↑
require 'hardware-information/gui/shared_code/foobar/foobar_module.rb' include ::HardwareInformation::GUI::Gtk::ShowInputDevicesModule
#¶ ↑
#¶ ↑
HardwareInformation::PurchasedHardware
¶ ↑
This module has been primarily written to support the old content shown in the old .cgi file. By having this available as a module we can, in principle, adapt this easily into sinatra or rails as well, so we gain more flexibility by using a module here.
#¶ ↑
require 'hardware_information/misc/purchased_hardware/purchased_hardware.rb' include HardwareInformation::PurchasedHardware
#¶ ↑
#¶ ↑
require 'hardware_information/monitor/monitor.rb' HardwareInformation.return_the_monitor_resolution
#¶ ↑
#¶ ↑
require 'hardware_information/project/project.rb'
#¶ ↑
#¶ ↑
require 'hardware_information/version/version.rb'
#¶ ↑
#¶ ↑
require 'hardware_information/www/embeddable_interface.rb' include HardwareInformation::EmbeddableInterface
#¶ ↑
Constants
- CPUINFO
- CPUINFO_LOCATION
#¶ ↑
CPUINFO_LOCATION
¶ ↑This constants stores where cpuinfo is kept. Will work only on Linux, I think.
#¶ ↑
- DATASET_FROM_PROC_MEMINFO
- ERROR_LINE
#¶ ↑
ERROR_LINE
¶ ↑#¶ ↑
- FILE_COLOURS_FOR_THE_HARDWARE_PROJECT
#¶ ↑
FILE_COLOURS_FOR_THE_HARDWARE_PROJECT
¶ ↑#¶ ↑
- LAST_UPDATE
#¶ ↑
LAST_UPDATE
¶ ↑#¶ ↑
- LEFT_PADDING
#¶ ↑
LEFT_PADDING
¶ ↑How many characters to pad on the left side. Used for the header_content() method.
#¶ ↑
- LSCPU
- LSPCI
- MAIN_DEFAULT_RJUST
#¶ ↑
MAIN_DEFAULT_RJUST
¶ ↑#¶ ↑
- N
#¶ ↑
N
¶ ↑#¶ ↑
- PROC_MEMINFO
#¶ ↑
PROC_MEMINFO
¶ ↑#¶ ↑
- PROJECT_BASE_DIRECTORY
#¶ ↑
PROJECT_BASE_DIRECTORY
¶ ↑#¶ ↑
- PROJECT_YAML_DIRECTORY
#¶ ↑
PROJECT_YAML_DIRECTORY
¶ ↑Refer to the internal yaml-directory as well.
#¶ ↑
- RAM_AVAILABLE
#¶ ↑
RAM_AVAILABLE
¶ ↑#¶ ↑
- RAM_AVAILABLE_FREE
#¶ ↑
RAM_AVAILABLE_FREE
¶ ↑#¶ ↑
- SPLITTED_CPUINFO
- VERSION
#¶ ↑
VERSION
¶ ↑#¶ ↑
Public Class Methods
#¶ ↑
HardwareInformation.return_the_monitor_resolution
¶ ↑
This method essentially captures the resolution from a String such as:
dimensions: 1920x1080 pixels (508x285 millimeters)
It will then return a String, as result, such as “1920x1080”.
#¶ ↑
# File lib/hardware_information/monitor/monitor.rb, line 20 def self.return_the_monitor_resolution result = `xdpyinfo`.split("\n").select {|entry| entry.include? 'dimensions' } if result.is_a? Array result = result.first end result.strip! if result.include? 'x' result = result.scan(/(\d{2,4}x\d{2,4})/).flatten.first.strip end return result end
#¶ ↑
HardwareInformation.start_sinatra_interface
¶ ↑
#¶ ↑
# File lib/hardware_information/www/my_hardware_for_sinatra.rb, line 56 def self.start_sinatra_interface puts 'Trying to start the sinatra-interface of HardwareInformation next.' HardwareInformation::SinatraMyHardware.start_sinatra_interface end
Public Instance Methods
#¶ ↑
_ (_ tag)¶ ↑
This method, as a shortcut, makes use of the method called add(), but it will also append a newline to the given input and support colours (if given as argument).
#¶ ↑
# File lib/hardware_information/class/misc.rb, line 74 def _(i, optional_colour = nil) if optional_colour and use_colours? # Add colours only if needed. if optional_colour.is_a? Symbol i = ::Colours.send(optional_colour, i) else i = optional_colour+i+rev end end add i+N # We try it with mandatory newline for now. end
#¶ ↑
add_title
¶ ↑
#¶ ↑
# File lib/hardware_information/class/misc.rb, line 88 def add_title optional_colour = nil if use_colours? if Object.const_defined? :Colours # User has the colours gem installed. optional_colour = :mediumslateblue else optional_colour = green? end end _ N+'Hardware Information'+N, optional_colour end
#¶ ↑
append_output_generated_via_lsblk
¶ ↑
Typical output generated via lsblk may be like this:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 2.7T 0 disk ├─sda1 8:1 0 1M 0 part └─sda2 8:2 0 2.7T 0 part / sr0 11:0 1 1024M 0 rom
#¶ ↑
# File lib/hardware_information/class/misc.rb, line 166 def append_output_generated_via_lsblk _ = ''.dup # ======================================================================== # # Next we will display/obtain more information, via df. # ======================================================================== # extended_information = `df -T`.split(N) result = `lsblk`.strip.split(N).map {|line| " #{line}" } result.each {|entry| # ===================================================================== # # Modify the input. # ===================================================================== # if entry.include? ' /' # =================================================================== # # These entries will be colourized. Note that the first part may # look like this: "└─sda2" # # " └─sda2 8:2 0 2.7T 0 part /" # # =================================================================== # splitted = entry.split(' ') # =================================================================== # # The root_entry may look like this: # # /dev/sda2 ext4 2883218608 529813416 2206875608 20% / # # =================================================================== # selection = extended_information.select {|line| last = line.split(' ').last last == '/' or last.include?('USB') } if selection selection = selection.select {|inner_line| inner_line.end_with? splitted[-1] } if selection.is_a?(Array) and selection.first selection = selection.first.split(' ') end end splitted[-1] = colourize_highlighted_content(splitted[-1].ljust(12)) # ← The last part. splitted[0] = colourize_highlighted_content(" #{splitted[0]}") # ← The first part. splitted[1] = colourize_via_regular_colour(splitted[1].strip.ljust(4).rjust(6)) splitted[2] = colourize_via_regular_colour(" #{splitted[2].strip.rjust(2)}") splitted[3] = colourize_filesize_of_the_harddisc(splitted[3].strip.rjust(5).ljust(6)) # ← The size of the harddisc. splitted[4] = colourize_via_regular_colour(splitted[4].strip.ljust(2).rjust(3)) splitted[5] = colourize_via_regular_colour(splitted[5].strip) file_system_type = selection[1] n_percent_occupied = selection[5] # =================================================================== # # /dev/sda2 ext4 2883218608 529753916 2206935108 20% /"] # =================================================================== # splitted = splitted.join(' ') unless entry.include? '/boot/' # ← Don't show information for /boot/ entries. splitted << colourize_file_system_type(" (#{file_system_type})") splitted << colourize_n_percent_occupied(" (#{n_percent_occupied} used)") end entry = splitted else # Else we only do a slightly simpler colourization-part. splitted = entry.split(' ') splitted[0] = colourize_via_regular_colour(" #{splitted[0].ljust(6)}") # ← The first part. splitted[1] = colourize_via_regular_colour(splitted[1].strip.ljust(4).rjust(6)) splitted[2] = colourize_via_regular_colour(" #{splitted[2].strip.rjust(2)}") splitted[3] = colourize_filesize_of_the_harddisc(splitted[3].strip.rjust(5).ljust(6)) # ← The size of the harddisc. splitted[4] = colourize_via_regular_colour(splitted[4].strip.ljust(2).rjust(3)) splitted[5] = colourize_via_regular_colour(splitted[5].strip) if splitted[6] and (splitted[6] == '[SWAP]') splitted[6] = royalblue(splitted[6]) end entry = splitted.join(' ') entry = colourize_via_regular_colour(entry) end _ << "#{entry}\n" # Now we can append this. } # ======================================================================= # # Add two newlines too, for slightly more readable output. # ======================================================================= # _ << "#{N}#{N}" add _ end
#¶ ↑
colourize_via_regular_colour
¶ ↑
Do note that this is presently hardcoded to the “thistle” colour. Unsure whether to allow the user more customization here, so for the time being this remains hardcoded.
#¶ ↑
# File lib/hardware_information/class/misc.rb, line 147 def colourize_via_regular_colour(i) Colours.send( :thistle, i ) end
#¶ ↑
make_line
¶ ↑
The first argument to this method should be the title that will be displayed.
The second argument should show the content towards that argument.
#¶ ↑
# File lib/hardware_information/class/make_line.rb, line 15 def make_line( title, content ) title = title.dup if title.frozen? use_this_colour_for_change = bold_teal? use_this_colour_to_revert = @default_colour # First a copy. title << ': ' if @use_colon_as_delimiter title = default_ljust(title) content = default_rjust(content) # ======================================================================= # # === Handle blocks next # # The passed block can modify the variable called content. This # will happen after the various padding-operations above. # ======================================================================= # if block_given? yielded = yield case yielded when nil # Pas through. else # Else, use colours. if use_colours? content = Colours.send(yielded, content) end end end string = ''.dup string << use_this_colour_for_change if use_colours? string << title string << use_this_colour_to_revert if use_colours? string = string.ljust(40) if content.is_a? Array _ string content.each {|line| _ " #{line}" } else string << content _ string end end
#¶ ↑
obtain_firmware_information
¶ ↑
Note that this functionality depends on the binary called “lshw”.
#¶ ↑
# File lib/hardware_information/class/obtain.rb, line 64 def obtain_firmware_information result = `lshw 2>&1` if result # ===================================================================== # # See: https://rubular.com/r/Uf4XqmbZW3atCy # ===================================================================== # regex = /description: Motherboard\s+product: (.+)\s+vendor: (.+)\s+[.:0-9a-zA-Z\n ]+\*-firmware[.:0-9a-zA-Z\n ]+version: (\d{0,4}[0-9.]+)\s+date: (\d{1,2}.+)/ result =~ regex motherboard = $1.to_s.dup motherboard_vendor = $2.to_s.dup bios_version = $3.to_s.dup bios_release = $4.to_s.dup # ===================================================================== # # Show some more information next, in particular the BIOS. # ===================================================================== # make_line(' Motherboard vendor', motherboard_vendor) make_line(' Motherboard', motherboard) make_line(' BIOS version', bios_version) make_line(' BIOS released on', bios_release) end end
#¶ ↑
obtain_pci_information
¶ ↑
#¶ ↑
# File lib/hardware_information/class/obtain.rb, line 145 def obtain_pci_information array_fetch_these_types = %w( SMBus Audio IDE VGA Memory Controller ) results = [] if LSPCI LSPCI.split(N).each {|line| array_fetch_these_types.each { |inner_line| results << line if line.include? inner_line } } make_line ' PCI Devices', results end end
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
# File lib/hardware_information/class/reset.rb, line 12 def reset # ======================================================================= # # === @string # ======================================================================= # @string = ''.dup # ======================================================================= # # === @default_colour # ======================================================================= # @default_colour = green? # ======================================================================= # # === @default_padding # # This variable denotes the leading padding. That padding will be # prepended to the output. # ======================================================================= # @default_padding = ' '.dup # 1 space. # ======================================================================= # # === @use_colours # ======================================================================= # @use_colours = true # If true we use ANSI colours. # ======================================================================= # # === @use_colon_as_delimiter # ======================================================================= # @use_colon_as_delimiter = true # If true we use colon as delimiter. # ======================================================================= # # === @hash_use_these_colours # # Next we will load the internal .yml file, if it exists. # ======================================================================= # @hash_use_these_colours = {} if File.exist? FILE_COLOURS_FOR_THE_HARDWARE_PROJECT require 'yaml' @hash_use_these_colours.update( YAML.load_file(FILE_COLOURS_FOR_THE_HARDWARE_PROJECT) ) else # else use a hardcoded approach. @hash_use_these_colours[:filesize_of_the_harddisc] = :orchid @hash_use_these_colours[:file_system_type] = :steelblue end set_commandline_mode # Default. end
#¶ ↑
return_information_about_the_GPU
¶ ↑
This method will return information about the GPU in use on the given computer system.
This may be similar to a String such as:
GPU: AMD ATI Radeon R7 Graphics
#¶ ↑
# File lib/hardware_information/class/obtain.rb, line 41 def return_information_about_the_GPU result = `lspci #{ERROR_LINE}`.strip if result and result.include?('VGA compatible controller') result = result.split(N).select {|line| line.include? 'VGA compatible controller' }.first # ===================================================================== # # Work on: # # VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Kaveri [Radeon R7 Graphics]" # # ===================================================================== # result = result.split('. [').last. delete('[]').tr('/',' ') end return result end
#¶ ↑
run¶ ↑
#¶ ↑
# File lib/hardware_information/class/run.rb, line 12 def run add_title obtain_architecture # === Architecture obtain_cpu_model # === The CPU model, such as "AMD" obtain_cpu_op_modes # === CPU op-modes obtain_n_cores # === n CPU cores find_out_the_amount_of_processors # === Amount of processors obtain_vendor_id # === Vendor ID obtain_virtualization # === Virtualization obtain_linux_kernel_version # === The Linux kernel version obtain_ram # === Amount of RAM obtain_ram_free obtain_swap_size # === SwapTotal obtain_chip_mhz # === Chip MHzx obtain_cache_size obtain_system_bogomips # === BogoMIPS obtain_byte_order obtain_cpu_family obtain_model # === Model obtain_information_about_the_GPU # === Show the GPU in use obtain_firmware_information # === Firmware Information obtain_pci_information add_audio_information # === Show the audio device obtain_information_about_the_monitor # === Gather information about the monitor append_newline append_output_generated_via_lsblk report_result if @run_already # Last but not least, report the result. end