excavate 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +20 -3
- data/excavate.gemspec +1 -0
- data/exe/excavate +7 -0
- data/lib/excavate.rb +2 -0
- data/lib/excavate/archive.rb +18 -3
- data/lib/excavate/cli.rb +50 -0
- data/lib/excavate/version.rb +1 -1
- metadata +23 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '05638165852fcf0b41aa72e491d285182a11d2b5989cdee78393ff3f8719a017'
|
4
|
+
data.tar.gz: b3a9e906c6dd35274e0e2b7a7e90f5c10ea8447b0f77c0b0cd59b277d224c06d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eea36c08d18780f9131875d3ca78c33bdf558c957425d9b936f08eb1512bb298724f68f418edb3b3db0c941e228e11473826ad6a16b6fcf399935f73be03514
|
7
|
+
data.tar.gz: 371061bead10a3716b931a9877153c3ea47e8666030fbb0dc7885217da32428f7f43298ec0a98a7fc0f2ef2ffd7a51af5e7371eedbee06f19d34b7a5995b8e3d
|
data/README.adoc
CHANGED
@@ -33,21 +33,38 @@ To extract an archive containing other archives inside:
|
|
33
33
|
|
34
34
|
[source,ruby]
|
35
35
|
----
|
36
|
-
archive = "path/to/archive.cab"
|
37
36
|
target = Dir.mktmpdir
|
38
|
-
Excavate::Archive.new(archive).extract(target, recursive_packages: true)
|
37
|
+
Excavate::Archive.new("path/to/archive.cab").extract(target, recursive_packages: true)
|
39
38
|
----
|
40
39
|
|
41
40
|
The same but allowing to choose only necessary files inside:
|
42
41
|
|
43
42
|
[source,ruby]
|
44
43
|
----
|
44
|
+
target = Dir.mktmpdir
|
45
45
|
Excavate::Archive.new("path/to/archive.cab").files(recursive_packages: true) do |path|
|
46
|
-
FileUtils.mv(path,
|
46
|
+
FileUtils.mv(path, target) if path.end_with?(".txt")
|
47
47
|
end
|
48
48
|
----
|
49
49
|
|
50
50
|
|
51
|
+
== CLI
|
52
|
+
|
53
|
+
`excavate` can be used via command line. To extract an archive including the nested ones:
|
54
|
+
|
55
|
+
[source,sh]
|
56
|
+
----
|
57
|
+
$ excavate --recursive path/to/archive.cab
|
58
|
+
----
|
59
|
+
|
60
|
+
If you'd like to skip extraction of nested archives, just use:
|
61
|
+
|
62
|
+
[source,sh]
|
63
|
+
----
|
64
|
+
$ excavate path/to/archive.cab
|
65
|
+
----
|
66
|
+
|
67
|
+
|
51
68
|
== Development
|
52
69
|
|
53
70
|
We are following Sandi Metz's Rules for this gem, you can read the
|
data/excavate.gemspec
CHANGED
data/exe/excavate
ADDED
data/lib/excavate.rb
CHANGED
data/lib/excavate/archive.rb
CHANGED
@@ -24,16 +24,31 @@ module Excavate
|
|
24
24
|
FileUtils.rm_rf(target)
|
25
25
|
end
|
26
26
|
|
27
|
-
def extract(target, recursive_packages: false)
|
27
|
+
def extract(target = nil, recursive_packages: false)
|
28
|
+
source = File.expand_path(@archive)
|
29
|
+
target ||= default_target(source)
|
30
|
+
raise(TargetNotEmptyError, "Target directory `#{File.basename(target)}` is not empty.") unless Dir.empty?(target)
|
31
|
+
|
28
32
|
if recursive_packages
|
29
|
-
extract_recursively(
|
33
|
+
extract_recursively(source, target)
|
30
34
|
else
|
31
|
-
extract_once(
|
35
|
+
extract_once(source, target)
|
32
36
|
end
|
37
|
+
|
38
|
+
target
|
33
39
|
end
|
34
40
|
|
35
41
|
private
|
36
42
|
|
43
|
+
def default_target(source)
|
44
|
+
target = File.expand_path(File.basename(source, ".*"))
|
45
|
+
raise(TargetExistsError, "Target directory `#{File.basename(target)}` already exists.") if File.exist?(target)
|
46
|
+
|
47
|
+
FileUtils.mkdir(target)
|
48
|
+
|
49
|
+
target
|
50
|
+
end
|
51
|
+
|
37
52
|
def extract_recursively(archive, target)
|
38
53
|
extract_once(archive, target)
|
39
54
|
|
data/lib/excavate/cli.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
require_relative "../excavate"
|
4
|
+
|
5
|
+
module Excavate
|
6
|
+
class CLI < Thor
|
7
|
+
STATUS_SUCCESS = 0
|
8
|
+
STATUS_UNKNOWN_ERROR = 1
|
9
|
+
STATUS_TARGET_EXISTS = 2
|
10
|
+
STATUS_TARGET_NOT_EMPTY = 3
|
11
|
+
|
12
|
+
def self.exit_on_failure?
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.start(given_args = ARGV, config = {})
|
17
|
+
args = if all_commands.key?(given_args[0])
|
18
|
+
given_args
|
19
|
+
else
|
20
|
+
given_args.dup.unshift("extract")
|
21
|
+
end
|
22
|
+
|
23
|
+
super(args, config)
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "extract ARCHIVE", "Extract ARCHIVE to a new directory"
|
27
|
+
option :recursive, aliases: :r, type: :boolean, default: false, desc: "Also extract all nested archives."
|
28
|
+
def extract(archive)
|
29
|
+
target = Excavate::Archive.new(archive).extract(recursive_packages: options[:recursive])
|
30
|
+
success("Successfully extracted to #{File.basename(target)}/")
|
31
|
+
rescue TargetExistsError => e
|
32
|
+
error(e.message, STATUS_TARGET_EXISTS)
|
33
|
+
rescue TargetNotEmptyError => e
|
34
|
+
error(e.message, STATUS_TARGET_NOT_EMPTY)
|
35
|
+
end
|
36
|
+
default_task :extract
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def success(message)
|
41
|
+
say(message)
|
42
|
+
STATUS_SUCCESS
|
43
|
+
end
|
44
|
+
|
45
|
+
def error(message, status)
|
46
|
+
say(message, :red)
|
47
|
+
status
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/excavate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: excavate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: arr-pm
|
@@ -80,10 +80,25 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
83
97
|
description: Extract nested archives with a single command.
|
84
98
|
email:
|
85
99
|
- open.source@ribose.com
|
86
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- excavate
|
87
102
|
extensions: []
|
88
103
|
extra_rdoc_files: []
|
89
104
|
files:
|
@@ -97,8 +112,10 @@ files:
|
|
97
112
|
- README.adoc
|
98
113
|
- Rakefile
|
99
114
|
- excavate.gemspec
|
115
|
+
- exe/excavate
|
100
116
|
- lib/excavate.rb
|
101
117
|
- lib/excavate/archive.rb
|
118
|
+
- lib/excavate/cli.rb
|
102
119
|
- lib/excavate/extractors.rb
|
103
120
|
- lib/excavate/extractors/cab_extractor.rb
|
104
121
|
- lib/excavate/extractors/cpio/cpio.rb
|
@@ -121,7 +138,7 @@ metadata:
|
|
121
138
|
homepage_uri: https://github.com/fontist/excavate
|
122
139
|
source_code_uri: https://github.com/fontist/excavate
|
123
140
|
changelog_uri: https://github.com/fontist/excavate
|
124
|
-
post_install_message:
|
141
|
+
post_install_message:
|
125
142
|
rdoc_options: []
|
126
143
|
require_paths:
|
127
144
|
- lib
|
@@ -137,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
154
|
version: '0'
|
138
155
|
requirements: []
|
139
156
|
rubygems_version: 3.0.3
|
140
|
-
signing_key:
|
157
|
+
signing_key:
|
141
158
|
specification_version: 4
|
142
159
|
summary: Extract nested archives with a single command.
|
143
160
|
test_files: []
|