extracter 1.1.8

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

Potentially problematic release.


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

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7ce90ada8ae5b5d682c599d1d8268cef5eb5b0defa8e0a3b9078b43878cdd909
4
+ data.tar.gz: 91b62a0f882e5fcc2355e382a3ba62ff420429fe8f66f49ebd24745e6b1dba0d
5
+ SHA512:
6
+ metadata.gz: afe80949cfaa569e0a8de4d151a18efe044ede03b791f483ac4d82404ff289239f009d0ebfd3f32d87d4f82f35b7bf600cd51dc4d3477fd21285d1eb95bc4a19
7
+ data.tar.gz: dcb9bc123d15f426cd4db86cae6422e6d813baee6aefae3e390e98a79f0b1119c9c45e46e0608676153fc936b1390f86e83ddccc5834d34cfc9304ca78c5336d
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ [![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](https://www.gobolinux.org/)
2
+ [![forthebadge](http://forthebadge.com/images/badges/made-with-ruby.svg)](https://www.ruby-lang.org/en/)
3
+ [![Gem Version](https://badge.fury.io/rb/extracter.svg)](https://badge.fury.io/rb/extracter)
4
+
5
+ # Extracter
6
+
7
+ ## Scope of Extracter
8
+
9
+ The scope (and goals) for **class Extracter** are really simple: throw any archive
10
+ format at it, and the class will try to **extract** it.
11
+
12
+ It can be used on the commandline as well.
13
+
14
+ ## How to find out whether a given file is a valid archive
15
+
16
+ You can find out whether given input xyz is a valid archive by issuing
17
+ the following toplevel-method:
18
+
19
+ Extracter.is_this_a_valid_archive?(path)
20
+
21
+ This will return either true or false.
22
+
23
+ ## How to extract an archive through class Extracter, in pure ruby
24
+
25
+ You can use the following method to extract an archive, into a specific
26
+ target location:
27
+
28
+ Extracter.extract_what_to('foo-1.0.tar.xz', '/tmp')
29
+
30
+ The first argument is the local path to an archive. The second
31
+ argument specifies the **target**, usually the target directory.
32
+
33
+ ## Colour support
34
+
35
+ If the **Colours** gem (**gem install colours**) is available then colour
36
+ support is possible for **class Extracter**. For the class, the instance
37
+ variable **@use_colours** determines this. If you do not want to have
38
+ colours then you can disable this, e. g. through the method call
39
+ **.disable_colours** to give one example for doing so.
40
+
41
+ ## class Extracter::ExtractIt
42
+
43
+ class Extracter::ExtractIt was a standalone .gem (named **extract_it**),
44
+ but since as of September 2020 it is now part of "module Extracter".
45
+
46
+ Basically this class is is a wrapper over the class Extracter,
47
+ which will extract archives in general. The extraction step
48
+ will go into the current working directory.
49
+
50
+ ## What archives and files can be extracted?
51
+
52
+ **class Extracter** can extract .tar.xz, .tar.bz, .tar.gz, tar.Z,
53
+ .zip and numerous other file formats. This requires that tools
54
+ such as **tar** or **gzip** or **xz** are installed and available
55
+ on the target computer-machine, as we will simply use ruby to
56
+ shell out to these other programs.
57
+
58
+ This class can also **extract audio-files** if ffmpeg is installed and
59
+ the multimedia_paradise project is available (**gem install
60
+ multimedia_paradise**), as well as squashfs files (typically
61
+ .img files). In the latter case, such an .img file will be mounted
62
+ in the current directory.
63
+
64
+ Support for extracting .jar files has been added in **May 2020**.
65
+
66
+ Support for 'extracting' .pdf files has been added in **January 2021**.
67
+ This depends on **poppler**, and it is not really an extraction; we
68
+ simply convert the file to a .txt (text) file. For this functionality
69
+ the **pdf_paradise** project has to be available.
70
+
71
+
72
+ ## Contact information
73
+
74
+ If your creative mind has ideas and specific suggestions to make this
75
+ gem more useful in general, feel free to drop me an email at any
76
+ time, via:
77
+
78
+ shevy@inbox.lt
79
+
80
+ Before that email I used an email account at Google gmail, but in **2021** I
81
+ decided to slowly abandon gmail for various reasons. In part this is because
82
+ the UI annoys me (on non-chrome browser loading takes too long), but also
83
+ because of Google's attempt to establish mass surveillance via its
84
+ federated cohorts sniffing (FLoC). I do not know what happened at Google,
85
+ but enough is enough - there is only so much you can take while supporting
86
+ greed. When it comes to data mining done by private groups, ultimately
87
+ the user became the product.
88
+
89
+ Do keep in mind that responding to emails may take some time,
90
+ depending on the amount of work I may have at that moment, due
91
+ to reallife time constraints. I will, however had, read feedback
92
+ eventually. Patches and code changes are welcome too, of course,
93
+ as long as they are in the spirit of the project at hand, e. g.
94
+ fitting to the general theme. For this I may make use of github
95
+ as a discussion site, but this has a low priority right now.
96
+
data/USAGE.md ADDED
@@ -0,0 +1,22 @@
1
+ = Usage of Library
2
+
3
+ == Requiring it
4
+
5
+ require 'extracter'
6
+
7
+ == Using it in a project
8
+
9
+ _ = Extracter.extract_what_to('foobar-1.0.tar.bz2', '/tmp/')
10
+
11
+ # You can also use the .new variant, which goes
12
+ # like so::
13
+
14
+ _ = Extracter.new('foo.gz', '/tmp', false) # Yes, you can extract .gz files.
15
+ _.run
16
+
17
+ # The argument false means "do not yet run". You have to
18
+ # invoke the .run method in that case.
19
+
20
+ # The second argument to the above method is the target
21
+ # location, the directory where we will extract our
22
+ # archive to.
data/bin/extract ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'extracter'
6
+
7
+ Extracter.what_to(ARGV, Dir.pwd)
data/bin/extract_it ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'extracter/extract_it/extract_it.rb'
6
+
7
+ if __FILE__ == $PROGRAM_NAME
8
+ _ = Extracter::ExtractIt.new(ARGV, false)
9
+ if ARGV[1]
10
+ _.show_commands_used
11
+ else
12
+ _.be_silent
13
+ end
14
+ _.run
15
+ end # extractit
data/doc/README.gen ADDED
@@ -0,0 +1,69 @@
1
+ ADD_RUBY_BADGE
2
+
3
+ # Extracter
4
+
5
+ ## Scope of Extracter
6
+
7
+ The scope (and goals) for **class Extracter** are really simple: throw any archive
8
+ format at it, and the class will try to **extract** it.
9
+
10
+ It can be used on the commandline as well.
11
+
12
+ ## How to find out whether a given file is a valid archive
13
+
14
+ You can find out whether given input xyz is a valid archive by issuing
15
+ the following toplevel-method:
16
+
17
+ Extracter.is_this_a_valid_archive?(path)
18
+
19
+ This will return either true or false.
20
+
21
+ ## How to extract an archive through class Extracter, in pure ruby
22
+
23
+ You can use the following method to extract an archive, into a specific
24
+ target location:
25
+
26
+ Extracter.extract_what_to('foo-1.0.tar.xz', '/tmp')
27
+
28
+ The first argument is the local path to an archive. The second
29
+ argument specifies the **target**, usually the target directory.
30
+
31
+ ## Colour support
32
+
33
+ If the **Colours** gem (**gem install colours**) is available then colour
34
+ support is possible for **class Extracter**. For the class, the instance
35
+ variable **@use_colours** determines this. If you do not want to have
36
+ colours then you can disable this, e. g. through the method call
37
+ **.disable_colours** to give one example for doing so.
38
+
39
+ ## class Extracter::ExtractIt
40
+
41
+ class Extracter::ExtractIt was a standalone .gem (named **extract_it**),
42
+ but since as of September 2020 it is now part of "module Extracter".
43
+
44
+ Basically this class is is a wrapper over the class Extracter,
45
+ which will extract archives in general. The extraction step
46
+ will go into the current working directory.
47
+
48
+ ## What archives and files can be extracted?
49
+
50
+ **class Extracter** can extract .tar.xz, .tar.bz, .tar.gz, tar.Z,
51
+ .zip and numerous other file formats. This requires that tools
52
+ such as **tar** or **gzip** or **xz** are installed and available
53
+ on the target computer-machine, as we will simply use ruby to
54
+ shell out to these other programs.
55
+
56
+ This class can also **extract audio-files** if ffmpeg is installed and
57
+ the multimedia_paradise project is available (**gem install
58
+ multimedia_paradise**), as well as squashfs files (typically
59
+ .img files). In the latter case, such an .img file will be mounted
60
+ in the current directory.
61
+
62
+ Support for extracting .jar files has been added in **May 2020**.
63
+
64
+ Support for 'extracting' .pdf files has been added in **January 2021**.
65
+ This depends on **poppler**, and it is not really an extraction; we
66
+ simply convert the file to a .txt (text) file. For this functionality
67
+ the **pdf_paradise** project has to be available.
68
+
69
+ ADD_CONTACT_INFORMATION
data/extracter.gemspec ADDED
@@ -0,0 +1,111 @@
1
+ # =========================================================================== #
2
+ # Gemspec for Project Extracter.
3
+ # =========================================================================== #
4
+ require 'extracter/version/version.rb'
5
+
6
+ Gem::Specification.new { |s|
7
+
8
+ s.name = 'extracter'
9
+ s.version = Extracter::Extracter::VERSION
10
+ s.date = Time.now.strftime('%Y-%m-%d')
11
+
12
+ DESCRIPTION = <<-EOF
13
+
14
+ This fairly small class/library can be used to extract different archive
15
+ formats such as .tar.bz2 or .tbz - archives such as .gem and .lzma
16
+ will also work.
17
+
18
+ You can also extract audio, by making use of class ExtractAudio. The
19
+ latter is - and should be - optional though.
20
+
21
+ Usage example:
22
+
23
+ require 'extracter'
24
+
25
+ Extracter.new('/foo/bla-1.0.tar.bz2')
26
+
27
+ The second argument that can be passed to the method new()
28
+ specifies where we should extract to, example:
29
+
30
+ Extracter.new('/foo/bla-1.0.tar.bz2', '/opt')
31
+
32
+ This would extract to the /opt directory.
33
+
34
+ You can query whether input is an archive or not via:
35
+
36
+ Extracter.is_archive? 'foo.tar.xz'
37
+
38
+ As of April 2014 we also provide a bin/extract file, so that
39
+ you can simply extract something from the commandline.
40
+
41
+ Since as of November 2018, class Extracter can also "extract"
42
+ .iso files. (The .iso will be mounted to a directory that
43
+ will be created, actually.)
44
+
45
+ If you have a specific suggestion to make this gem more useful
46
+ for others, please drop me an email at:
47
+
48
+ shevegen@gmail.com
49
+
50
+ Thank you.
51
+
52
+ EOF
53
+
54
+ s.summary = DESCRIPTION
55
+ s.description = DESCRIPTION
56
+
57
+ s.authors = ['Robert A. Heiler']
58
+ s.email = 'shevegen@gmail.com'
59
+ s.files = Dir['**/*']
60
+ s.files << 'USAGE.md'
61
+ s.licenses = 'GPL-2.0'
62
+ s.homepage = 'http://rubygems.org/gems/extracter'
63
+
64
+ # ========================================================================= #
65
+ # Show this when a user installs the DiamondShell.
66
+ # ========================================================================= #
67
+ s.post_install_message = <<-EOF
68
+
69
+ class Extracter can be used to extract archives, such as .tar.gz or
70
+ .zip.
71
+
72
+ If you need some help, you can invoke bin/extract via:
73
+
74
+ extract --help
75
+
76
+ In general, the syntax for extract is kept simple. Just pass in the
77
+ archive that has to be extracted as the first argument to
78
+ extract ( bin/extract) , and class Extracter will try to extract
79
+ it, if it is a registered archive format.
80
+
81
+ In ruby code, you may be able to use class Extracter in this manner:
82
+
83
+ require 'extracter'
84
+ Extracter[file_path_here]
85
+
86
+ or
87
+
88
+ require 'extracter'
89
+ Extracter.new(file_path_here)
90
+
91
+ Specific example:
92
+
93
+ require 'extracter'
94
+ Extracter.new('htop-2.2.0.tar.xz')
95
+
96
+ See the --help option.
97
+
98
+ EOF
99
+
100
+ s.required_ruby_version = '>= '+RUBY_VERSION
101
+ s.required_rubygems_version = '>= '+Gem::VERSION
102
+ s.rubygems_version = '>= '+Gem::VERSION
103
+
104
+ # ========================================================================= #
105
+ # Specify the dependencies for this gem:
106
+ # ========================================================================= #
107
+ s.add_dependency 'colours'
108
+ s.add_dependency 'opn'
109
+ s.add_dependency 'remove_file_suffix'
110
+
111
+ }
data/lib/extracter.rb ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'extracter/extracter.rb'
6
+ require 'extracter/extract_it/extract_it.rb'
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ module Extracter
6
+
7
+ class Extracter
8
+
9
+ # ========================================================================= #
10
+ # === Extracter::Extracter.is_this_a_valid_archive?
11
+ #
12
+ # Query whether the input is a valid archive.
13
+ #
14
+ # The registered formats are stored in the constant
15
+ # ARRAY_REGISTERED_ARCHIVES.
16
+ # ========================================================================= #
17
+ def self.is_this_a_valid_archive?(
18
+ i,
19
+ array_registered_archives = ARRAY_REGISTERED_ARCHIVES
20
+ )
21
+ return_value = false
22
+ array_registered_archives.each {|entry|
23
+ return_value = true if i =~ /#{entry}$/
24
+ }
25
+ return return_value
26
+ end; self.instance_eval { alias is_archive? is_this_a_valid_archive? } # === Extracter::Extracter.is_archive?
27
+
28
+ # ========================================================================= #
29
+ # === Extracter::Extracter.extract_what_to
30
+ #
31
+ # This method provides a convenient API to extract something to a
32
+ # specified directory, as a class method. It defaults to the
33
+ # current working directory, as that is by far the most convenient
34
+ # way to extract a source tarball/archive.
35
+ #
36
+ # Useage example goes like this:
37
+ #
38
+ # Extracter.extract_what_to('foo-1.0.tar.xz', '/tmp')
39
+ #
40
+ # ========================================================================= #
41
+ def self.extract_what_to(
42
+ what,
43
+ to = Dir.pwd, # <- This can also be a Hash.
44
+ optional_be_silent = false
45
+ )
46
+ _ = Extracter.new(what, to, :do_not_run_yet)
47
+ if to.is_a? Hash
48
+ # ===================================================================== #
49
+ # === :prepend_this_namespace
50
+ # ===================================================================== #
51
+ if to.has_key? :prepend_this_namespace
52
+ prefix_with_this = to.delete(:prepend_this_namespace) # Get rid of it from the Hash as well.
53
+ _.prefix_namespace_with(
54
+ prefix_with_this
55
+ )
56
+ end
57
+ # ===================================================================== #
58
+ # === :to
59
+ # ===================================================================== #
60
+ if to.has_key? :to
61
+ to = to.delete(:to)
62
+ end
63
+ # ===================================================================== #
64
+ # === :verbosity
65
+ #
66
+ # Handle how verbose we shall be.
67
+ # ===================================================================== #
68
+ if to.has_key? :verbosity
69
+ _.set_verbosity(
70
+ to.delete(:verbosity)
71
+ )
72
+ end
73
+ # ===================================================================== #
74
+ # === :use_colours
75
+ # ===================================================================== #
76
+ if to.has_key? :use_colours
77
+ _.set_use_colours(to[:use_colours])
78
+ end
79
+ # ===================================================================== #
80
+ # === :pad_opn_with_n_tokens
81
+ # ===================================================================== #
82
+ if to.has_key? :pad_opn_with_n_tokens
83
+ _.set_pad_opn_with_n_tokens(to[:pad_opn_with_n_tokens])
84
+ end
85
+ # ===================================================================== #
86
+ # === :use_opn
87
+ # ===================================================================== #
88
+ if to.has_key? :use_opn
89
+ _.set_use_opn(to[:use_opn])
90
+ end
91
+ end
92
+ if optional_be_silent
93
+ _.be_silent
94
+ else
95
+ _.be_verbose
96
+ end
97
+ # ======================================================================= #
98
+ # === Handle blocks next
99
+ # ======================================================================= #
100
+ if block_given?
101
+ yielded = yield
102
+ case yielded
103
+ when :show_the_full_name_of_the_archive
104
+ _.do_show_the_full_name_of_the_archive
105
+ end
106
+ end
107
+ _.run
108
+ end; self.instance_eval { alias extract_this extract_what_to } # === Extracter.extract_this
109
+ self.instance_eval { alias what_to extract_what_to } # === Extracter.what_to
110
+ self.instance_eval { alias extract extract_what_to } # === Extracter.extract
111
+
112
+ # ========================================================================= #
113
+ # === Extracter::Extracter[]
114
+ # ========================================================================= #
115
+ def self.[](i, where_to = Dir.pwd)
116
+ new(i, where_to)
117
+ end
118
+
119
+ end
120
+
121
+ # =========================================================================== #
122
+ # === Extracter.is_this_a_valid_archive?
123
+ #
124
+ # Determine whether the Extracter project can deal with the given archive
125
+ # or whether it can not.
126
+ # =========================================================================== #
127
+ def self.is_this_a_valid_archive?(i)
128
+ ::Extracter::Extracter.is_this_a_valid_archive?(i)
129
+ end; self.instance_eval { alias is_archive? is_this_a_valid_archive? } # === Extracter.is_archive?
130
+
131
+ # =========================================================================== #
132
+ # === Extracter.extract_what_to
133
+ # =========================================================================== #
134
+ def self.extract_what_to(
135
+ what = 'foo-1.0.tar.xz',
136
+ to = '/tmp/', # This target directory defaults to Linux/UNIX-like systems.
137
+ optional_be_silent = false
138
+ )
139
+ ::Extracter::Extracter.extract_what_to(what, to, optional_be_silent)
140
+ end; self.instance_eval { alias what_to extract_what_to } # === Extracter.what_to
141
+
142
+ # ========================================================================= #
143
+ # === Extracter.extract_what_to
144
+ # ========================================================================= #
145
+ def self.extract_what_to(
146
+ what,
147
+ to = Dir.pwd, # <- This can also be a Hash.
148
+ optional_be_silent = false
149
+ )
150
+ ::Extracter::Extracter.extract_what_to(what, to, optional_be_silent)
151
+ end; self.instance_eval { alias extract_this extract_what_to } # === Extracter.extract_this
152
+ self.instance_eval { alias what_to extract_what_to } # === Extracter.what_to
153
+ self.instance_eval { alias extract extract_what_to } # === Extracter.extract
154
+
155
+ # =========================================================================== #
156
+ # === Extracter[]
157
+ # =========================================================================== #
158
+ def self.[](i, where_to = Dir.pwd)
159
+ ::Extracter::Extracter.new(i, where_to)
160
+ end
161
+
162
+ end