program_information 1.1.3

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.

Potentially problematic release.


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

@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca607b1d436ccedea84032d281b1611f2d38dbdef363fc39f25d9b97603f29cb
4
+ data.tar.gz: 783469f7383a5ca7608308065ba0f91c750dae7221c4156a90e332f052463cc2
5
+ SHA512:
6
+ metadata.gz: b6869ce061838966f6963022fa9ba5976e5ee2d93f5ffff477359b13b37e71c4626737d5f32020c910e35ebfc586b12a4105401571c74a69d4b5919959422eb2
7
+ data.tar.gz: 75937f68f7fc398f47f7b98a91001999041fd45c8c8024b0fdb231080da66791031713cd66ef1e85c2fc59058083ee11b294d2b3716b33bcf9f6b55e6176a7b2
@@ -0,0 +1,9 @@
1
+ ## .first and .last
2
+
3
+ You can obtain the name of the program at hand, and the associated
4
+ version, like so:
5
+
6
+ require 'program_information'
7
+ x = ProgramInformation.new('ruby-2.5.0')
8
+ puts x.first
9
+ puts x.last
@@ -0,0 +1,14 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'program_information'
6
+
7
+ if ARGV.first
8
+ ProgramInformation::ProgramInformation.new(ARGV).report(:be_verbose)
9
+ else # "Normal" tests here.
10
+ _ = ProgramInformation.parse 'http://downloads.sourceforge.net/boost/boost_1_54_0.tar.bz2'
11
+ p ProgramInformation.parse('http://downloads.sourceforge.net/boost/boost_1_54_0.tar.bz2', false)
12
+ end
13
+ # p _.original_program_name
14
+ # pii
@@ -0,0 +1,22 @@
1
+ Any given input can have three components:
2
+
3
+ (1) real_short_name
4
+ (2) short_name
5
+ (3) program_version
6
+
7
+ real_short_name depends on short_name. It simply is short_name with all
8
+ instances of the '_' character removed. It is thus a dependent variable.
9
+
10
+ The three numbers above also correspond to respective @instance_variables,
11
+ so in other words we have @real_short_name, @short_name and
12
+ @program_version.
13
+
14
+ The input passed to the main class may be "unclean". The class will try
15
+ # to get the "best" result out of any given input that was supplied, no
16
+ matter how unclean this input was.
17
+
18
+ It is recommended to use this class when wanting to determine the
19
+ short_name and the program version of any given program.
20
+
21
+ Note that short_name is allowed to include '-' characters whereas
22
+ real_short_name will strip '-' characters.
@@ -0,0 +1,9 @@
1
+ ## .first and .last
2
+
3
+ You can obtain the name of the program at hand, and the associated
4
+ version, like so:
5
+
6
+ require 'program_information'
7
+ x = ProgramInformation.new('ruby-2.5.0')
8
+ puts x.first
9
+ puts x.last
@@ -0,0 +1,2 @@
1
+ require 'program_information/toplevel_methods.rb'
2
+ require 'program_information/constants/array_test_with_this_as_input.rb'
@@ -0,0 +1,120 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # This is the input that can be used by the testing file.
6
+ # =========================================================================== #
7
+ # require 'program_information/constants/array_test_with_this_as_input.rb'
8
+ # =========================================================================== #
9
+ require 'program_information/constants/regex.rb'
10
+ require 'program_information/toplevel_methods/return_proper_pipe_token_to_this_input.rb'
11
+
12
+ module ProgramInformation
13
+
14
+ # ========================================================================= #
15
+ # === ProgramInformation::ARRAY_TEST_THIS_AS_INPUT
16
+ #
17
+ # The character '|' is not allowed to be part of any program name,
18
+ # so we wil use this as special token.
19
+ #
20
+ # We will insert it at the boundary level.
21
+ # ========================================================================= #
22
+ ARRAY_TEST_THIS_AS_INPUT = %w(
23
+ unieject-6
24
+ acl_2.2.47-1
25
+ ncbi_cxx-12_0_0
26
+ lynx-2.8.8-rel2
27
+ subtle-0.11.3224-xi
28
+ font-bitstream-75dpi-1.0.3
29
+ xf86-input-elographics-1.4.1
30
+ zope.interface-4.2.0
31
+ CrownCutlass-Alpha1.4
32
+ gobject-introspection-1.53.4
33
+ dvd+rw-tools-7.1
34
+ font-xfree86-type1-1.0.4
35
+ lshw-B.02.08.01
36
+ e_dbus-1.7.10
37
+ xf86-video-omap-0.4.2
38
+ at-spi2-core-2.19.2
39
+ xfce4-dev-tools-4.8.0
40
+ WebKit-r174650
41
+ akonadi-calendar-tools-17.08.1
42
+ Archive-Zip-1.46
43
+ did_you_mean-1.1.2
44
+ artemis_v16.0.11
45
+ chunky_png-1.3.8
46
+ libedit-20170329-3.1
47
+ font-adobe-utopia-type1-1.0.4
48
+ wpa_supplicant-2.6
49
+ dpkg_1.18.22
50
+ ncbi-blast-2.6.0+
51
+ ntfs-3g_ntfsprogs-2017.3.23
52
+ b43-fwcutter-015
53
+ wcd-6.0.1-beta3
54
+ xf86-video-i810-1.7.4
55
+ gnome-internet-radio-locator-0.9.0
56
+ SDL2_gfx-1.0.1
57
+ boost-1_54_0
58
+ boost_1_65_1.tar.bz2
59
+ boost_1_65_1
60
+ oxygen-icons5-5.37.0
61
+ artemis_v16.0.11.jar
62
+ mod_python_3.3.1
63
+ xfce4-statusnotifier-plugin-0.2.0
64
+ p7zip_16.02_src_all.tar.bz2
65
+ mime-types-data-3.2016.0521.gem
66
+ domain_name-0.5.20170404.gem
67
+ ftp://ftp.alsa-project.org/pub/plugins/alsa-plugins-1.0.29.tar.bz2
68
+ alsa-plugins-1.0.29.tar.bz2
69
+ alsa-plugins-1.0.29
70
+ libquvi-scripts-0.9.20131130
71
+ btrfs-progs-v4.13.2.tar.xz
72
+ btrfs-progs-v4.13.2
73
+ ImageMagick-7.0.7-7
74
+ Archive-Zip-1.46
75
+ loop-AES-v3.7d
76
+ boost-build-2014-10
77
+ openobex-1.7.1-Source
78
+ /Users/x/SRC/zope.interface/zope.interface-4.4.2.tar.gz
79
+ libatomic_ops-7.4.2.tar.gz
80
+ mod_python-11.10.2017
81
+ expect5.45.3
82
+ http://search.cpan.org/CPAN/authors/id/M/MA/MARKOV/XML-LibXML-Simple-0.98.tar.gz
83
+ https://rubygems.org/downloads/mini_portile2-2.3.0.gem
84
+ kismet-2016-07-R1.tar.xz
85
+ nana%201.5.4.zip
86
+ http://download.icu-project.org/files/icu4c/61.1/icu4c-61_1-src.tgz
87
+ XML-NamespaceSupport-1.09.tar.xz
88
+ XML-NamespaceSupport-1.09
89
+ icu4c-62_1
90
+ polkit-kde-agent-1-5.15.2
91
+ polkit-kde-agent-1-5.10.95
92
+ polkit-qt-1-0.112.0
93
+ xf86-video-amd-2.7.7.7
94
+ NVIDIA-Linux-x86-352.63.run
95
+ xf86-video-s3virge-1.11.0
96
+ youtube-dl-2019.06.27
97
+ dvd+rw-tools-7.1
98
+ )
99
+
100
+ end
101
+
102
+ if __FILE__ == $PROGRAM_NAME
103
+ require 'colours/autoinclude'
104
+ # ========================================================================= #
105
+ # This is colourized in more detail because it makes it easier to
106
+ # visualize what is going on, on the commandline.
107
+ # ========================================================================= #
108
+ ProgramInformation::ARRAY_TEST_THIS_AS_INPUT.each {|entry|
109
+ original_entry = entry.dup
110
+ entry = File.basename(entry)
111
+ entry = ProgramInformation.return_proper_pipe_token_to_this_input(entry)
112
+ use_sfancy_colour = Colours.colour_methods_to_specific_colour?[:sfancy]
113
+ e "#{simp(original_entry.ljust(36))}"\
114
+ " -> "\
115
+ "#{sfancy(
116
+ entry.sub(/\|/, Colours.orange('|')+
117
+ Colours.send(use_sfancy_colour))
118
+ )}"
119
+ }
120
+ end
@@ -0,0 +1,42 @@
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
+ begin
10
+ require 'colours'
11
+ rescue LoadErrors; end
12
+
13
+ # ========================================================================= #
14
+ # === rev
15
+ # ========================================================================= #
16
+ def rev
17
+ Colours.rev
18
+ end
19
+
20
+ # ========================================================================= #
21
+ # === COLOUR_FOR_REVERT
22
+ # ========================================================================= #
23
+ COLOUR_FOR_REVERT = Colours::WHITE # WHITE is defined in the colours project.
24
+
25
+ # ========================================================================= #
26
+ # === APOSTROPH
27
+ # ========================================================================= #
28
+ APOSTROPH = Colours::TEAL+'`'+COLOUR_FOR_REVERT # +Colours.rev
29
+
30
+ # ========================================================================= #
31
+ # === NAME_OF_CLASS
32
+ # ========================================================================= #
33
+ NAME_OF_CLASS = Colours::CGREY+'ProgramInformation:'+COLOUR_FOR_REVERT
34
+
35
+ # ========================================================================= #
36
+ # === yellow?
37
+ # ========================================================================= #
38
+ def yellow?
39
+ Colours::BOLD_YELLOW
40
+ end
41
+
42
+ end; end
@@ -0,0 +1,55 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'program_information/constants/constants.rb'
6
+ # =========================================================================== #
7
+ require 'program_information/constants/regex.rb'
8
+ require 'program_information/constants/colours.rb'
9
+
10
+ module ProgramInformation
11
+
12
+ class ProgramInformation
13
+
14
+ # ========================================================================= #
15
+ # === SHALL_WE_DOWNCASE
16
+ #
17
+ # So that input such as "Libgnome" can become "libgnome".
18
+ # ========================================================================= #
19
+ SHALL_WE_DOWNCASE = false
20
+
21
+ # ========================================================================= #
22
+ # === REMOVE_PLUS_AND_MINUS
23
+ #
24
+ # If true then we will remove plus '+' and minus '-' from the program name.
25
+ # ========================================================================= #
26
+ REMOVE_PLUS_AND_MINUS = false
27
+
28
+ # ========================================================================= #
29
+ # === REPLACE_PLUS_WITH_LONG_NAME
30
+ #
31
+ # If this constant is true then we will replace all '+' with the
32
+ # string 'plus' as part of the issued name. Note that remove-actions
33
+ # are stronger, so if the constant REMOVE_PLUS_AND_MINUS was also
34
+ # set to true, then the constant here will not be honoured at all.
35
+ # ========================================================================= #
36
+ REPLACE_PLUS_WITH_LONG_NAME = false
37
+
38
+ # ========================================================================= #
39
+ # === REMOVE_PLUS_TOKEN
40
+ #
41
+ # If this constant is true then we will eliminate '+' in the input.
42
+ #
43
+ # This overrules the replace-constant called REPLACE_PLUS_WITH_LONG_NAME.
44
+ #
45
+ # Also note that if the constant REMOVE_PLUS_AND_MINUS is set to true
46
+ # then this setting here will always be set to false.
47
+ # ========================================================================= #
48
+ REMOVE_PLUS_TOKEN = false
49
+
50
+ # ========================================================================= #
51
+ # === BE_VERBOSE
52
+ # ========================================================================= #
53
+ BE_VERBOSE = false
54
+
55
+ end; end
@@ -0,0 +1,85 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'program_information/constants/regex.rb'
6
+ # =========================================================================== #
7
+ module ProgramInformation
8
+
9
+ # ========================================================================= #
10
+ # === REGEX_FOR_TWO_HYPHENS
11
+ #
12
+ # This is valid for input such as 'lynx-2.8.8-rel2' or
13
+ # 'gobject-introspection-1.53.4' or 'subtle-0.11.3224-xi' or
14
+ # 'dvd+rw-tools-7.1' or 'Archive-Zip-1.46' or 'btrfs-progs-v4.12.1'
15
+ # or 'color-tools-1.3.0' or 'libedit-20170329-3.1' or
16
+ # 'ncbi-blast-2.6.0+' or 'b43-fwcutter-015' or 'wcd-6.0.1-beta3'
17
+ # or 'oxygen-icons5-5.37.0' or 'btrfs-progs-v4.13.2' or
18
+ # 'Archive-Zip-1.46' or 'wcd-6.0.1-beta3' or 'openobex-1.7.1-Source'
19
+ # or 'youtube-dl-2019.06.27'.
20
+ #
21
+ # See:
22
+ #
23
+ # https://rubular.com/r/u9Yy3qcxrlp5uG
24
+ #
25
+ # ========================================================================= #
26
+ REGEX_FOR_TWO_HYPHENS =
27
+ /([A-Za-z+]{0,12}-?[a-z0-9]{0,9}-?[A-Za-z]{0,14}\d{0,4}-?[A-Za-z0-9]{0,12})-(\d{0,2}\.?[a-z]{0,1}\d{0,2}\.?[a-z]{0,1}\d{0,4}[.|-]?\d{0,8}[A-Za-z]{0,9}\d?\+?)$/
28
+
29
+ # ========================================================================= #
30
+ # === REGEX_FOR_THREE_OR_MORE_HYPHENS
31
+ #
32
+ # This is for input such as 'akonadi-calendar-tools-17.08.1' or
33
+ # 'boost-build-2014-10' or 'xf86-video-i810-1.7.4' or
34
+ # or 'xfce4-statusnotifier-plugin-0.2.0' or 'mime-types-data-3.2016.0521'
35
+ # or 'XML-LibXML-Simple-0.98' or 'kismet-2016-07-R1.tar.xz' or
36
+ # 'polkit-kde-agent-1-5.15.2' or 'xf86-video-amd-2.7.7.7'
37
+ # or 'xf86-video-s3virge-1.11.0'.
38
+ #
39
+ # See: https://rubular.com/r/lCrdU01HE7MRV4
40
+ # ========================================================================= #
41
+ REGEX_FOR_THREE_OR_MORE_HYPHENS =
42
+ /^([A-Za-z]{0,9}\d{0,2}-?[A-Za-z]{0,12}\d{0,2}-?[a-z]{0,9}\d{0,1}-?[A-Za-z]{0,8}-?1?\d{0,3}[a-z]{0,3})-(\d{0,4}\.?\d{0,4}\.?-?[A-Z]{0,1}\d{0,4}\.?\d{0,4})$/
43
+
44
+ # ========================================================================= #
45
+ # === REGEX_FOR_INPUT_HAVING_ONLY_DOTS
46
+ #
47
+ # This is valid for strange input such as 'expect5.45.3' or
48
+ # 'sendmail.8.15.2'. These have no '-' and no '_'.
49
+ # ========================================================================= #
50
+ REGEX_FOR_INPUT_HAVING_ONLY_DOTS = # See: http://rubular.com/r/KVePR7ShX3
51
+ /([a-z]{1,10})\.?(\d+\.?\d{1,2}\.?\d{0,2})/
52
+
53
+ # ========================================================================= #
54
+ # === REGEX_FOR_BOOST_LIKE_INPUT
55
+ #
56
+ # Valid input should be 'ncbi_cxx-12_0_0' or 'icu4c-61_1'.
57
+ #
58
+ # See: http://rubular.com/r/CyNqJbCMR2
59
+ # ========================================================================= #
60
+ REGEX_FOR_BOOST_LIKE_INPUT =
61
+ /([a-z]{0,3}\d{0,1}[a-z]{0,5}_?[a-z]{0,3})([-|_]{1})(\d{1,2}_\d{1,2}_?\d*)/
62
+
63
+ # ========================================================================= #
64
+ # === REGEX_FOR_ACL_LIKE_INPUT
65
+ #
66
+ # Valid input should be 'acl_2.2.47-1' or 'e_dbus-1.7.10' or
67
+ # 'wpa_supplicant-2.6' or 'SDL2_gfx-1.0.1' or 'libatomic_ops-7.4.2'
68
+ # or 'mod_python-11.10.2017' or 'mini_portile2-2.3.0.gem'.
69
+ #
70
+ # See: http://rubular.com/r/XDdBNWxipp
71
+ # ========================================================================= #
72
+ REGEX_FOR_ACL_LIKE_INPUT =
73
+ /([A-Za-z]{0,10}[0-9]{0,1}_?[0-9]{0,1}[a-z]{1,10}[0-9]{0,1})(_|-)([0-9]{0,2}\.?[0-9]{0,2}\.?[0-9]{0,2}-?[0-9]{0,2}_?[0-9]{0,4})/
74
+
75
+ # ========================================================================= #
76
+ # === REGEX_FOR_INPUT_CONTAINING_TWO_HYPHENS_AND_ONE_UNDERSCORE
77
+ #
78
+ # This is input for programs such as 'ntfs-3g_ntfsprogs-2017.3.23'.
79
+ #
80
+ # See: http://rubular.com/r/15pAuHKxt5
81
+ # ========================================================================= #
82
+ REGEX_FOR_INPUT_CONTAINING_TWO_HYPHENS_AND_ONE_UNDERSCORE =
83
+ /([a-z]{1}.+)(-)(\d{1,4}\.\d\.\d{1,2})/
84
+
85
+ end
@@ -0,0 +1,34 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ module ProgramInformation
6
+
7
+ class ProgramInformation # === ProgramInformation::ProgramInformation
8
+
9
+ # ========================================================================= #
10
+ # === initialize
11
+ #
12
+ # Specific Usage Example:
13
+ # ProgramInformation::ProgramInformation.new('util-linux-ng-2.15')
14
+ # ========================================================================= #
15
+ def initialize(
16
+ i = ARGV,
17
+ run_already = true,
18
+ optional_be_verbose = false
19
+ )
20
+ reset
21
+ set_input(i)
22
+ if optional_be_verbose
23
+ set_be_verbose(optional_be_verbose)
24
+ end
25
+ case run_already
26
+ when :do_run_already
27
+ run_already = true
28
+ when :dont_run_already, :do_not_run_already
29
+ run_already = false
30
+ end
31
+ run if run_already
32
+ end
33
+
34
+ end; end
@@ -0,0 +1,29 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'program_information/menu.rb'
6
+ # =========================================================================== #
7
+ module ProgramInformation
8
+
9
+ class ProgramInformation
10
+
11
+ # ========================================================================= #
12
+ # === menu (menu tag)
13
+ # ========================================================================= #
14
+ def menu(i)
15
+ if i.is_a? Array
16
+ i.each {|entry| menu(entry) }
17
+ else
18
+ case i
19
+ # ===================================================================== #
20
+ # === help
21
+ # ===================================================================== #
22
+ when /-?-?help$/i
23
+ show_help
24
+ exit
25
+ end
26
+ end
27
+ end
28
+
29
+ end; end
@@ -0,0 +1,568 @@
1
+ #!/System/Index/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === ProgramInformation::ProgramInformation
6
+ #
7
+ # The main class will reside here.
8
+ #
9
+ # This class can provide us with the proper name, and the proper version
10
+ # for any given program.
11
+ #
12
+ # We simply take the given input and use three components for it:
13
+ #
14
+ # (1) real_short_name
15
+ # (2) short_name
16
+ # (3) program_version
17
+ #
18
+ # Note that real_short_name depends on short_name. It simply is short_name
19
+ # with all instances of the '_' character removed. It is thus a dependent
20
+ # variable.
21
+ #
22
+ # The three numbers above also correspond to respective @instance_variables,
23
+ # so in other words we have @real_short_name, @short_name and
24
+ # @program_version.
25
+ #
26
+ # The input can be a bit "unclean". The class will try to get the "best"
27
+ # result out of any given input, no matter how unclean it is.
28
+ #
29
+ # It is recommended to use this class when wanting to determine the
30
+ # short_name and the program version of any given program.
31
+ # =========================================================================== #
32
+ # require 'program_information/program_information.rb'
33
+ # =========================================================================== #
34
+ require 'remove_file_suffix'
35
+ require 'program_information/project/project_base_directory.rb'
36
+ require 'program_information/toplevel_methods/e.rb'
37
+ require 'program_information/toplevel_methods/return_proper_pipe_token_to_this_input.rb'
38
+ require 'program_information/toplevel_methods/remove_archive_type.rb'
39
+ require 'program_information/constants/constants.rb'
40
+ require 'program_information/version/version.rb'
41
+ require 'program_information/initialize.rb'
42
+ require 'program_information/menu.rb'
43
+ require 'program_information/reset.rb'
44
+ require 'program_information/report.rb'
45
+ require 'program_information/run.rb'
46
+
47
+ module ProgramInformation
48
+
49
+ class ProgramInformation # === ProgramInformation::ProgramInformation
50
+
51
+ # ========================================================================= #
52
+ # === return_proper_pipe_token_to_this_input
53
+ # ========================================================================= #
54
+ def return_proper_pipe_token_to_this_input(i)
55
+ ::ProgramInformation.return_proper_pipe_token_to_this_input(i)
56
+ end
57
+
58
+ # ========================================================================= #
59
+ # === remove_file_suffix
60
+ #
61
+ # Delegate towards class RemoveFileSuffix. This is easier to handle
62
+ # Archive.
63
+ # ========================================================================= #
64
+ def remove_file_suffix(i)
65
+ RemoveFileSuffix[i.to_s]
66
+ end
67
+
68
+ # ========================================================================= #
69
+ # === do_not_replace_plus
70
+ # ========================================================================= #
71
+ def do_not_replace_plus
72
+ @replace_plus_with_long_name = false
73
+ end; alias do_not_replace_anything do_not_replace_plus # === do_not_replace_anything
74
+
75
+ # ========================================================================= #
76
+ # === set_program_version
77
+ #
78
+ # Use this method whenever you wish to assign to the @program_version
79
+ # variable.
80
+ #
81
+ # The input to this method may include stuff such as ".tar.xz", which
82
+ # should be chopped off, as it is not part of the program version.
83
+ #
84
+ # Keep in mind that we may also return nil.
85
+ #
86
+ # Until March 2015 we also replaced all '_' with '.' characters,
87
+ # but input such as "ncbi_cxx--12_0_0.tar.gz" would break as a
88
+ # consequence, so this was disabled again.
89
+ # ========================================================================= #
90
+ def set_program_version(i)
91
+ i = remove_file_suffix(i) unless i.nil? # Disallow archive-types here.
92
+ # ======================================================================= #
93
+ # The following check is not good at all because we may have input
94
+ # such as "1-0.112.0". Polkitqt has this, for instance.
95
+ # Thus, the following line was disabled on Feb 2016.
96
+ # ======================================================================= #
97
+ # if i.include? '-' # In this case, we use only the last part.
98
+ # i = i.split('-').last
99
+ # end
100
+ # ======================================================================= #
101
+ # And if result is actually an empty String, but the original input
102
+ # has included at the least one number, such as in "3.3.6-pl1",
103
+ # then we will simply use that instead.
104
+ # ======================================================================= #
105
+ if i.is_a?(String) and i.empty? and
106
+ @input =~ /\d+/ # <- If the input has at the least one Number.
107
+ i = @input.dup
108
+ end
109
+ @program_version = i
110
+ end; alias set_version set_program_version # === set_version
111
+
112
+ # ========================================================================= #
113
+ # === be_verbose?
114
+ # ========================================================================= #
115
+ def be_verbose?
116
+ @be_verbose
117
+ end
118
+
119
+ # ========================================================================= #
120
+ # === remove_plus_token?
121
+ # ========================================================================= #
122
+ def remove_plus_token?
123
+ @remove_plus_token
124
+ end
125
+
126
+ # ========================================================================= #
127
+ # === input?
128
+ # ========================================================================= #
129
+ def input?
130
+ @input
131
+ end
132
+
133
+ # ========================================================================= #
134
+ # === return_array
135
+ #
136
+ # This method will return a composite, 3-member Array that will hold the
137
+ # short_name, the real_short_name, and the program_version.
138
+ # ========================================================================= #
139
+ def return_array
140
+ [ short_name?, real_short_name?, program_version? ]
141
+ end; alias array? return_array # === array?
142
+
143
+ # ========================================================================= #
144
+ # === remove_plus_and_minus?
145
+ # ========================================================================= #
146
+ def remove_plus_and_minus?
147
+ @remove_plus_and_minus
148
+ end; alias remove_plus_and_minus remove_plus_and_minus? # === remove_plus_and_minus
149
+
150
+ # ========================================================================= #
151
+ # === apostroph?
152
+ # ========================================================================= #
153
+ def apostroph?
154
+ APOSTROPH
155
+ end
156
+
157
+ # ========================================================================= #
158
+ # === replace_plus_with_long_name?
159
+ # ========================================================================= #
160
+ def replace_plus_with_long_name?
161
+ @replace_plus_with_long_name
162
+ end
163
+
164
+ # ========================================================================= #
165
+ # === short_name_and_version?
166
+ #
167
+ # This method returns an aggregated @short_name+'-'+@program_version
168
+ # string.
169
+ # ========================================================================= #
170
+ def short_name_and_version?
171
+ "#{short_name?}-#{program_version?}"
172
+ end; alias short_name_and_version short_name_and_version? # === short_name_and_version
173
+
174
+ # ========================================================================= #
175
+ # === set_short_name_then_version
176
+ #
177
+ # This method will combine two other methods.
178
+ # ========================================================================= #
179
+ def set_short_name_then_version(a, b)
180
+ set_short_name(a)
181
+ set_program_version(b)
182
+ end; alias set_name_then_version set_short_name_then_version # === set_name_then_version
183
+
184
+ # ========================================================================= #
185
+ # === return_real_short_name_and_version
186
+ #
187
+ # We delegate to the module-method here.
188
+ # ========================================================================= #
189
+ def return_real_short_name_and_version(i)
190
+ ::ProgramInformation.return_real_short_name_and_version(i)
191
+ end
192
+
193
+ # ========================================================================= #
194
+ # === return_name_and_version
195
+ #
196
+ # This method will return an array with two elements:
197
+ #
198
+ # (1) The first element is the name of the program in question.
199
+ # (2) The second element is the version of the program in question.
200
+ #
201
+ # The input can be rather tricky and complicated.
202
+ #
203
+ # Consider the following examples:
204
+ #
205
+ # 'libunwind-1.0-rc1'
206
+ # 'htop-1.0.0'
207
+ # 'WebKit-r93670'
208
+ # 'xfce4-dev-tools-4.8.0'
209
+ # 'e_dbus-1.7.10.tar.gz'
210
+ # 'boost_1_54_0.tar.bz2'
211
+ # 'short-mime-1.0.0-rc1'
212
+ #
213
+ # This can all be valid input.
214
+ #
215
+ # Which are the key-assumptions that we can do here?
216
+ #
217
+ # I think the best assumption we can do is to find the first NUMBER in
218
+ # the given string, and then group the rest of the data according to
219
+ # this NUMBER. This will not work in the case of something such as
220
+ # WebKit-r93, as there is a 'r' character before that number.
221
+ # So we will have to make a second assumption: if the character preceding
222
+ # the first found integer is NOT a '-' character, we will instead split
223
+ # on that character instead. This will however lead to a problem for
224
+ # something like "xfce4-dev-tools-4.8.0". So, in case there is a '-'
225
+ # character immediately after the pos variable, we assume we have such
226
+ # a special case.
227
+ #
228
+ # On Sep 2011, I came up with a far simpler idea. We simply have to
229
+ # find the most important '-' and then split accordingly. As long as
230
+ # we can identify the most important '-' correctly, so long will
231
+ # everything else "just work". This also did not work out, so I
232
+ # switched to a regex instead. Since then it has worked very fine.
233
+ #
234
+ # Take input such as:
235
+ #
236
+ # "font-bitstream-75dpi-1.0.0"
237
+ #
238
+ # Note though that this approach does not work with input like:
239
+ # "CrownCutlass-Alpha1.4"
240
+ # unless we assume that alpha is a part of the version,
241
+ # which is possibly correct.
242
+ # ========================================================================= #
243
+ def return_name_and_version(i = nil)
244
+ if i
245
+ determine_the_three_main_variables(i)
246
+ end
247
+ # ======================================================================= #
248
+ # We must consider what we wish to do about the '_' characters. We could
249
+ # remove them, but certain programs such as e_dbus may require it as
250
+ # part of their name. Also, Version entries such as '1_2_3' will become
251
+ # '123' rather than '1.2.3'. Thus, on Jan 2014 I have disabled the
252
+ # following line.
253
+ # ======================================================================= #
254
+ # i.delete!('_') if i.include? '_'
255
+ return [
256
+ @short_name, @program_version
257
+ ]
258
+ end; alias rnav return_name_and_version # === rnav
259
+
260
+ # ========================================================================= #
261
+ # === set_shall_we_downcase
262
+ # ========================================================================= #
263
+ def set_shall_we_downcase(
264
+ i = SHALL_WE_DOWNCASE
265
+ )
266
+ @shall_we_downcase = i
267
+ end
268
+
269
+ # ========================================================================= #
270
+ # === do_not_downcase
271
+ # ========================================================================= #
272
+ def do_not_downcase
273
+ @shall_we_downcase = false
274
+ end
275
+
276
+ # ========================================================================= #
277
+ # === set_be_verbose
278
+ #
279
+ # Set to report in a verbose way here.
280
+ # ========================================================================= #
281
+ def set_be_verbose(i = BE_VERBOSE)
282
+ case i
283
+ when :be_verbose
284
+ i = true
285
+ end
286
+ @be_verbose = i
287
+ end
288
+
289
+ # ========================================================================= #
290
+ # === determine_the_three_main_variables
291
+ #
292
+ # This method will determine the three main instance variables:
293
+ #
294
+ # - @short_name
295
+ # - @real_short_name
296
+ # - @program_version
297
+ #
298
+ # We must be careful, as the input may not include any '-' or '_' token,
299
+ # and then the regex would fail. Hence, the behaviour of this method
300
+ # will depend on whether the input includes a '-' or whether it
301
+ # does not.
302
+ #
303
+ # Note that presently, set_input() will modify the given input and
304
+ # ensure that there will be a '-' token, even in input that does
305
+ # not have any '-' or '_' such as in 'sendmail.8.15.2'.
306
+ # ========================================================================= #
307
+ def determine_the_three_main_variables(i = @input)
308
+ if i
309
+ if i.include? '|'
310
+ splitted = i.split('|')
311
+ short_name = splitted.first.to_s.dup
312
+ program_version = splitted.last.to_s.dup
313
+ set_short_name(short_name)
314
+ set_program_version(program_version)
315
+ else
316
+ opn; e "The input `#{i}` does not include a | character."
317
+ end
318
+ end
319
+ end; alias determine_name_and_program_version determine_the_three_main_variables # === determine_name_and_program_version
320
+
321
+ # ========================================================================= #
322
+ # === set_real_short_name
323
+ #
324
+ # The instance variable @real_short_name is not allowed to include any
325
+ # '-' characters. It may also not include any '_' characters.
326
+ #
327
+ # The latter could be found as part of program names such as "SDL_image".
328
+ # The @short_name variant may include these '_' tokens.
329
+ #
330
+ # Note that as of September 2017, we also disallow '.' tokens, such as
331
+ # may occur accidentally in input like "sendmail.5.8.2".
332
+ # ========================================================================= #
333
+ def set_real_short_name(i = @short_name)
334
+ i = i.to_s.dup.delete('-_.').rstrip
335
+ @real_short_name = i
336
+ end
337
+
338
+ # ========================================================================= #
339
+ # === set_short_name
340
+ #
341
+ # Use this method whenever you wish to assign to the @short_name variable.
342
+ #
343
+ # This variable is allowed to keep '-' and '_' entries, but some
344
+ # settings may also modify this.
345
+ # ========================================================================= #
346
+ def set_short_name(i)
347
+ i = i.dup
348
+ # ======================================================================= #
349
+ # First, consider getting rid of '+' and '-' tokens in the
350
+ # @short_name variant of the program name.
351
+ # For this to work, @remove_plus_and_minus has to be set to true.
352
+ # ======================================================================= #
353
+ if remove_plus_and_minus?
354
+ i.delete!('+') if i.include? '+'
355
+ i.delete!('-') if i.include? '-'
356
+ end
357
+ # ======================================================================= #
358
+ # === Get rid of '+' tokens, if they are included.
359
+ # ======================================================================= #
360
+ if remove_plus_token?
361
+ i.delete!('+') if i.include? '+'
362
+ # ======================================================================= #
363
+ # === Alternatively, replace '+' with the string 'plus' should it
364
+ # exist there.
365
+ # ======================================================================= #
366
+ elsif replace_plus_with_long_name?
367
+ i.gsub!(/\+/, 'plus') if i.include? '+'
368
+ end
369
+ @short_name = i
370
+ set_real_short_name(i) # We will also sync towards @real_short_name.
371
+ end; alias set_name set_short_name # === set_name
372
+ alias set_program_name set_short_name # === set_program_name
373
+
374
+ # ========================================================================= #
375
+ # === remove_source_like_strings
376
+ # ========================================================================= #
377
+ def remove_source_like_strings(i)
378
+ # ======================================================================= #
379
+ # i.gsub!(/--/,'-') if i.include? '--' # Replace '--' with '-'.
380
+ # ^^^ May not be good, depending on the input.
381
+ # ======================================================================= #
382
+ i.sub!(/-src/,'') if i.include? '-src' # Get rid of -src entries.
383
+ i.sub!(/\.source/,'') if i.include? '.source'
384
+ i.sub!(/-source$/,'') if i.end_with? '-source'
385
+ return i
386
+ end
387
+
388
+ # ========================================================================= #
389
+ # === remove_archive_type
390
+ # ========================================================================= #
391
+ def remove_archive_type(i)
392
+ ::ProgramInformation.remove_archive_type(i)
393
+ return i
394
+ end
395
+
396
+ # ========================================================================= #
397
+ # === e
398
+ # ========================================================================= #
399
+ def e(i = '')
400
+ ::ProgramInformation.e(i)
401
+ end
402
+
403
+ # ========================================================================= #
404
+ # === real_short_name?
405
+ #
406
+ # Keep in mind that @real_short_name does not have any '-' tokens.
407
+ # ========================================================================= #
408
+ def real_short_name?
409
+ @real_short_name
410
+ end; alias real_name? real_short_name? # === real_name?
411
+ alias real_program_name? real_short_name? # === real_program_name?
412
+ alias real_short_name real_short_name? # === real_short_name
413
+ alias name_of_the_program? real_short_name? # === name_of_the_program?
414
+
415
+ # ========================================================================= #
416
+ # === short_name?
417
+ #
418
+ # Reader method for the @short_name instance variable.
419
+ #
420
+ # short_name is an alias to @short_name.
421
+ # ========================================================================= #
422
+ def short_name?
423
+ @short_name
424
+ end; alias program_name short_name? # === program_name
425
+ alias program_name? short_name? # === program_name?
426
+ alias name short_name? # === name
427
+ alias name? short_name? # === name?
428
+ alias return_short_name short_name? # === return_short_name
429
+ alias short_name short_name? # === short_name
430
+ alias return_name short_name? # === return_name
431
+ alias first short_name? # === first
432
+ alias return_program_real_name short_name? # === return_program_real_name
433
+
434
+ # ========================================================================= #
435
+ # === program_version?
436
+ #
437
+ # Getter method for the @program_version variable.
438
+ # ========================================================================= #
439
+ def program_version?
440
+ @program_version
441
+ end; alias program_version program_version? # === program_version
442
+ alias version program_version? # === version
443
+ alias version? program_version? # === version?
444
+ alias last? program_version? # === last?
445
+ alias last program_version? # === last?
446
+ alias version_of_the_program? program_version? # === version_of_the_program?
447
+
448
+ # ========================================================================= #
449
+ # === set_input
450
+ #
451
+ # This method will, after performing some sanitize-operations, assign
452
+ # to the @input variable.
453
+ # ========================================================================= #
454
+ def set_input(i)
455
+ if i.is_a? Array
456
+ menu(i)
457
+ i = i.join(' ').strip
458
+ end
459
+ i = i.to_s.dup if i.frozen?
460
+ i = File.basename(i)
461
+ # ======================================================================= #
462
+ # We .squeeze away '--' tokens.
463
+ # ======================================================================= #
464
+ i.squeeze!('-')
465
+ i.strip!
466
+ # ======================================================================= #
467
+ # Next, some simple replacements without any method.
468
+ # ======================================================================= #
469
+ i.sub!(/-paco/,'') if i.include? '-paco'
470
+ i.sub!(/\/Programs\//,'') if i.include? '/Programs'
471
+ # ======================================================================= #
472
+ # The following must not conflict with i.e. "pkgconfig", hence why we
473
+ # also include a '/' character.
474
+ # ======================================================================= #
475
+ i.gsub!(/\/pkg/,'') if i.include? '/pkg'
476
+ # ======================================================================= #
477
+ # i.gsub!(/\//,'-') # Controversial. Disabled for now as of Jan 2014.
478
+ # ======================================================================= #
479
+ # We don't want either { or }.
480
+ # ======================================================================= #
481
+ i.delete!('{') if i.include? '{'
482
+ i.delete!('}') if i.include? '}'
483
+ # ======================================================================= #
484
+ # As of July 2016, we get rid of all tokens that follow a '#' character.
485
+ # We also will get rid of the '#' as well. Must come before we call
486
+ # remove_archive_type().
487
+ # ======================================================================= #
488
+ if i.include? '#'
489
+ i = i[0...i.index('#')]
490
+ end
491
+ i = remove_archive_type(i)
492
+ i = remove_source_like_strings(i)
493
+ # ======================================================================= #
494
+ # Next, we correct for input such as "nana%201.5.4". This one has no
495
+ # '-' token and no '_' token, but a '%' token. This '%' token will be
496
+ # replaced.
497
+ # ======================================================================= #
498
+ if i.include? '%'
499
+ unless i.include?('_') or i.include?('-')
500
+ i.tr!('%','-')
501
+ end
502
+ end
503
+ # ======================================================================= #
504
+ # Leading '-' will be removed.
505
+ # ======================================================================= #
506
+ i[0,1] = '' if i.start_with? '-'
507
+ # ======================================================================= #
508
+ # === Handle downcasing of the given input
509
+ #
510
+ # This will consider downcasing the input. The reason as to why this is
511
+ # necessary is so that input such as "Libgnome" can become "libgnome".
512
+ # ======================================================================= #
513
+ i.downcase! if @shall_we_downcase
514
+ # ======================================================================= #
515
+ # === Handle '+' tokens
516
+ # ======================================================================= #
517
+ if REMOVE_PLUS_TOKEN
518
+ i.delete!('+') if i.include? '+'
519
+ end
520
+ i = return_proper_pipe_token_to_this_input(i)
521
+ @input = i
522
+ end
523
+
524
+ # ========================================================================= #
525
+ # === show_help (help tag)
526
+ #
527
+ # To invoke this method, try:
528
+ #
529
+ # pinfo --show-help
530
+ #
531
+ # ========================================================================= #
532
+ def show_help
533
+ e
534
+ e 'This class is able to split a given input (a string) into'
535
+ e 'the inferred program-name, and associated program version '\
536
+ 'of said string.'
537
+ e
538
+ e 'For example, if you have this input string:'
539
+ e
540
+ e ' gobject-introspection-1.52.1'
541
+ e
542
+ e 'then this class can split this into these constituents:'
543
+ e
544
+ e ' @real_short_name: gobjectintrospection'
545
+ e ' @short_name: gobject-introspection'
546
+ e ' @program_version: 1.52.1'
547
+ e
548
+ e 'This is especially useful for other projects that require this'
549
+ e 'functionality, such as the rbt gem.'
550
+ e
551
+ end
552
+
553
+ end
554
+
555
+ # =========================================================================== #
556
+ # === ProgramInformation[]
557
+ # =========================================================================== #
558
+ def self.[](i)
559
+ ::ProgramInformation::ProgramInformation.new(i)
560
+ end; self.instance_eval { alias new [] } # === ProgramInformation.new
561
+ self.instance_eval { alias parse [] } # === ProgramInformation.parse
562
+ self.instance_eval { alias combined [] } # === ProgramInformation.combined
563
+
564
+ end
565
+
566
+ if __FILE__ == $PROGRAM_NAME
567
+ ProgramInformation::ProgramInformation.new(ARGV)
568
+ end # pinfo /Users/x/SRC/gobjectintrospection/gobject-introspection-1.52.1.tar.xz