extracter 1.1.0

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.

@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 88fe5f6b81c9fce68a6d838cfdcef1c9858faf1c736d6d76cb288d1217062043
4
+ data.tar.gz: 8be661f699fbcd0b42db87235d69b1f0a0fc7ac0da0fa4cf876c2256bc980573
5
+ SHA512:
6
+ metadata.gz: eff820355199d58175269a382940260b6c1a54702d7f1ccbde8a17999b0cab45dbd6799320a22b6312387692da04d2a200da928186463b773bbe1ef4a1e8bdc0
7
+ data.tar.gz: fd8139d76229652883f71a44129ff6b589f902ef34466ecff11e10a0f222765b0c933fb62d5f9a9ec5faafc33cd854b3a4a9217491363615db6737bb524fd5d7
@@ -0,0 +1,70 @@
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
+
56
+ ## Contact information
57
+
58
+ If your creative mind has ideas and specific suggestions to make this
59
+ gem more useful in general, feel free to drop me an email at any
60
+ time, via:
61
+
62
+ shevegen@gmail.com
63
+
64
+ (Do keep in mind that responding to emails may take some time, depending
65
+ on the amount of work I may have at that moment, due to reallife. I will,
66
+ however had, read feedback. Patches and code changes are welcome too
67
+ of course, as long as they are in the spirit of the project at
68
+ hand, e. g. fitting to the general theme.)
69
+
70
+ Thank you.
@@ -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.
@@ -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)
@@ -0,0 +1,53 @@
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
+ ADD_CONTACT_INFORMATION
@@ -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::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
+ }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'extracter/extracter.rb'
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ class Extracter
6
+
7
+ # ========================================================================= #
8
+ # === Extracter.is_this_a_valid_archive?
9
+ #
10
+ # Query whether the input is a valid archive.
11
+ #
12
+ # The registered formats are stored in the constant
13
+ # ARRAY_REGISTERED_ARCHIVES.
14
+ # ========================================================================= #
15
+ def self.is_this_a_valid_archive?(i)
16
+ return_value = false
17
+ ARRAY_REGISTERED_ARCHIVES.each {|entry|
18
+ return_value = true if i =~ /#{entry}$/
19
+ }
20
+ return return_value
21
+ end; self.instance_eval { alias is_archive? is_this_a_valid_archive? } # === Extracter.is_archive?
22
+
23
+ # ========================================================================= #
24
+ # === Extracter.extract_what_to
25
+ #
26
+ # This method provides a convenient API to extract something to a
27
+ # specified directory, as a class method. It defaults to the
28
+ # current working directory, as that is by far the most convenient
29
+ # way to extract a source tarball/archive.
30
+ #
31
+ # Useage example goes like this:
32
+ #
33
+ # Extracter.extract_what_to('foo-1.0.tar.xz', '/tmp')
34
+ #
35
+ # ========================================================================= #
36
+ def self.extract_what_to(
37
+ what,
38
+ to = Dir.pwd, # <- This can also be a Hash.
39
+ optional_be_silent = false
40
+ )
41
+ _ = Extracter.new(what, to, :do_not_run_yet)
42
+ if to.is_a? Hash
43
+ # ===================================================================== #
44
+ # === :prepend_this_namespace
45
+ # ===================================================================== #
46
+ if to.has_key? :prepend_this_namespace
47
+ prefix_with_this = to.delete(:prepend_this_namespace) # Get rid of it from the Hash as well.
48
+ _.prefix_namespace_with(
49
+ prefix_with_this
50
+ )
51
+ end
52
+ # ===================================================================== #
53
+ # === :to
54
+ # ===================================================================== #
55
+ if to.has_key? :to
56
+ to = to.delete(:to)
57
+ end
58
+ # ===================================================================== #
59
+ # === :verbosity
60
+ #
61
+ # Handle how verbose we shall be.
62
+ # ===================================================================== #
63
+ if to.has_key? :verbosity
64
+ _.set_verbosity(
65
+ to.delete(:verbosity)
66
+ )
67
+ end
68
+ # ===================================================================== #
69
+ # === :use_colours
70
+ # ===================================================================== #
71
+ if to.has_key? :use_colours
72
+ _.set_use_colours(to[:use_colours])
73
+ end
74
+ # ===================================================================== #
75
+ # === :pad_opn_with_n_tokens
76
+ # ===================================================================== #
77
+ if to.has_key? :pad_opn_with_n_tokens
78
+ _.set_pad_opn_with_n_tokens(to[:pad_opn_with_n_tokens])
79
+ end
80
+ # ===================================================================== #
81
+ # === :use_opn
82
+ # ===================================================================== #
83
+ if to.has_key? :use_opn
84
+ _.set_use_opn(to[:use_opn])
85
+ end
86
+ end
87
+ if optional_be_silent
88
+ _.be_silent
89
+ else
90
+ _.be_verbose
91
+ end
92
+ # ======================================================================= #
93
+ # === Handle blocks next
94
+ # ======================================================================= #
95
+ if block_given?
96
+ yielded = yield
97
+ case yielded
98
+ when :show_the_full_name_of_the_archive
99
+ _.do_show_the_full_name_of_the_archive
100
+ end
101
+ end
102
+ _.run
103
+ end; self.instance_eval { alias extract_this extract_what_to } # === Extracter.extract_this
104
+ self.instance_eval { alias what_to extract_what_to } # === Extracter.what_to
105
+ self.instance_eval { alias extract extract_what_to } # === Extracter.extract
106
+
107
+ # ========================================================================= #
108
+ # === Extracter[]
109
+ # ========================================================================= #
110
+ def self.[](i, where_to = Dir.pwd)
111
+ new(i, where_to)
112
+ end
113
+
114
+ end
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ class Extracter
6
+
7
+ begin
8
+ require 'colours'
9
+ rescue LoadError; end
10
+
11
+ # ========================================================================= #
12
+ # === use_colours?
13
+ #
14
+ # Determine whether we will use colours in class Extracter.
15
+ # ========================================================================= #
16
+ def use_colours?
17
+ @use_colours
18
+ end
19
+
20
+ # ========================================================================= #
21
+ # === set_use_colours
22
+ # ========================================================================= #
23
+ def set_use_colours(i)
24
+ # ======================================================================= #
25
+ # We must also sync this towards our main Hash, for opn(). The next
26
+ # line of code achieves precisely that.
27
+ # ======================================================================= #
28
+ @use_this_opn_hash.update(use_colours: i)
29
+ @use_colours = i
30
+ end
31
+
32
+ # ========================================================================= #
33
+ # === disable_colours
34
+ #
35
+ # Use this method if you want to disable colour-support of this class.
36
+ # ========================================================================= #
37
+ def disable_colours
38
+ @use_colours = false
39
+ @colour_to_use_for_directories = ''.dup
40
+ end
41
+
42
+ # ========================================================================= #
43
+ # === enable_colours
44
+ # ========================================================================= #
45
+ def enable_colours
46
+ @use_colours = true
47
+ @colour_to_use_for_directories = cyan?
48
+ end
49
+
50
+ # ========================================================================= #
51
+ # === set_colour_for_directories
52
+ #
53
+ # Set the colour for directories to use.
54
+ # ========================================================================= #
55
+ def set_colour_for_directories(i)
56
+ @colour_to_use_for_directories = Colours.beautify(i)
57
+ end
58
+
59
+ # ========================================================================= #
60
+ # === colour_to_use_for_directories?
61
+ # ========================================================================= #
62
+ def colour_to_use_for_directories?
63
+ if @use_colours
64
+ @colour_to_use_for_directories
65
+ else
66
+ ''
67
+ end
68
+ end
69
+
70
+ # ========================================================================= #
71
+ # === cyan
72
+ # ========================================================================= #
73
+ def cyan?
74
+ if @use_colours
75
+ Colours::CYAN
76
+ else
77
+ ''
78
+ end
79
+ end
80
+
81
+ # ========================================================================= #
82
+ # === ewarn
83
+ # ========================================================================= #
84
+ def ewarn(i = '')
85
+ if use_colours?
86
+ e Colours.swarn(i)
87
+ else
88
+ e i
89
+ end
90
+ end
91
+
92
+ # ========================================================================= #
93
+ # === simp
94
+ # ========================================================================= #
95
+ def simp(i = '')
96
+ return Colours.simp(i) if @use_colours
97
+ return i
98
+ end
99
+
100
+ # ========================================================================= #
101
+ # === sfile
102
+ # ========================================================================= #
103
+ def sfile(i = '')
104
+ return Colours.sfancy(i) if @use_colours
105
+ return i
106
+ end
107
+
108
+ # ========================================================================= #
109
+ # === sfancy
110
+ # ========================================================================= #
111
+ def sfancy(i = '')
112
+ return Colours.sfancy(i) if @use_colours
113
+ return i
114
+ end
115
+
116
+ # ========================================================================= #
117
+ # === sdir
118
+ # ========================================================================= #
119
+ def sdir(i = '')
120
+ return Colours.sdir(i) if @use_colours
121
+ return i
122
+ end
123
+
124
+ end