excavate 0.1.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +24 -3
- data/excavate.gemspec +1 -0
- data/exe/excavate +7 -0
- data/lib/excavate.rb +2 -0
- data/lib/excavate/archive.rb +20 -3
- data/lib/excavate/cli.rb +50 -0
- data/lib/excavate/extractors/cpio_extractor.rb +2 -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: f075e9cc9f1e097abd937e9788c119aa19016fb12e04db6d2848b76343ecb16a
|
4
|
+
data.tar.gz: 549ab0c2572a205f3eaa95715d203741700942361cdb545ea638e7dbb8a7489e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 606fa4dda709f925d779145e4b53b09a310c7cfa98d75cf992e2421eab916acccd1e48c54ae1516509c02ff350c33a54487181842260093d29e8bb70c7b039c7
|
7
|
+
data.tar.gz: 4a4a4ab4d2eb48f76af71b8e1378308fc830de06ed7299339995cac94f90438f7d035b30c73646099ad2d8412a7e04441b72794378953eb94e5d5852f2fb27b9
|
data/README.adoc
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
image:https://img.shields.io/gem/v/excavate.svg["Gem Version", link="https://rubygems.org/gems/excavate"]
|
2
|
+
// image:https://codeclimate.com/github/fontist/expressir/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/fontist/excavate"]
|
3
|
+
image:https://github.com/fontist/excavate/workflows/rspec/badge.svg["Build Status", link="https://github.com/fontist/excavate/actions?workflow=rspec"]
|
4
|
+
|
1
5
|
= Excavate: Ruby gem to extract nested archives
|
2
6
|
|
3
7
|
Extract nested archives with a single command.
|
@@ -33,21 +37,38 @@ To extract an archive containing other archives inside:
|
|
33
37
|
|
34
38
|
[source,ruby]
|
35
39
|
----
|
36
|
-
archive = "path/to/archive.cab"
|
37
40
|
target = Dir.mktmpdir
|
38
|
-
Excavate::Archive.new(archive).extract(target, recursive_packages: true)
|
41
|
+
Excavate::Archive.new("path/to/archive.cab").extract(target, recursive_packages: true)
|
39
42
|
----
|
40
43
|
|
41
44
|
The same but allowing to choose only necessary files inside:
|
42
45
|
|
43
46
|
[source,ruby]
|
44
47
|
----
|
48
|
+
target = Dir.mktmpdir
|
45
49
|
Excavate::Archive.new("path/to/archive.cab").files(recursive_packages: true) do |path|
|
46
|
-
FileUtils.mv(path,
|
50
|
+
FileUtils.mv(path, target) if path.end_with?(".txt")
|
47
51
|
end
|
48
52
|
----
|
49
53
|
|
50
54
|
|
55
|
+
== CLI
|
56
|
+
|
57
|
+
`excavate` can be used via command line. To extract an archive including the nested ones:
|
58
|
+
|
59
|
+
[source,sh]
|
60
|
+
----
|
61
|
+
$ excavate --recursive path/to/archive.cab
|
62
|
+
----
|
63
|
+
|
64
|
+
If you'd like to skip extraction of nested archives, just use:
|
65
|
+
|
66
|
+
[source,sh]
|
67
|
+
----
|
68
|
+
$ excavate path/to/archive.cab
|
69
|
+
----
|
70
|
+
|
71
|
+
|
51
72
|
== Development
|
52
73
|
|
53
74
|
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
|
|
@@ -89,6 +104,8 @@ module Excavate
|
|
89
104
|
end
|
90
105
|
|
91
106
|
def archive?(file)
|
107
|
+
return false unless File.file?(file)
|
108
|
+
|
92
109
|
ext = normalized_extension(file)
|
93
110
|
TYPES.key?(ext)
|
94
111
|
end
|
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
|
@@ -21,6 +21,7 @@ module Excavate
|
|
21
21
|
if entry.directory?
|
22
22
|
FileUtils.mkdir_p(path)
|
23
23
|
else
|
24
|
+
FileUtils.mkdir_p(File.dirname(path))
|
24
25
|
File.write(path, file.read, mode: "wb")
|
25
26
|
end
|
26
27
|
end
|
@@ -34,6 +35,7 @@ module Excavate
|
|
34
35
|
if entry.directory?
|
35
36
|
FileUtils.mkdir_p(path)
|
36
37
|
else
|
38
|
+
FileUtils.mkdir_p(File.dirname(path))
|
37
39
|
File.write(path, entry.data, mode: "wb")
|
38
40
|
end
|
39
41
|
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.
|
4
|
+
version: 0.2.3
|
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-04-01 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: []
|