extracter 1.1.2

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: b260c677f0670e3f764bf8e90285a356b901a730e7829261a8c25b0136b8df1b
4
+ data.tar.gz: 7dedb77f42b215ac1d08bf529ae39048cb260e7407239c446275594e717d99b7
5
+ SHA512:
6
+ metadata.gz: f681459221aac1216b4094d681161982934e1e41f4d15057100b25da08d1cb906dc8cbcefd9e439b7c8fb20bb6047c5783462fa2891d936f100b41dbb73e771e
7
+ data.tar.gz: 454105cfc7ba001f684a7098be48ecc37cae49e122b19694da9349c340611c03068e3461d1ed4c6159422c693723efac0ac34affda1b863531f5a52d553e292b
data/README.md ADDED
@@ -0,0 +1,79 @@
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
+ ## What archives and files can be extracted?
42
+
43
+ class Extracter can extract .tar.xz, .tar.bz, .tar.gz, tar.Z,
44
+ .zip and numerous more file formats. This requires that tools such
45
+ as **tar** or **gzip** or **xz** are installed and available on the
46
+ target computer-machine.
47
+
48
+ It can also extract audio-files if ffmpeg is installed and the
49
+ multimedia_paradise project is available (**gem install multimedia_paradise**),
50
+ as well as squashfs files (typically .img files). In the latter case,
51
+ such an .img file will be mounted in the current directory.
52
+
53
+ Support for extracting .jar files has been added in **May 2020**.
54
+
55
+ ## class Extracter::ExtractIt
56
+
57
+ class Extracter::ExtractIt was a standalone .gem (named **extract_it**),
58
+ but since as of September 2020 it is now part of "module Extracter".
59
+
60
+ Basically this class is is a wrapper over the class Extracter,
61
+ which will extract archives in general. The extraction step
62
+ will go into the current working directory.
63
+
64
+
65
+ ## Contact information
66
+
67
+ If your creative mind has ideas and specific suggestions to make this
68
+ gem more useful in general, feel free to drop me an email at any
69
+ time, via:
70
+
71
+ shevegen@gmail.com
72
+
73
+ (Do keep in mind that responding to emails may take some time, depending
74
+ on the amount of work I may have at that moment, due to reallife. I will,
75
+ however had, read feedback. Patches and code changes are welcome too
76
+ of course, as long as they are in the spirit of the project at
77
+ hand, e. g. fitting to the general theme.)
78
+
79
+ Thank you.
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,62 @@
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
+ ## What archives and files can be extracted?
40
+
41
+ class Extracter can extract .tar.xz, .tar.bz, .tar.gz, tar.Z,
42
+ .zip and numerous more file formats. This requires that tools such
43
+ as **tar** or **gzip** or **xz** are installed and available on the
44
+ target computer-machine.
45
+
46
+ It can also extract audio-files if ffmpeg is installed and the
47
+ multimedia_paradise project is available (**gem install multimedia_paradise**),
48
+ as well as squashfs files (typically .img files). In the latter case,
49
+ such an .img file will be mounted in the current directory.
50
+
51
+ Support for extracting .jar files has been added in **May 2020**.
52
+
53
+ ## class Extracter::ExtractIt
54
+
55
+ class Extracter::ExtractIt was a standalone .gem (named **extract_it**),
56
+ but since as of September 2020 it is now part of "module Extracter".
57
+
58
+ Basically this class is is a wrapper over the class Extracter,
59
+ which will extract archives in general. The extraction step
60
+ will go into the current working directory.
61
+
62
+ 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,143 @@
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?(i)
18
+ return_value = false
19
+ ARRAY_REGISTERED_ARCHIVES.each {|entry|
20
+ return_value = true if i =~ /#{entry}$/
21
+ }
22
+ return return_value
23
+ end; self.instance_eval { alias is_archive? is_this_a_valid_archive? } # === Extracter.is_archive?
24
+
25
+ # ========================================================================= #
26
+ # === Extracter.extract_what_to
27
+ #
28
+ # This method provides a convenient API to extract something to a
29
+ # specified directory, as a class method. It defaults to the
30
+ # current working directory, as that is by far the most convenient
31
+ # way to extract a source tarball/archive.
32
+ #
33
+ # Useage example goes like this:
34
+ #
35
+ # Extracter.extract_what_to('foo-1.0.tar.xz', '/tmp')
36
+ #
37
+ # ========================================================================= #
38
+ def self.extract_what_to(
39
+ what,
40
+ to = Dir.pwd, # <- This can also be a Hash.
41
+ optional_be_silent = false
42
+ )
43
+ _ = Extracter.new(what, to, :do_not_run_yet)
44
+ if to.is_a? Hash
45
+ # ===================================================================== #
46
+ # === :prepend_this_namespace
47
+ # ===================================================================== #
48
+ if to.has_key? :prepend_this_namespace
49
+ prefix_with_this = to.delete(:prepend_this_namespace) # Get rid of it from the Hash as well.
50
+ _.prefix_namespace_with(
51
+ prefix_with_this
52
+ )
53
+ end
54
+ # ===================================================================== #
55
+ # === :to
56
+ # ===================================================================== #
57
+ if to.has_key? :to
58
+ to = to.delete(:to)
59
+ end
60
+ # ===================================================================== #
61
+ # === :verbosity
62
+ #
63
+ # Handle how verbose we shall be.
64
+ # ===================================================================== #
65
+ if to.has_key? :verbosity
66
+ _.set_verbosity(
67
+ to.delete(:verbosity)
68
+ )
69
+ end
70
+ # ===================================================================== #
71
+ # === :use_colours
72
+ # ===================================================================== #
73
+ if to.has_key? :use_colours
74
+ _.set_use_colours(to[:use_colours])
75
+ end
76
+ # ===================================================================== #
77
+ # === :pad_opn_with_n_tokens
78
+ # ===================================================================== #
79
+ if to.has_key? :pad_opn_with_n_tokens
80
+ _.set_pad_opn_with_n_tokens(to[:pad_opn_with_n_tokens])
81
+ end
82
+ # ===================================================================== #
83
+ # === :use_opn
84
+ # ===================================================================== #
85
+ if to.has_key? :use_opn
86
+ _.set_use_opn(to[:use_opn])
87
+ end
88
+ end
89
+ if optional_be_silent
90
+ _.be_silent
91
+ else
92
+ _.be_verbose
93
+ end
94
+ # ======================================================================= #
95
+ # === Handle blocks next
96
+ # ======================================================================= #
97
+ if block_given?
98
+ yielded = yield
99
+ case yielded
100
+ when :show_the_full_name_of_the_archive
101
+ _.do_show_the_full_name_of_the_archive
102
+ end
103
+ end
104
+ _.run
105
+ end; self.instance_eval { alias extract_this extract_what_to } # === Extracter.extract_this
106
+ self.instance_eval { alias what_to extract_what_to } # === Extracter.what_to
107
+ self.instance_eval { alias extract extract_what_to } # === Extracter.extract
108
+
109
+ # ========================================================================= #
110
+ # === Extracter::Extracter[]
111
+ # ========================================================================= #
112
+ def self.[](i, where_to = Dir.pwd)
113
+ new(i, where_to)
114
+ end
115
+
116
+ end
117
+
118
+ # =========================================================================== #
119
+ # === Extracter.is_this_a_valid_archive?
120
+ # =========================================================================== #
121
+ def self.is_this_a_valid_archive?(i)
122
+ ::Extracter::Extracter.is_this_a_valid_archive?(i)
123
+ end
124
+
125
+ # =========================================================================== #
126
+ # === Extracter.extract_what_to
127
+ # =========================================================================== #
128
+ def self.extract_what_to(
129
+ what = 'foo-1.0.tar.xz',
130
+ to = '/tmp',
131
+ optional_be_silent = false
132
+ )
133
+ ::Extracter::Extracter.extract_what_to(what, to, optional_be_silent)
134
+ end
135
+
136
+ # =========================================================================== #
137
+ # === Extracter[]
138
+ # =========================================================================== #
139
+ def self.[](i, where_to = Dir.pwd)
140
+ ::Extracter::Extracter.new(i, where_to)
141
+ end
142
+
143
+ end