environment_information 1.4.29
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of environment_information might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +1061 -0
- data/bin/envi +7 -0
- data/bin/fast_envi +7 -0
- data/doc/README.gen +893 -0
- data/doc/TODO_FOR_THE_ENVIRONMENT_INFORMATION_PROJECT.md +54 -0
- data/environment_information.gemspec +130 -0
- data/lib/environment_information/base/base.rb +113 -0
- data/lib/environment_information/class/add.rb +186 -0
- data/lib/environment_information/class/colours.rb +283 -0
- data/lib/environment_information/class/constants.rb +35 -0
- data/lib/environment_information/class/environment_information.rb +51 -0
- data/lib/environment_information/class/help.rb +86 -0
- data/lib/environment_information/class/html.rb +78 -0
- data/lib/environment_information/class/initialize.rb +178 -0
- data/lib/environment_information/class/menu.rb +436 -0
- data/lib/environment_information/class/misc.rb +821 -0
- data/lib/environment_information/class/opn.rb +33 -0
- data/lib/environment_information/class/register_sigint.rb +20 -0
- data/lib/environment_information/class/reset.rb +213 -0
- data/lib/environment_information/class/ruby.rb +79 -0
- data/lib/environment_information/class/run.rb +61 -0
- data/lib/environment_information/class/show_display_and_report.rb +310 -0
- data/lib/environment_information/colours/colours.rb +150 -0
- data/lib/environment_information/colours/sfancy.rb +19 -0
- data/lib/environment_information/colours/simp.rb +19 -0
- data/lib/environment_information/constants/array_tracked_components.rb +207 -0
- data/lib/environment_information/constants/constants.rb +17 -0
- data/lib/environment_information/constants/encoding.rb +21 -0
- data/lib/environment_information/constants/error_line.rb +17 -0
- data/lib/environment_information/constants/file_constants.rb +102 -0
- data/lib/environment_information/constants/misc.rb +86 -0
- data/lib/environment_information/constants/namespace.rb +14 -0
- data/lib/environment_information/constants/newline.rb +16 -0
- data/lib/environment_information/constants/regex.rb +30 -0
- data/lib/environment_information/constants/temp_directory.rb +52 -0
- data/lib/environment_information/gui/gtk/bindings.rb +300 -0
- data/lib/environment_information/misc_components/README.md +3 -0
- data/lib/environment_information/misc_components/cflags.rb +36 -0
- data/lib/environment_information/misc_components/cpuinfo.rb +64 -0
- data/lib/environment_information/misc_components/operating_system.rb +54 -0
- data/lib/environment_information/misc_components/operating_system_bit_type.rb +42 -0
- data/lib/environment_information/misc_components/ram.rb +30 -0
- data/lib/environment_information/misc_components/rubygems_installation_directory.rb +54 -0
- data/lib/environment_information/misc_components/screen_resolution.rb +50 -0
- data/lib/environment_information/project/project.rb +27 -0
- data/lib/environment_information/queries/README.md +2 -0
- data/lib/environment_information/queries/complex_version.rb +263 -0
- data/lib/environment_information/queries/pkg_config.rb +125 -0
- data/lib/environment_information/queries/simple_version.rb +211 -0
- data/lib/environment_information/requires/require_asciitable.rb +15 -0
- data/lib/environment_information/requires/require_the_constants.rb +7 -0
- data/lib/environment_information/requires/require_the_environment_information_project.rb +23 -0
- data/lib/environment_information/requires/require_the_individual_misc_components.rb +30 -0
- data/lib/environment_information/requires/require_the_toplevel_methods.rb +22 -0
- data/lib/environment_information/toplevel_methods/autogenerate_all_relevant_methods.rb +152 -0
- data/lib/environment_information/toplevel_methods/cd.rb +16 -0
- data/lib/environment_information/toplevel_methods/e.rb +30 -0
- data/lib/environment_information/toplevel_methods/hash.rb +60 -0
- data/lib/environment_information/toplevel_methods/internet_is_available.rb +30 -0
- data/lib/environment_information/toplevel_methods/is_on_roebe.rb +16 -0
- data/lib/environment_information/toplevel_methods/menu.rb +90 -0
- data/lib/environment_information/toplevel_methods/misc.rb +264 -0
- data/lib/environment_information/toplevel_methods/n_subcommands.rb +31 -0
- data/lib/environment_information/toplevel_methods/prefix_to_use.rb +39 -0
- data/lib/environment_information/toplevel_methods/register_this_component_is_missing.rb +61 -0
- data/lib/environment_information/toplevel_methods/remote_url_of_this_program.rb +45 -0
- data/lib/environment_information/toplevel_methods/replay_from_the_stored_file.rb +84 -0
- data/lib/environment_information/toplevel_methods/return_pkgconfig_based_programs.rb +28 -0
- data/lib/environment_information/toplevel_methods/return_remote_gtk2_version.rb +54 -0
- data/lib/environment_information/toplevel_methods/return_simple_version_based_programs.rb +28 -0
- data/lib/environment_information/toplevel_methods/return_version_of_this_program.rb +186 -0
- data/lib/environment_information/toplevel_methods/show_all_available_components.rb +192 -0
- data/lib/environment_information/toplevel_methods/write_what_into.rb +24 -0
- data/lib/environment_information/version/version.rb +25 -0
- data/lib/environment_information/www/sinatra_interface.rb +213 -0
- data/lib/environment_information/www/webobject_interface.cgi +29 -0
- data/lib/environment_information/yaml/array_default_programs_on_linux.yml +14 -0
- data/lib/environment_information/yaml/array_lfs_core_programs.yml +35 -0
- data/lib/environment_information/yaml/array_science_cluster.yml +12 -0
- data/lib/environment_information/yaml/array_tracked_non_programs.yml +13 -0
- data/lib/environment_information/yaml/array_tracked_programs.yml +165 -0
- data/lib/environment_information/yaml/array_tracked_xorg_components.yml +34 -0
- data/lib/environment_information/yaml/query_to_use_for_the_individual_components.yml +215 -0
- data/lib/environment_information.rb +5 -0
- data/test/testing_environment_information.rb +26 -0
- data/test/testing_missing_components.rb +9 -0
- data/test/testing_prefix_for_the_environment_information_project.rb +20 -0
- metadata +195 -0
@@ -0,0 +1,300 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# === EnvironmentInformation::EnvironmentInformation::GUI::GtkEnvironmentInformation
|
6
|
+
# =========================================================================== #
|
7
|
+
# require 'environment_information/gui/gtk/bindings.rb'
|
8
|
+
# EnvironmentInformation::::EnvironmentInformation::GUI::GtkEnvironmentInformation.run
|
9
|
+
# EnvironmentInformation.run_gtk
|
10
|
+
# =========================================================================== #
|
11
|
+
module EnvironmentInformation
|
12
|
+
|
13
|
+
require 'environment_information/base/base.rb'
|
14
|
+
require 'environment_information/requires/require_the_environment_information_project.rb'
|
15
|
+
|
16
|
+
class EnvironmentInformation < ::EnvironmentInformation::Base # === EnvironmentInformation::EnvironmentInformation
|
17
|
+
|
18
|
+
begin # Pull in the gtk_paradise project next.
|
19
|
+
require 'gtk_paradise/requires/require_the_gtk_paradise_project.rb'
|
20
|
+
rescue LoadError; end
|
21
|
+
|
22
|
+
module GUI
|
23
|
+
|
24
|
+
class GtkEnvironmentInformation < ::Gtk::VBox
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'colours'
|
28
|
+
include Colours::E
|
29
|
+
rescue LoadError; end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'gtk_paradise/base_module/base_module.rb'
|
33
|
+
include ::Gtk::BaseModule
|
34
|
+
rescue LoadError; end
|
35
|
+
|
36
|
+
# ========================================================================= #
|
37
|
+
# === N
|
38
|
+
# ========================================================================= #
|
39
|
+
N = "\n"
|
40
|
+
|
41
|
+
# ========================================================================= #
|
42
|
+
# === Pick a default font
|
43
|
+
# ========================================================================= #
|
44
|
+
Gtk::Settings.default.gtk_font_name = 'Sans 20'
|
45
|
+
|
46
|
+
# ========================================================================= #
|
47
|
+
# === WIDTH
|
48
|
+
# ========================================================================= #
|
49
|
+
WIDTH = '1280'
|
50
|
+
|
51
|
+
# ========================================================================= #
|
52
|
+
# === HEIGHT
|
53
|
+
# ========================================================================= #
|
54
|
+
HEIGHT = '840'
|
55
|
+
|
56
|
+
# ========================================================================= #
|
57
|
+
# === EnvironmentInformation::EnvironmentInformation::GUI::GtkEnvironmentInformation.width
|
58
|
+
# ========================================================================= #
|
59
|
+
def self.width
|
60
|
+
WIDTH
|
61
|
+
end
|
62
|
+
|
63
|
+
# ========================================================================= #
|
64
|
+
# === EnvironmentInformation::EnvironmentInformation::GUI::GtkEnvironmentInformation.height
|
65
|
+
# ========================================================================= #
|
66
|
+
def self.height
|
67
|
+
HEIGHT
|
68
|
+
end
|
69
|
+
|
70
|
+
# ========================================================================= #
|
71
|
+
# === initialize
|
72
|
+
# ========================================================================= #
|
73
|
+
def initialize(
|
74
|
+
run_already = true
|
75
|
+
)
|
76
|
+
super()
|
77
|
+
reset
|
78
|
+
run if run_already
|
79
|
+
end
|
80
|
+
|
81
|
+
# ========================================================================= #
|
82
|
+
# === reset
|
83
|
+
# ========================================================================= #
|
84
|
+
def reset
|
85
|
+
# ======================================================================= #
|
86
|
+
# === @data
|
87
|
+
# ======================================================================= #
|
88
|
+
assign_the_environment_information_dataset_to_the_data_variable
|
89
|
+
# ======================================================================= #
|
90
|
+
# === @display_information_on_the_commandline
|
91
|
+
#
|
92
|
+
# If the next variable is set to true then information will be
|
93
|
+
# displayed on the commandline.
|
94
|
+
# ======================================================================= #
|
95
|
+
@display_information_on_the_commandline = true
|
96
|
+
# ======================================================================= #
|
97
|
+
# === @list_store
|
98
|
+
# ======================================================================= #
|
99
|
+
@list_store = Gtk::ListStore.new(String, String)
|
100
|
+
end
|
101
|
+
|
102
|
+
# ========================================================================= #
|
103
|
+
# === assign_the_environment_information_dataset_to_the_data_variable
|
104
|
+
# ========================================================================= #
|
105
|
+
def assign_the_environment_information_dataset_to_the_data_variable
|
106
|
+
@data = ::EnvironmentInformation.initialize_hash
|
107
|
+
end
|
108
|
+
|
109
|
+
# ========================================================================= #
|
110
|
+
# === create_gtk_tree_view
|
111
|
+
#
|
112
|
+
# The TreeView widget is the main widget which allows the user to
|
113
|
+
# display environment-related information about installed
|
114
|
+
# programs.
|
115
|
+
# ========================================================================= #
|
116
|
+
def create_gtk_tree_view
|
117
|
+
@tree_view = Gtk::TreeView.new(@list_store) # rf ruby gtk_TreeView
|
118
|
+
@tree_view.do_select_multiple # Allow multiple selections.
|
119
|
+
@tree_view.use_clickable_headers
|
120
|
+
@tree_view.enable_model_drag_source(
|
121
|
+
Gdk::Window::BUTTON1_MASK,
|
122
|
+
[ ['GTK_TREE_MODEL_ROW', 0, 0] ],
|
123
|
+
Gdk::DragContext::ACTION_COPY|Gdk::DragContext::ACTION_MOVE
|
124
|
+
)
|
125
|
+
@tree_view.enable_model_drag_dest([
|
126
|
+
['GTK_TREE_MODEL_ROW', 0, 0] ],
|
127
|
+
Gdk::DragContext::ACTION_COPY|Gdk::DragContext::ACTION_MOVE
|
128
|
+
)
|
129
|
+
@tree_view.signal_connect(:row_activated) {
|
130
|
+
# puts "hello"
|
131
|
+
}
|
132
|
+
# ========================================================================= #
|
133
|
+
# Respond to mouse-button press events. This is currently not in use
|
134
|
+
# really.
|
135
|
+
# ========================================================================= #
|
136
|
+
@tree_view.signal_connect(:button_press_event) { |widget, event|
|
137
|
+
if mouse_button_double_click?(event)
|
138
|
+
# e 'MouseButton: double click event.'
|
139
|
+
# ^^^ Currently we do not handle this event.
|
140
|
+
elsif left_mouse_button_clicked?(event)
|
141
|
+
# e 'MouseButton: left-click event (once).'
|
142
|
+
elsif right_mouse_button_clicked?(event)
|
143
|
+
e 'MouseButton: right-click event (once).'
|
144
|
+
end
|
145
|
+
}
|
146
|
+
@tree_view.selection.set_mode(Gtk::SelectionMode::MULTIPLE)
|
147
|
+
@tree_view.selection.signal_connect(:changed) {|entry|
|
148
|
+
entry.selected_each {|model, path, inner_array|
|
149
|
+
if @display_information_on_the_commandline
|
150
|
+
if inner_array[0]
|
151
|
+
name_of_the_program = inner_array[0].strip
|
152
|
+
else
|
153
|
+
name_of_the_program = '(unknown'
|
154
|
+
end
|
155
|
+
version_of_the_program = inner_array[1]
|
156
|
+
result = Colours.steelblue(
|
157
|
+
name_of_the_program.ljust(25)
|
158
|
+
).dup
|
159
|
+
if ::EnvironmentInformation.is_this_a_registered_program?(name_of_the_program)
|
160
|
+
result << 'Version: '
|
161
|
+
end
|
162
|
+
result << Colours.lightgreen(version_of_the_program.to_s)
|
163
|
+
e result
|
164
|
+
end
|
165
|
+
}
|
166
|
+
}
|
167
|
+
end
|
168
|
+
|
169
|
+
# ========================================================================= #
|
170
|
+
# === currently_selected
|
171
|
+
#
|
172
|
+
# Will show both key and version.
|
173
|
+
# ========================================================================= #
|
174
|
+
def currently_selected
|
175
|
+
(
|
176
|
+
@tree_view.selection.selected[0]+': '
|
177
|
+
).ljust(30)+
|
178
|
+
@tree_view.selection.selected[1]
|
179
|
+
end
|
180
|
+
|
181
|
+
# ========================================================================= #
|
182
|
+
# === create_toolbar
|
183
|
+
# ========================================================================= #
|
184
|
+
def create_toolbar
|
185
|
+
@toolbar = gtk_toolbar
|
186
|
+
@toolbar.append_space
|
187
|
+
# ======================================================================= #
|
188
|
+
# Add the refresh-button next.
|
189
|
+
# ======================================================================= #
|
190
|
+
button_refresh = gtk_button(:refresh)
|
191
|
+
button_refresh.no_relief
|
192
|
+
button_refresh.signal_connect(:clicked) {
|
193
|
+
do_update_the_main_content_of_the_widget
|
194
|
+
}
|
195
|
+
button_refresh.fancy_tooltips = 'Click this button in order to '\
|
196
|
+
'refresh the information shown below.'
|
197
|
+
@toolbar << button_refresh
|
198
|
+
end
|
199
|
+
|
200
|
+
# ========================================================================= #
|
201
|
+
# === do_update_the_main_content_of_the_widget
|
202
|
+
# ========================================================================= #
|
203
|
+
def do_update_the_main_content_of_the_widget
|
204
|
+
assign_the_environment_information_dataset_to_the_data_variable
|
205
|
+
@list_store.clear
|
206
|
+
@data.each {|line|
|
207
|
+
name, version = *line # Decompose line.
|
208
|
+
iter = @list_store.append
|
209
|
+
if version.nil? or version.to_s.empty?
|
210
|
+
version = '[Not installed.]'
|
211
|
+
end
|
212
|
+
iter.set_value(0, name)
|
213
|
+
iter.set_value(1, version)
|
214
|
+
}
|
215
|
+
end
|
216
|
+
|
217
|
+
# ========================================================================= #
|
218
|
+
# === add_status_icon
|
219
|
+
# ========================================================================= #
|
220
|
+
def add_status_icon
|
221
|
+
_ = gtk_status_icon(:dialog_info)
|
222
|
+
# ======================================================================= #
|
223
|
+
# Add a menu and a quit-button too.
|
224
|
+
# ======================================================================= #
|
225
|
+
menu = ::Gtk::Menu.new
|
226
|
+
quit = ::Gtk::ImageMenuItem.new(::Gtk::Stock::QUIT)
|
227
|
+
quit.signal_connect(:activate) { ::Gtk.main_quit }
|
228
|
+
menu.append(quit)
|
229
|
+
menu.show_all
|
230
|
+
_.signal_connect(:popup_menu) { |icon, button, time|
|
231
|
+
menu.popup(nil, nil, button, time)
|
232
|
+
}
|
233
|
+
end
|
234
|
+
|
235
|
+
# ========================================================================= #
|
236
|
+
# === run
|
237
|
+
# ========================================================================= #
|
238
|
+
def run
|
239
|
+
create_toolbar
|
240
|
+
create_gtk_tree_view
|
241
|
+
@renderer = gtk_cell_renderer_text
|
242
|
+
# ======================================================================= #
|
243
|
+
# Append the information contained in our @data variable to the
|
244
|
+
# ListStore object next. This will yield an Array.
|
245
|
+
# ======================================================================= #
|
246
|
+
do_update_the_main_content_of_the_widget
|
247
|
+
@tree_view.insert_column(-1, 'Name', @renderer, text: 0)
|
248
|
+
@tree_view.insert_column(-1, 'Version', @renderer, text: 1)
|
249
|
+
@tree_view.signal_connect(:key_press_event) { |w, event|
|
250
|
+
case Gdk::Keyval.to_name(event.keyval)
|
251
|
+
when 'Return','KP_Enter'
|
252
|
+
e currently_selected
|
253
|
+
end
|
254
|
+
}
|
255
|
+
File.delete('gmon.out') if File.exist? 'gmon.out' # Don't keep gmon.out
|
256
|
+
vbox = gtk_vbox
|
257
|
+
vbox.pack_start(@toolbar, false, false, 5)
|
258
|
+
@scrolled_window = gtk_scrolled_window(@tree_view)
|
259
|
+
vbox.pack_start(@scrolled_window, true, true,0)
|
260
|
+
add(vbox)
|
261
|
+
add_status_icon
|
262
|
+
show_all
|
263
|
+
end
|
264
|
+
|
265
|
+
end; end; end
|
266
|
+
|
267
|
+
# ========================================================================= #
|
268
|
+
# === EnvironmentInformation.gtk_bindings
|
269
|
+
# ========================================================================= #
|
270
|
+
def self.gtk_bindings
|
271
|
+
::EnvironmentInformation::EnvironmentInformation::GUI::GtkEnvironmentInformation.new
|
272
|
+
end
|
273
|
+
|
274
|
+
# ========================================================================= #
|
275
|
+
# === EnvironmentInformation.run_gtk
|
276
|
+
#
|
277
|
+
# Use this method if you wish to run the gtk-component of the
|
278
|
+
# EnvironmentInformation project.
|
279
|
+
# ========================================================================= #
|
280
|
+
def self.run_gtk
|
281
|
+
x = ::EnvironmentInformation.gtk_bindings
|
282
|
+
r = Gtk.run(
|
283
|
+
::EnvironmentInformation::EnvironmentInformation::GUI::GtkEnvironmentInformation.width,
|
284
|
+
::EnvironmentInformation::EnvironmentInformation::GUI::GtkEnvironmentInformation.height,
|
285
|
+
:tabble,
|
286
|
+
'Environment Information',2
|
287
|
+
)
|
288
|
+
r << x # ← Add the widget here.
|
289
|
+
r.add_shortcut(1, 'focus(:left)', :alt)
|
290
|
+
r.modify_bg(
|
291
|
+
Gtk::STATE_NORMAL, Gdk::Color.parse('grey')
|
292
|
+
)
|
293
|
+
r.top_left_then_run
|
294
|
+
end
|
295
|
+
|
296
|
+
end
|
297
|
+
|
298
|
+
if __FILE__ == $PROGRAM_NAME
|
299
|
+
EnvironmentInformation.run_gtk
|
300
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'environment_information/misc_components/cflags.rb'
|
6
|
+
# EnvironmentInformation.cflags_in_use?
|
7
|
+
# =========================================================================== #
|
8
|
+
module EnvironmentInformation
|
9
|
+
|
10
|
+
# ========================================================================= #
|
11
|
+
# === EnvironmentInformation.cflags? (cflags tag)
|
12
|
+
#
|
13
|
+
# The following is equivalent to the value stored in the variable
|
14
|
+
# $CFLAGS, which on unix-like systems may be obtained by issuing
|
15
|
+
# the following command:
|
16
|
+
#
|
17
|
+
# echo $CFLAGS
|
18
|
+
#
|
19
|
+
# The output may be like this:
|
20
|
+
#
|
21
|
+
# -O2 -fPIC -fno-strict-overflow -Wno-error
|
22
|
+
#
|
23
|
+
# ========================================================================= #
|
24
|
+
def self.cflags?
|
25
|
+
version = ENV['CFLAGS'].to_s.strip
|
26
|
+
version = '<none>' if version.empty? # Display special status if it is empty.
|
27
|
+
version
|
28
|
+
end; self.instance_eval { alias cflags_in_use? cflags? } # === EnvironmentInformation.cflags_in_use?
|
29
|
+
self.instance_eval { alias return_version_of_cflags cflags? } # === EnvironmentInformation.return_version_of_cflags
|
30
|
+
self.instance_eval { alias cflags cflags? } # === EnvironmentInformation.cflags
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
if __FILE__ == $PROGRAM_NAME
|
35
|
+
puts EnvironmentInformation.cflags?
|
36
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'environment_information/misc_components/cpuinfo.rb'
|
6
|
+
# EnvironmentInformation.cpuinfo?
|
7
|
+
# =========================================================================== #
|
8
|
+
module EnvironmentInformation
|
9
|
+
|
10
|
+
require 'environment_information/constants/newline.rb'
|
11
|
+
require 'environment_information/constants/error_line.rb'
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === EnvironmentInformation.cpuinfo? (cpuinfo tag)
|
15
|
+
#
|
16
|
+
# This method currently relies on /proc/cpuinfo, thus favouring
|
17
|
+
# Linux-based systems.
|
18
|
+
#
|
19
|
+
# The output will be similar to this:
|
20
|
+
#
|
21
|
+
# AMD A8-7600 Radeon R7, 10 Compute Cores 4C+6G, 4 cores
|
22
|
+
#
|
23
|
+
# It will become the display part of "CPU Model".
|
24
|
+
# ========================================================================= #
|
25
|
+
def self.cpuinfo?
|
26
|
+
result = '/proc/cpuinfo'
|
27
|
+
if File.exist? result
|
28
|
+
readlines = File.readlines(result)
|
29
|
+
_ = readlines.grep(/model name/).first.chomp
|
30
|
+
splitted = _.split(':')
|
31
|
+
_ = splitted[1].strip # => "model name\t: AMD Sempron(tm) 145 Processor"
|
32
|
+
# ===================================================================== #
|
33
|
+
# Next, add the amount of cores. We use "nproc" for this but "lscpu"
|
34
|
+
# also contains this information. The following regex could be used
|
35
|
+
# for lscpu:
|
36
|
+
#
|
37
|
+
# Core\(s\) per socket: (.+)
|
38
|
+
#
|
39
|
+
# Ok, we use lscpu for now.
|
40
|
+
# ===================================================================== #
|
41
|
+
n_cores = `nproc --all`.strip
|
42
|
+
case n_cores.to_s
|
43
|
+
when '1'
|
44
|
+
n_cores << ' core' # Singular.
|
45
|
+
else
|
46
|
+
n_cores << ' cores' # Plural then.
|
47
|
+
end
|
48
|
+
_ << ", #{n_cores}" unless n_cores.empty?
|
49
|
+
result = _
|
50
|
+
else
|
51
|
+
result = nil
|
52
|
+
end
|
53
|
+
result
|
54
|
+
end; self.instance_eval { alias append_operating_system_cpuinfo cpuinfo? } # === EnvironmentInformation.append_operating_system_cpuinfo
|
55
|
+
self.instance_eval { alias cpu_model cpuinfo? } # === EnvironmentInformation.cpu_model
|
56
|
+
self.instance_eval { alias cpu_model? cpuinfo? } # === EnvironmentInformation.cpu_model?
|
57
|
+
self.instance_eval { alias return_version_of_cpuinfo cpuinfo? } # === EnvironmentInformation.return_version_of_cpuinfo
|
58
|
+
self.instance_eval { alias cpuinfo cpuinfo? } # === EnvironmentInformation.cpuinfo
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
if __FILE__ == $PROGRAM_NAME
|
63
|
+
puts EnvironmentInformation.cpuinfo?
|
64
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'environment_information/misc_components/operating_system.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module EnvironmentInformation
|
8
|
+
|
9
|
+
require 'environment_information/constants/newline.rb'
|
10
|
+
require 'environment_information/constants/error_line.rb'
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === EnvironmentInformation.operating_system (os tag)
|
14
|
+
#
|
15
|
+
# This method is also known as "bit type".
|
16
|
+
#
|
17
|
+
# The return value of this method may be a String such as this one here:
|
18
|
+
#
|
19
|
+
# "GNU/Linux"
|
20
|
+
#
|
21
|
+
# This is then further modified a bit to drop the "GNU/" part
|
22
|
+
# specifically.
|
23
|
+
#
|
24
|
+
# ========================================================================= #
|
25
|
+
def self.operating_system
|
26
|
+
cmd = 'uname -mo'
|
27
|
+
result = `#{cmd}`.chomp
|
28
|
+
if result.start_with? 'GNU'
|
29
|
+
# ===================================================================== #
|
30
|
+
# The next part removes 'GNU/' specifically. It is a simpler name
|
31
|
+
# than "GNU Linux" and variants, just as "BSD" is simpler than
|
32
|
+
# e. g. "FreeBSD". You can reason that it may be "less accurate",
|
33
|
+
# but it makes the notification-part of this gem simpler.
|
34
|
+
# ===================================================================== #
|
35
|
+
result.sub!(/^GNU\//,'') # Experimental as of Sep 2019.
|
36
|
+
end
|
37
|
+
if result.include? ' '
|
38
|
+
result = result.split(' ').last
|
39
|
+
end
|
40
|
+
result
|
41
|
+
end; self.instance_eval { alias operating_system? operating_system } # === EnvironmentInformation.operating_system?
|
42
|
+
self.instance_eval { alias operating_system_information? operating_system } # === EnvironmentInformation.operating_system_information
|
43
|
+
self.instance_eval { alias add_operating_system_information operating_system } # === EnvironmentInformation.add_operating_system_information
|
44
|
+
self.instance_eval { alias append_operating_system_in_use operating_system } # === EnvironmentInformation.append_operating_system_in_use
|
45
|
+
self.instance_eval { alias add_os_information operating_system } # === EnvironmentInformation.add_os_information
|
46
|
+
self.instance_eval { alias operating_system_in_use? operating_system } # === EnvironmentInformation.operating_system_in_use?
|
47
|
+
self.instance_eval { alias return_version_of_operating_system operating_system } # === EnvironmentInformation.return_version_of_operating_system
|
48
|
+
self.instance_eval { alias return_version_of_operating_system_in_use operating_system } # === EnvironmentInformation.return_version_of_operating_system_in_use
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
if __FILE__ == $PROGRAM_NAME
|
53
|
+
puts EnvironmentInformation.operating_system
|
54
|
+
end # envi_operating_system
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'environment_information/misc_components/operating_system.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module EnvironmentInformation
|
8
|
+
|
9
|
+
require 'environment_information/constants/newline.rb'
|
10
|
+
require 'environment_information/constants/error_line.rb'
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === EnvironmentInformation.operating_system_bit_type_information (bit tag, bit type tag)
|
14
|
+
#
|
15
|
+
# This method will return the bit type in use, as a String,
|
16
|
+
# such as "x86_64" or "x86_64 (64 bit)" specifically. The
|
17
|
+
# reason why this method appends ' (64 bit)' is mostly so
|
18
|
+
# that the user can quickly see whether a computer is on
|
19
|
+
# 32 bit or on 64 bit.
|
20
|
+
# ========================================================================= #
|
21
|
+
def self.operating_system_bit_type_information
|
22
|
+
cmd = 'uname -m'
|
23
|
+
result = `#{cmd}`.chomp
|
24
|
+
result = result.split(' ')[-1] if result.include?(' ')
|
25
|
+
result = result.dup if result.frozen?
|
26
|
+
case result
|
27
|
+
when 'x86_64'
|
28
|
+
result << ' (64 bit)'
|
29
|
+
end
|
30
|
+
result
|
31
|
+
end; self.instance_eval { alias add_bit_type_information operating_system_bit_type_information } # === EnvironmentInformation.add_bit_type_information
|
32
|
+
self.instance_eval { alias add_operating_system_bit_type operating_system_bit_type_information } # === EnvironmentInformation.add_operating_system_bit_type
|
33
|
+
self.instance_eval { alias bit_type? operating_system_bit_type_information } # === EnvironmentInformation.bit_type?
|
34
|
+
self.instance_eval { alias return_version_of_operating_system_bit_type operating_system_bit_type_information } # === EnvironmentInformation.return_version_of_operating_system_bit_type
|
35
|
+
self.instance_eval { alias operating_system_bit_type? operating_system_bit_type_information } # === EnvironmentInformation.operating_system_bit_type?
|
36
|
+
self.instance_eval { alias operating_system_bit_type operating_system_bit_type_information } # === EnvironmentInformation.operating_system_bit_type
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
if __FILE__ == $PROGRAM_NAME
|
41
|
+
puts EnvironmentInformation.operating_system_bit_type_information
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'environment_information/misc_components/ram.rb'
|
6
|
+
# ::EnvironmentInformation.ram?
|
7
|
+
# =========================================================================== #
|
8
|
+
module EnvironmentInformation
|
9
|
+
|
10
|
+
# ========================================================================= #
|
11
|
+
# === EnvironmentInformation.ram? (ram tag)
|
12
|
+
#
|
13
|
+
# This method will determine how much RAM the given computer host has.
|
14
|
+
#
|
15
|
+
# The result will be given in n MB.
|
16
|
+
# ========================================================================= #
|
17
|
+
def self.ram?
|
18
|
+
result_in_n_mb = `free -m 2>&1`.split("\n")[1]
|
19
|
+
if result_in_n_mb and result_in_n_mb.include?(' ')
|
20
|
+
result_in_n_mb = result_in_n_mb.split(' ')[1]
|
21
|
+
end
|
22
|
+
result_in_n_mb
|
23
|
+
end; self.instance_eval { alias return_version_of_ram ram? } # === EnvironmentInformation.return_version_of_ram
|
24
|
+
self.instance_eval { alias ram ram? } # === EnvironmentInformation.ram
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
if __FILE__ == $PROGRAM_NAME
|
29
|
+
puts EnvironmentInformation.ram?
|
30
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'environment_information/misc_components/rubygems_installation_directory.rb'
|
6
|
+
# EnvironmentInformation.rubygems_installation_directory?
|
7
|
+
# =========================================================================== #
|
8
|
+
module EnvironmentInformation
|
9
|
+
|
10
|
+
require 'environment_information/constants/newline.rb'
|
11
|
+
require 'environment_information/constants/error_line.rb'
|
12
|
+
require 'environment_information/toplevel_methods/prefix_to_use.rb'
|
13
|
+
|
14
|
+
# ========================================================================= #
|
15
|
+
# === EnvironmentInformation.rubygems_installation_directory
|
16
|
+
#
|
17
|
+
# This method will return the path to the rubygems installation
|
18
|
+
# directory, if possible (if it exists).
|
19
|
+
#
|
20
|
+
# As this ought to be a directory, we will ensure that a trailing '/'
|
21
|
+
# character exists.
|
22
|
+
#
|
23
|
+
# This method may return a String such as "/root/.gem/".
|
24
|
+
# ========================================================================= #
|
25
|
+
def self.rubygems_installation_directory(
|
26
|
+
prefix_to_use = @prefix_to_use
|
27
|
+
)
|
28
|
+
result = `#{prefix_to_use}gem env #{ERROR_LINE}` # We need the 2>&1 to check if gem is available.
|
29
|
+
unless result.include? 'not found'
|
30
|
+
# ===================================================================== #
|
31
|
+
# Apply a regex next.
|
32
|
+
# ===================================================================== #
|
33
|
+
path_to_the_rubygem_directory = result.to_s.scan(
|
34
|
+
/INSTALLATION DIRECTORY: (.+)/ # Obtain the proper match here.
|
35
|
+
).flatten.first.to_s
|
36
|
+
if File.directory? path_to_the_rubygem_directory
|
37
|
+
path_to_the_rubygem_directory << '/'
|
38
|
+
end unless path_to_the_rubygem_directory.end_with? '/'
|
39
|
+
result = path_to_the_rubygem_directory
|
40
|
+
else
|
41
|
+
result = nil
|
42
|
+
end
|
43
|
+
result
|
44
|
+
end; self.instance_eval { alias add_rubygems_installation_directory_information rubygems_installation_directory } # === EnvironmentInformation.add_rubygems_installation_directory_information
|
45
|
+
self.instance_eval { alias add_rubygem_directory_information rubygems_installation_directory } # === EnvironmentInformation.add_rubygem_directory_information
|
46
|
+
self.instance_eval { alias append_rubygem_installation_directory rubygems_installation_directory } # === EnvironmentInformation.append_rubygem_installation_directory
|
47
|
+
self.instance_eval { alias return_version_of_rubygems_installation_directory rubygems_installation_directory } # === EnvironmentInformation.return_version_of_rubygems_installation_directory
|
48
|
+
self.instance_eval { alias rubygems_installation_directory? rubygems_installation_directory } # === EnvironmentInformation.rubygems_installation_directory?
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
if __FILE__ == $PROGRAM_NAME
|
53
|
+
puts EnvironmentInformation.rubygems_installation_directory
|
54
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'environment_information/misc_components/screen_resolution.rb'
|
6
|
+
# EnvironmentInformation.screen_resolution?
|
7
|
+
# =========================================================================== #
|
8
|
+
module EnvironmentInformation
|
9
|
+
|
10
|
+
require 'environment_information/constants/newline.rb'
|
11
|
+
require 'environment_information/constants/error_line.rb'
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === EnvironmentInformation.screen_resolution (screen tag)
|
15
|
+
#
|
16
|
+
# This method will typically make use of xdpyinfo first, as it also
|
17
|
+
# works in a .cgi environment. For non-cgi environments, on linux,
|
18
|
+
# we could use xrandr, which is a bit more elegant.
|
19
|
+
#
|
20
|
+
# On success, the method here will return a String such as "1920x1080".
|
21
|
+
# ========================================================================= #
|
22
|
+
def self.screen_resolution
|
23
|
+
result = '(unknown)' # This is the default return-value, then.
|
24
|
+
# ======================================================================= #
|
25
|
+
# === Check for linux as host OS first
|
26
|
+
# ======================================================================= #
|
27
|
+
if RUBY_PLATFORM.downcase.include? 'linux'
|
28
|
+
# ================================================================= #
|
29
|
+
# We have to be careful as xdpyinfo may not be installed on the
|
30
|
+
# given computer system.
|
31
|
+
# ================================================================= #
|
32
|
+
resolution = `xdpyinfo #{ERROR_LINE}`.scan(/dimensions:.+$/).first # The error here may be: "xdpyinfo: unable to open display"
|
33
|
+
if resolution and resolution.include? ':'
|
34
|
+
result = resolution.split(':').last.strip.split('pixels').first.strip
|
35
|
+
end
|
36
|
+
# ======================================================================= #
|
37
|
+
# === Else simply assume to be on windows here
|
38
|
+
# ======================================================================= #
|
39
|
+
else
|
40
|
+
result = `wmic desktopmonitor get screenheight,screenwidth`
|
41
|
+
end
|
42
|
+
result
|
43
|
+
end; self.instance_eval { alias screen_resolution? screen_resolution } # === EnvironmentInformation.screen_resolution?
|
44
|
+
self.instance_eval { alias return_version_of_screen_resolution screen_resolution } # === EnvironmentInformation.return_version_of_screen_resolution
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
if __FILE__ == $PROGRAM_NAME
|
49
|
+
puts EnvironmentInformation.screen_resolution
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'environment_information/project/project.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module EnvironmentInformation
|
8
|
+
|
9
|
+
# ========================================================================= #
|
10
|
+
# === EnvironmentInformation::PROJECT_BASE_DIRECTORY
|
11
|
+
#
|
12
|
+
# This constant may point to a target such as:
|
13
|
+
#
|
14
|
+
# /home/Programs/Ruby/2.7.1/lib/ruby/site_ruby/2.7.0/environment_information/
|
15
|
+
#
|
16
|
+
# ========================================================================= #
|
17
|
+
PROJECT_BASE_DIRECTORY =
|
18
|
+
File.absolute_path("#{__dir__}/..")+'/'
|
19
|
+
|
20
|
+
# ========================================================================= #
|
21
|
+
# === EnvironmentInformation.project_base_directory?
|
22
|
+
# ========================================================================= #
|
23
|
+
def self.project_base_directory?
|
24
|
+
PROJECT_BASE_DIRECTORY
|
25
|
+
end; self.instance_eval { alias project_base_dir? project_base_directory? } # === EnvironmentInformation.project_base_dir?
|
26
|
+
|
27
|
+
end
|