program_information 1.1.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of program_information might be problematic. Click here for more details.

@@ -0,0 +1,22 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'program_information/project/project_base_directory.rb'
6
+ # =========================================================================== #
7
+ module ProgramInformation
8
+
9
+ # ========================================================================= #
10
+ # === ProgramInformation::PROJECT_BASE_DIRECTORY
11
+ # ========================================================================= #
12
+ PROJECT_BASE_DIRECTORY =
13
+ "#{RbConfig::CONFIG['sitelibdir']}/program_information/"
14
+
15
+ # ========================================================================= #
16
+ # === ProgramInformation.project_base_dir?
17
+ # ========================================================================= #
18
+ def self.project_base_dir?
19
+ PROJECT_BASE_DIRECTORY
20
+ end
21
+
22
+ end
@@ -0,0 +1,48 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ module ProgramInformation
6
+
7
+ class ProgramInformation
8
+
9
+ # ========================================================================= #
10
+ # === report (debug tag, report tag)
11
+ # ========================================================================= #
12
+ def report(
13
+ be_verbose = be_verbose?
14
+ )
15
+ case be_verbose
16
+ when :do_report, :be_verbose
17
+ be_verbose = true
18
+ end
19
+ lpad = 90
20
+ rpad = 49
21
+ if be_verbose
22
+ inner_ljust = 28
23
+ # ===================================================================== #
24
+ # === real short name
25
+ # ===================================================================== #
26
+ e (NAME_OF_CLASS+(' Program real short name ').ljust(inner_ljust)+'('+
27
+ yellow?+'@real_short_name'+rev+') is: ').ljust(lpad)+
28
+ (apostroph?+real_short_name?+apostroph?).
29
+ ljust(rpad)
30
+ # ===================================================================== #
31
+ # === short name
32
+ # ===================================================================== #
33
+ e (
34
+ NAME_OF_CLASS+(' Program name').ljust(inner_ljust)+'('+
35
+ yellow?+'@short_name'+rev+' ) is: '
36
+ ).ljust(lpad)+(apostroph?+short_name?+apostroph?).
37
+ ljust(rpad)
38
+ # ===================================================================== #
39
+ # === program version
40
+ # ===================================================================== #
41
+ e (NAME_OF_CLASS+(' Program version ').ljust(inner_ljust)+'('+
42
+ yellow?+'@program_version'+rev+') is: ').ljust(lpad)+
43
+ (apostroph?+version?+apostroph?).
44
+ ljust(rpad)
45
+ end
46
+ end; alias report_result report # === report_result
47
+
48
+ end; end
@@ -0,0 +1,46 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'program_information/reset.rb'
6
+ # =========================================================================== #
7
+ module ProgramInformation
8
+
9
+ class ProgramInformation # === ProgramInformation::ProgramInformation
10
+
11
+ # ========================================================================= #
12
+ # === reset
13
+ # ========================================================================= #
14
+ def reset
15
+ # ======================================================================= #
16
+ # === @short_name
17
+ # ======================================================================= #
18
+ @short_name = nil
19
+ # ======================================================================= #
20
+ # === @real_short_name
21
+ # ======================================================================= #
22
+ @real_short_name = nil
23
+ # ======================================================================= #
24
+ # === @program_version
25
+ # ======================================================================= #
26
+ @program_version = nil
27
+ set_shall_we_downcase # Should become before set_input().
28
+ set_be_verbose
29
+ # ======================================================================= #
30
+ # === @remove_plus_and_minus
31
+ # ======================================================================= #
32
+ @remove_plus_and_minus = REMOVE_PLUS_AND_MINUS
33
+ # ======================================================================= #
34
+ # === @replace_plus_with_long_name
35
+ # ======================================================================= #
36
+ @replace_plus_with_long_name = REPLACE_PLUS_WITH_LONG_NAME
37
+ @remove_plus_token = REMOVE_PLUS_TOKEN
38
+ if @remove_plus_and_minus # Overrule always in this case.
39
+ @replace_plus_with_long_name = false
40
+ end
41
+ if @remove_plus_and_minus
42
+ @remove_plus_token = false
43
+ end
44
+ end
45
+
46
+ end; end
@@ -0,0 +1,18 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'program_information/run.rb'
6
+ # =========================================================================== #
7
+ module ProgramInformation
8
+
9
+ class ProgramInformation
10
+
11
+ # ========================================================================= #
12
+ # === run
13
+ # ========================================================================= #
14
+ def run
15
+ determine_the_three_main_variables
16
+ end
17
+
18
+ end; end
@@ -0,0 +1,159 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'program_information/toplevel_methods.rb'
6
+ # =========================================================================== #
7
+ require 'program_information/toplevel_methods/opnn.rb'
8
+ require 'program_information/toplevel_methods/e.rb'
9
+ require 'program_information/toplevel_methods/return_short_name.rb'
10
+ require 'program_information/program_information.rb'
11
+
12
+ module ProgramInformation
13
+
14
+ # ========================================================================= #
15
+ # === ProgramInformation.return_program_version
16
+ #
17
+ # This module-method will return the program version of a given input.
18
+ #
19
+ # For example, if the input to this method is
20
+ # 'gobject-introspection-1.52.1.tar.xz', then this method will
21
+ # return the String '1.52.1'.
22
+ #
23
+ # We must also handle the case when the version passed to us is incomplete
24
+ # or wrong, such as "2.1.0-source". In that case, the proper program
25
+ # version would be 2.1.0.
26
+ #
27
+ # Usage examples, using the shorter variant instead:
28
+ #
29
+ # ProgramInformation.return_version('/opt/ffmpeg-2.3.tar.xz') # => "2.3"
30
+ # ProgramInformation.return_version 'ophcrack-3.6.0' # => "3.6.0"
31
+ # ProgramInformation.return_version 'gobject-introspection-1.52.1.tar.xz' # => "1.52.1"
32
+ #
33
+ # ========================================================================= #
34
+ def self.return_program_version(of_this_program = '')
35
+ if of_this_program.nil? or of_this_program.empty?
36
+ opnn; e 'Please provide some input to the method '\
37
+ 'ProgramInformation.return_program_version.'
38
+ else
39
+ _ = ::ProgramInformation::ProgramInformation.new(of_this_program)
40
+ _.program_version?
41
+ end
42
+ end; self.instance_eval { alias return_version return_program_version } # === ProgramInformation.return_version
43
+ self.instance_eval { alias return_version_of return_program_version } # === ProgramInformation.return_version_of
44
+
45
+ # ========================================================================= #
46
+ # === ProgramInformation.return_real_short_name
47
+ #
48
+ # This method will return the real short name.
49
+ #
50
+ # Usage example:
51
+ #
52
+ # ProgramInformation.return_real_short_name('iso-codes-3.50.tar.xz')
53
+ #
54
+ # The above would return "isocodes".
55
+ # ========================================================================= #
56
+ def self.return_real_short_name(of_this_program = '')
57
+ if of_this_program.nil? or of_this_program.empty?
58
+ opnn; e 'Please provide some input to the method '\
59
+ 'ProgramInformation.return_real_short_name.'
60
+ else
61
+ _ = ::ProgramInformation::ProgramInformation.new(of_this_program)
62
+ _.real_short_name?
63
+ end
64
+ end; self.instance_eval { alias real_short_name return_real_short_name } # === ProgramInformation.real_short_name
65
+ self.instance_eval { alias return_real_name return_real_short_name } # === ProgramInformation.return_real_name
66
+ self.instance_eval { alias return_program_name return_real_short_name } # === ProgramInformation.return_program_name
67
+ self.instance_eval { alias program_name? return_real_short_name } # === ProgramInformation.program_name?
68
+
69
+ # ========================================================================= #
70
+ # === ProgramInformation.return_short_name_and_program_version
71
+ #
72
+ # This will return an Array with two entries - the short name,
73
+ # and the program version.
74
+ # ========================================================================= #
75
+ def self.return_short_name_and_program_version(
76
+ i,
77
+ replace_input = true
78
+ )
79
+ case replace_input
80
+ when :do_not_modify_input
81
+ replace_input = false
82
+ end
83
+ _ = ::ProgramInformation::ProgramInformation.new(i, :dont_run_yet)
84
+ _.do_not_replace_anything unless replace_input
85
+ _.run
86
+ # ======================================================================= #
87
+ # Assemble the Array here.
88
+ # ======================================================================= #
89
+ array = [ _.short_name?, _.program_version? ]
90
+ return array
91
+ end; self.instance_eval { alias return_short_name_and_version return_short_name_and_program_version } # === ProgramInformation.return_short_name_and__version
92
+
93
+ # ========================================================================= #
94
+ # === ProgramInformation.return_array_name_and_version
95
+ #
96
+ # This will return the short_name and the version, as Array.
97
+ #
98
+ # Usage example:
99
+ #
100
+ # ProgramInformation::ProgramInformation.return_array_name_and_version(
101
+ # "font-sony-misc-1.0.3") => ["font-sony-misc", "1.0.3"]
102
+ #
103
+ # ========================================================================= #
104
+ def self.return_array_name_and_version(i)
105
+ array = [
106
+ ::ProgramInformation.return_short_name(i),
107
+ ::ProgramInformation.return_program_version(i)
108
+ ]
109
+ return array
110
+ end; self.instance_eval { alias return_array_program_name_and_program_version return_array_name_and_version } # === ProgramInformation.return_array_program_name_and_program_version
111
+
112
+ # ========================================================================= #
113
+ # === ProgramInformation.return_real_short_name_and_version
114
+ #
115
+ # This method will return two results, in Array form:
116
+ #
117
+ # The @real_short_name and
118
+ # the @program_version
119
+ #
120
+ # The optional second argument can be used to downcase the program
121
+ # name that is returned.
122
+ # ========================================================================= #
123
+ def self.return_real_short_name_and_version(
124
+ i, optional_downcase = false
125
+ )
126
+ case optional_downcase
127
+ when :downcase
128
+ optional_downcase = true
129
+ end
130
+ real_short_name = ::ProgramInformation.return_real_short_name(i)
131
+ if optional_downcase
132
+ real_short_name.downcase!
133
+ end
134
+ program_version = ::ProgramInformation.return_program_version(i)
135
+ return [
136
+ real_short_name, program_version
137
+ ]
138
+ end; self.instance_eval { alias return_real_name_and_version return_real_short_name_and_version } # === ProgramInformation.return_real_name_and_version
139
+ self.instance_eval { alias return_real_short_name_and_program_version return_real_short_name_and_version } # === ProgramInformation.return_real_short_name_and_program_version
140
+ self.instance_eval { alias return_name_and_version return_real_short_name_and_version } # === ProgramInformation.return_name_and_version
141
+ self.instance_eval { alias return_name_and_version_of return_real_short_name_and_version } # === ProgramInformation.return_name_and_version_of
142
+
143
+ end
144
+
145
+ if __FILE__ == $PROGRAM_NAME
146
+ # ========================================================================= #
147
+ # Some testing code follows next:
148
+ # ========================================================================= #
149
+ if ARGV.empty?
150
+ _ = 'gobject-introspection-1.52.1.tar.xz'
151
+ p ProgramInformation.return_program_version(_)
152
+ p ProgramInformation.return_short_name(_)
153
+ p ProgramInformation.return_real_short_name(_)
154
+ else
155
+ p ProgramInformation.return_program_version(ARGV.first)
156
+ p ProgramInformation.return_short_name(ARGV.first)
157
+ p ProgramInformation.return_real_short_name(ARGV.first)
158
+ end
159
+ end # rb toplevel_methods.rb /Users/x/SRC/gobjectintrospection/gobject-introspection-1.52.1.tar.xz
@@ -0,0 +1,14 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ module ProgramInformation
6
+
7
+ # ========================================================================= #
8
+ # === ProgramInformation.e
9
+ # ========================================================================= #
10
+ def self.e(i = '')
11
+ puts i
12
+ end
13
+
14
+ end
@@ -0,0 +1,27 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'program_information/toplevel_methods/opnn.rb'
6
+ # =========================================================================== #
7
+ require 'program_information/toplevel_methods/e.rb'
8
+
9
+ module ProgramInformation
10
+
11
+ begin
12
+ require 'opn'
13
+ rescue LoadError; end
14
+
15
+ # ========================================================================= #
16
+ # === ProgramInformation.e
17
+ # ========================================================================= #
18
+ def self.opnn(
19
+ i = 'ProgramInformation'
20
+ )
21
+ if i.is_a? String
22
+ i = { namespace: i }
23
+ end
24
+ Opn.opn(i) if Object.const_defined? :Opn
25
+ end
26
+
27
+ end
@@ -0,0 +1,32 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'program_information/toplevel_methods/remove_archive_type.rb'
6
+ # =========================================================================== #
7
+ module ProgramInformation
8
+
9
+ # ========================================================================= #
10
+ # === ProgramInformation.remove_archive_type
11
+ #
12
+ # This method will remove the "archive type", e. g. ".tar.xz" or
13
+ # ".tar.bz2" or ".tar.lz".
14
+ # ========================================================================= #
15
+ def self.remove_archive_type(i)
16
+ i = i.dup if i.frozen?
17
+ i.sub!(/\.tar\.gz$/,'')
18
+ i.sub!(/\.tar\.xz$/,'')
19
+ i.sub!(/\.tar\.bz2$/,'')
20
+ i.sub!(/\.run$/,'') if i.end_with? '.run'
21
+ i.sub!(/\.bz2$/,'') if i.end_with? '.bz2'
22
+ i.sub!(/\.tar\.lz$/,'') if i.end_with? '.tar.lz'
23
+ i.sub!(/\.gem$/,'')
24
+ i.sub!(/\.tgz$/,'')
25
+ i.sub!(/\.zip$/,'')
26
+ i.sub!(/\.jar$/,'')
27
+ i.sub!(/\.js$/,'')
28
+ i.sub!(/\.stable$/,'')
29
+ return i
30
+ end
31
+
32
+ end
@@ -0,0 +1,167 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'program_information/toplevel_methods/return_proper_pipe_token_to_this_input.rb'
6
+ # =========================================================================== #
7
+ require 'program_information/constants/regex.rb'
8
+ require 'program_information/toplevel_methods/opnn.rb'
9
+ require 'program_information/toplevel_methods/remove_archive_type.rb'
10
+
11
+ module ProgramInformation
12
+
13
+ # ========================================================================= #
14
+ # === ProgramInformation.return_proper_pipe_token_to_this_input
15
+ #
16
+ # Most of the content of this method has to be put into a begin/require
17
+ # clause, as errors may happen, which could propagate downstream,
18
+ # leading to confusion. So we will rescue the error, and notify the
19
+ # user as to what has happened.
20
+ # ========================================================================= #
21
+ def self.return_proper_pipe_token_to_this_input(
22
+ entry
23
+ )
24
+ if entry.is_a? Array
25
+ entry = entry.first
26
+ end
27
+ entry = remove_archive_type(entry)
28
+ use_this_replacement_token = '|'
29
+ return if entry.to_s.empty?
30
+ begin
31
+ # ===================================================================== #
32
+ # === Check for input such as 'unieject-6', containing one '-' and 0 '_'
33
+ # ===================================================================== #
34
+ if (entry.count('-') == 1) and
35
+ (entry.count('_') == 0)
36
+ entry[entry.index('-'),1] = use_this_replacement_token
37
+ # ===================================================================== #
38
+ # === Check for input such as 'p7zip_16.02_src_all.tar.bz2' with
39
+ # 3 '_' and at the least one '.' and no '-'
40
+ # ===================================================================== #
41
+ elsif (entry.count('_') == 3) and
42
+ (entry.count('.') > 0) and
43
+ (!entry.include?('-'))
44
+ entry[entry.index('_'),1] = use_this_replacement_token
45
+ # ===================================================================== #
46
+ # === Input such as 'mod_python_3.3.1', with two '_' and no '-'.
47
+ # ===================================================================== #
48
+ elsif (entry.count('_') == 2) and
49
+ (entry.count('-') == 0)
50
+ entry[entry.rindex('_'),1] = use_this_replacement_token
51
+ # ===================================================================== #
52
+ # === Input such as 'unzip60' without any '-' or '_'
53
+ # ===================================================================== #
54
+ elsif (entry.count('-') == 0) and
55
+ (entry.count('_') == 0) and
56
+ (!entry.include?('.'))
57
+ entry[entry.index(/\d/), 0] = '|'
58
+ # ===================================================================== #
59
+ # === Check for input such as 'artemis_v16.0.11' or 'dpkg_1.18.22'
60
+ # with one '_' and no '-'.
61
+ # ===================================================================== #
62
+ elsif (entry.count('_') == 1) and
63
+ (entry.count('-') == 0)
64
+ entry[entry.index('_'),1] = use_this_replacement_token
65
+ # ===================================================================== #
66
+ # === Input such as 'sendmail.8.15.2' or 'expect5.45.3', without
67
+ # any '-' or '_'.
68
+ # ===================================================================== #
69
+ elsif (entry.count('-') == 0) and
70
+ (entry.count('_') == 0) and
71
+ (entry.include?('.'))
72
+ entry =~ REGEX_FOR_INPUT_HAVING_ONLY_DOTS
73
+ entry = $1.to_s.dup+use_this_replacement_token+$2.to_s.dup
74
+ # ===================================================================== #
75
+ # For input such as 'boost-1_54_0' or 'ncbi_cxx-12_0_0' or
76
+ # 'boost_1.56.6'. So it contains exactly one '-' character.
77
+ # ===================================================================== #
78
+ elsif ((entry.count('-') == 1) and
79
+ (entry.count('_') > 1) and # More than 1 '_'
80
+ (entry =~ REGEX_FOR_BOOST_LIKE_INPUT)) or # or the second condition.
81
+ ((entry.count('_') == 3) and
82
+ (entry.count('-') == 0) and
83
+ (entry =~ REGEX_FOR_BOOST_LIKE_INPUT))
84
+ entry =~ REGEX_FOR_BOOST_LIKE_INPUT
85
+ # =================================================================== #
86
+ # We here need only the first and the third match.
87
+ # =================================================================== #
88
+ entry = "#{$1.to_s.dup}#{use_this_replacement_token}#{$3.to_s.dup}"
89
+ # ===================================================================== #
90
+ # For input such as 'acl_2.2.47-1' or 'e_dbus-1.7.10' or
91
+ # 'SDL2_gfx-1.0.1' or 'domain_name-0.5.20170404.gem' or
92
+ # 'libatomic_ops-7.4.2' or 'icu4c-62_1'.
93
+ # ===================================================================== #
94
+ elsif (entry.count('_') == 1) and
95
+ (entry.count('-') == 1) and
96
+ (entry =~ REGEX_FOR_ACL_LIKE_INPUT)
97
+ regex_to_use = REGEX_FOR_ACL_LIKE_INPUT
98
+ entry =~ regex_to_use
99
+ # =================================================================== #
100
+ # Here we also only need to match towards the first and the third
101
+ # entry.
102
+ # =================================================================== #
103
+ entry = $1.to_s.dup+use_this_replacement_token+$3.to_s.dup
104
+ # ===================================================================== #
105
+ # === Input such as 'did_you_mean-1.1.2' with one '-' and two '_'
106
+ # ===================================================================== #
107
+ elsif (entry.count('-') == 1) and
108
+ (entry.count('_') == 2)
109
+ entry[entry.index('-'),1] = use_this_replacement_token
110
+ # ===================================================================== #
111
+ # === Input such as 'ntfs-3g_ntfsprogs-2017.3.23' for 2 '-' and
112
+ # 1 '_'.
113
+ # ===================================================================== #
114
+ elsif (entry.count('-') == 2) and
115
+ (entry.count('_') == 1)
116
+ regex_to_use = REGEX_FOR_INPUT_CONTAINING_TWO_HYPHENS_AND_ONE_UNDERSCORE
117
+ entry =~ regex_to_use
118
+ entry = $1.to_s.dup+use_this_replacement_token+$3.to_s.dup
119
+ # ===================================================================== #
120
+ # For input such as 'lynx-2.8.8-rel2' or 'subtle-0.11.3224-xi' or
121
+ # 'gobject-introspection-1.53.4' or 'dvd+rw-tools-7.1' or
122
+ # 'Archive-Zip-1.46' or 'b43-fwcutter-015' or 'wcd-6.0.1-beta3'
123
+ # or 'oxygen-icons5-5.37.0'. These entries have two '-' and zero
124
+ # '_'.
125
+ # ===================================================================== #
126
+ elsif (entry.count('-') == 2) and
127
+ (entry.count('_') == 0)
128
+ regex_to_use = REGEX_FOR_TWO_HYPHENS
129
+ entry =~ regex_to_use
130
+ entry = $1.to_s.dup+use_this_replacement_token+$2.to_s.dup
131
+ # ===================================================================== #
132
+ # For input such as 'polkit-qt-1-0.112.0' or
133
+ # 'font-bitstream-75dpi-1.0.3' or 'boost-build-2014-10' or
134
+ # 'xf86-video-i810-1.7.4' or 'gnome-internet-radio-locator-0.9.0'
135
+ # or 'mime-types-data-3.2016.0521' or 'polkit-kde-agent-1-5.15.2'
136
+ # or 'xf86-video-amd-2.7.7.7'.
137
+ #
138
+ # This input will NOT have any '_' token; and at the least 3
139
+ # '-' tokens.
140
+ # ===================================================================== #
141
+ elsif (!entry.include?('_')) and
142
+ (entry.count('-') >= 3)
143
+ regex_to_use = REGEX_FOR_THREE_OR_MORE_HYPHENS
144
+ entry =~ regex_to_use
145
+ entry = $1.to_s.dup+
146
+ use_this_replacement_token+
147
+ $2.to_s.dup
148
+ else
149
+ e 'ERROR in program_information.rb! This should never happen.'
150
+ e "The input was: #{entry}"
151
+ end
152
+ rescue Exception => error
153
+ opnn; e 'An error happened (line: '+__LINE__.to_s+'), for '\
154
+ 'the entry `'+entry.to_s+'`.'
155
+ pp error
156
+ pp error.class
157
+ opnn; e 'The caller stack was:'
158
+ pp caller()
159
+ end
160
+ return entry
161
+ end
162
+
163
+ end
164
+
165
+ if __FILE__ == $PROGRAM_NAME
166
+ ProgramInformation.return_proper_pipe_token_to_this_input(ARGV)
167
+ end # rb return_proper*rb icu4c-61_1