smp_tool-cli 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -2
- data/lib/smp_tool/cli/commands/delete.rb +14 -6
- data/lib/smp_tool/cli/commands/extract.rb +26 -0
- data/lib/smp_tool/cli/commands/extract_all.rb +25 -0
- data/lib/smp_tool/cli/commands/list_files.rb +22 -0
- data/lib/smp_tool/cli/commands/new.rb +1 -1
- data/lib/smp_tool/cli/commands.rb +1 -0
- data/lib/smp_tool/cli/executor/base.rb +0 -47
- data/lib/smp_tool/cli/executor/bin_write_mixin.rb +6 -7
- data/lib/smp_tool/cli/executor/deleter.rb +10 -2
- data/lib/smp_tool/cli/executor/extracter_base.rb +2 -2
- data/lib/smp_tool/cli/executor/extracter_raw.rb +17 -0
- data/lib/smp_tool/cli/executor/extracter_raw_all.rb +15 -0
- data/lib/smp_tool/cli/executor/extracter_raw_base.rb +23 -0
- data/lib/smp_tool/cli/executor/extracter_txt.rb +1 -6
- data/lib/smp_tool/cli/executor/extracter_txt_all.rb +1 -6
- data/lib/smp_tool/cli/executor/extracter_txt_base.rb +19 -0
- data/lib/smp_tool/cli/executor/file_list_informer.rb +27 -0
- data/lib/smp_tool/cli/executor/informer.rb +2 -0
- data/lib/smp_tool/cli/executor/squeeze_mixin.rb +16 -0
- data/lib/smp_tool/cli/executor/squeezer.rb +3 -2
- data/lib/smp_tool/cli/executor/vol_read_operator.rb +3 -28
- data/lib/smp_tool/cli/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3149aa9dc1f632c851d3eb26f0a7789a793915fade6999067efa2869b2190e38
|
4
|
+
data.tar.gz: 71b57cabecc20c1a3ef3f45f69a44a908349ee3a91783d54f911a42c3c10f58a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e558d4ce08db06194481a202b21e42b9e350a346f4c0819dfa493d25e1b06dbf3ed3ce83934c6aff390210d81465c8a3e3f37bde6ede2079cd1fa87f859d3efe
|
7
|
+
data.tar.gz: 60fca9c7337d7934b8b8f9270d8e9db3cdd57b2fe04eb48f133b91a2564cfb75cbe935a16597c17ffe9c5f13fca47dc0f933002ed5cafbf2f340807162832099
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
+
## [0.2.1] - 2024-03-18
|
2
|
+
|
3
|
+
* bug fix: file read/write on MS Windows
|
4
|
+
|
5
|
+
## [0.2.0] - 2024-03-17
|
6
|
+
|
7
|
+
* `--raw` option for the extract command
|
8
|
+
* more advanced `delete` command
|
9
|
+
|
1
10
|
## [0.1.1] - 2024-03-15
|
2
11
|
|
3
|
-
|
12
|
+
* Few changes in the UI
|
4
13
|
|
5
14
|
## [0.1.0] - 2024-03-14
|
6
15
|
|
7
|
-
|
16
|
+
* Initial release
|
@@ -4,20 +4,28 @@ module SMPTool
|
|
4
4
|
module CLI
|
5
5
|
module Commands
|
6
6
|
#
|
7
|
-
# Delete
|
7
|
+
# Delete file(s) from the volume.
|
8
8
|
#
|
9
9
|
class Delete < VolumeOperation
|
10
|
-
desc "Delete
|
10
|
+
desc "Delete files from the volume"
|
11
11
|
|
12
|
-
option :
|
12
|
+
option :f_list,
|
13
|
+
type: :array,
|
13
14
|
required: true,
|
14
|
-
desc: "File to delete",
|
15
|
+
desc: "File(s) to delete",
|
15
16
|
aliases: ["-f"]
|
16
17
|
|
17
|
-
|
18
|
+
option :squeeze,
|
19
|
+
type: :boolean,
|
20
|
+
required: false,
|
21
|
+
default: false,
|
22
|
+
desc: "When done, perform the `squeeze` operation",
|
23
|
+
aliases: ["-s"]
|
24
|
+
|
25
|
+
def call(input:, f_list:, **options)
|
18
26
|
Executor::Deleter.new(
|
19
27
|
input: input,
|
20
|
-
|
28
|
+
f_list: f_list,
|
21
29
|
logger: _logger(options[:verbosity]),
|
22
30
|
**options
|
23
31
|
).call
|
@@ -21,7 +21,24 @@ module SMPTool
|
|
21
21
|
desc: "File(s) to extract",
|
22
22
|
aliases: ["-f"]
|
23
23
|
|
24
|
+
option :raw,
|
25
|
+
type: :boolean,
|
26
|
+
default: false,
|
27
|
+
required: false,
|
28
|
+
desc: "Extract as raw data",
|
29
|
+
aliases: ["-r"]
|
30
|
+
|
24
31
|
def call(input:, f_list:, **options)
|
32
|
+
if options[:raw]
|
33
|
+
_extract_raw(input: input, f_list: f_list, **options)
|
34
|
+
else
|
35
|
+
_extract_txt(input: input, f_list: f_list, **options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def _extract_txt(input:, f_list:, **options)
|
25
42
|
Executor::ExtracterTxt.new(
|
26
43
|
input: input,
|
27
44
|
f_list: f_list,
|
@@ -29,6 +46,15 @@ module SMPTool
|
|
29
46
|
**options
|
30
47
|
).call
|
31
48
|
end
|
49
|
+
|
50
|
+
def _extract_raw(input:, f_list:, **options)
|
51
|
+
Executor::ExtracterRaw.new(
|
52
|
+
input: input,
|
53
|
+
f_list: f_list,
|
54
|
+
logger: _logger(options[:verbosity]),
|
55
|
+
**options
|
56
|
+
).call
|
57
|
+
end
|
32
58
|
end
|
33
59
|
end
|
34
60
|
end
|
@@ -15,13 +15,38 @@ module SMPTool
|
|
15
15
|
desc: "Output directory",
|
16
16
|
aliases: ["-d"]
|
17
17
|
|
18
|
+
option :raw,
|
19
|
+
type: :boolean,
|
20
|
+
default: false,
|
21
|
+
required: false,
|
22
|
+
desc: "Extract as raw data",
|
23
|
+
aliases: ["-r"]
|
24
|
+
|
18
25
|
def call(input:, **options)
|
26
|
+
if options[:raw]
|
27
|
+
_extract_raw(input: input, **options)
|
28
|
+
else
|
29
|
+
_extract_txt(input: input, **options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def _extract_txt(input:, **options)
|
19
36
|
Executor::ExtracterTxtAll.new(
|
20
37
|
input: input,
|
21
38
|
logger: _logger(options[:verbosity]),
|
22
39
|
**options
|
23
40
|
).call
|
24
41
|
end
|
42
|
+
|
43
|
+
def _extract_raw(input:, **options)
|
44
|
+
Executor::ExtracterRawAll.new(
|
45
|
+
input: input,
|
46
|
+
logger: _logger(options[:verbosity]),
|
47
|
+
**options
|
48
|
+
).call
|
49
|
+
end
|
25
50
|
end
|
26
51
|
end
|
27
52
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SMPTool
|
4
|
+
module CLI
|
5
|
+
module Commands
|
6
|
+
#
|
7
|
+
# Command to list files.
|
8
|
+
#
|
9
|
+
class ListFiles < InputCommand
|
10
|
+
desc "List all files on the volume"
|
11
|
+
|
12
|
+
def call(input:, **options)
|
13
|
+
Executor::FileListInformer.new(
|
14
|
+
input: input,
|
15
|
+
logger: _logger(options[:verbosity]),
|
16
|
+
**options
|
17
|
+
).call
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -18,6 +18,7 @@ module SMPTool
|
|
18
18
|
register "rename", Rename, aliases: ["r"]
|
19
19
|
register "resize", Resize, aliases: ["z"]
|
20
20
|
register "squeeze", Squeeze, aliases: ["s"]
|
21
|
+
register "list", ListFiles, aliases: ["l"]
|
21
22
|
|
22
23
|
register "version", Version, aliases: ["-v", "--version"]
|
23
24
|
end
|
@@ -12,53 +12,6 @@ module SMPTool
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def call; end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
#
|
19
|
-
# Save volume to a binary file.
|
20
|
-
#
|
21
|
-
# @param [String] path
|
22
|
-
# Path to the destination file.
|
23
|
-
#
|
24
|
-
# @param [SMPTool::VirtualVolume::Volume] volume
|
25
|
-
#
|
26
|
-
# @param [Hash{ Symbol => Object }] **_options
|
27
|
-
#
|
28
|
-
def _save_volume(path:, volume:, **_options)
|
29
|
-
b_str = _volume_to_binary(volume)
|
30
|
-
@logger.debug "Converted to binary string."
|
31
|
-
|
32
|
-
_write_bin_file(
|
33
|
-
path,
|
34
|
-
b_str
|
35
|
-
)
|
36
|
-
|
37
|
-
@logger.info "Changes saved to the file: '#{path}'"
|
38
|
-
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# Convert virtual volume to binary string.
|
42
|
-
#
|
43
|
-
# @param [SMPTool::VirtualVolume::Volume] volume
|
44
|
-
#
|
45
|
-
# @return [String]
|
46
|
-
#
|
47
|
-
def _volume_to_binary(volume)
|
48
|
-
volume.to_binary_s
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
# Write data to a binary file.
|
53
|
-
#
|
54
|
-
# @param [String] path
|
55
|
-
#
|
56
|
-
# @param [String] data
|
57
|
-
# Binary string with the file's content.
|
58
|
-
#
|
59
|
-
def _write_bin_file(path, data)
|
60
|
-
Dry::Files.new.write(path, data)
|
61
|
-
end
|
62
15
|
end
|
63
16
|
end
|
64
17
|
end
|
@@ -17,12 +17,12 @@ module SMPTool
|
|
17
17
|
# @param [Hash{ Symbol => Object }] **_options
|
18
18
|
#
|
19
19
|
def _save_volume(path:, volume:, **_options)
|
20
|
-
|
21
|
-
@logger.debug "Converted to
|
20
|
+
bin_obj = volume.to_volume_io
|
21
|
+
@logger.debug "Converted to VolumeIO of #{bin_obj.num_bytes} bytes"
|
22
22
|
|
23
23
|
_write_bin_file(
|
24
24
|
path,
|
25
|
-
|
25
|
+
bin_obj
|
26
26
|
)
|
27
27
|
|
28
28
|
@logger.es_info "Changes saved to the file: '#{path}'"
|
@@ -44,11 +44,10 @@ module SMPTool
|
|
44
44
|
#
|
45
45
|
# @param [String] path
|
46
46
|
#
|
47
|
-
# @param [
|
48
|
-
# Binary string with the file's content.
|
47
|
+
# @param [Object] bin_obj
|
49
48
|
#
|
50
|
-
def _write_bin_file(path,
|
51
|
-
|
49
|
+
def _write_bin_file(path, bin_obj)
|
50
|
+
File.open(path, "wb") { |file| bin_obj.write(file) }
|
52
51
|
end
|
53
52
|
end
|
54
53
|
end
|
@@ -4,9 +4,17 @@ module SMPTool
|
|
4
4
|
module CLI
|
5
5
|
module Executor
|
6
6
|
class Deleter < VolReadWriteOperator
|
7
|
+
include SqueezeMixin
|
8
|
+
|
7
9
|
def call
|
8
|
-
|
9
|
-
|
10
|
+
@options[:f_list].each do |file|
|
11
|
+
fn = @volume.f_delete(file)
|
12
|
+
@logger.info "File '#{fn}' was deleted from the volume"
|
13
|
+
end
|
14
|
+
|
15
|
+
@logger.es_info "#{@options[:f_list].length} files were deleted from the volume"
|
16
|
+
|
17
|
+
_squeeze if @options[:squeeze]
|
10
18
|
|
11
19
|
super
|
12
20
|
end
|
@@ -19,7 +19,7 @@ module SMPTool
|
|
19
19
|
|
20
20
|
f_arr.each do |f|
|
21
21
|
path = dry_files.join(@options[:dir], _filter_filename(f.filename))
|
22
|
-
|
22
|
+
_save_file(path, f)
|
23
23
|
@logger.info "File '#{path}' created"
|
24
24
|
end
|
25
25
|
|
@@ -34,7 +34,7 @@ module SMPTool
|
|
34
34
|
base + ext
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def _save_file(path, _file_obj); end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SMPTool
|
4
|
+
module CLI
|
5
|
+
module Executor
|
6
|
+
class ExtracterRaw < ExtracterRawBase
|
7
|
+
private
|
8
|
+
|
9
|
+
def _extract_files
|
10
|
+
@options[:f_list].map do |fn|
|
11
|
+
@volume.f_extract_raw(fn)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SMPTool
|
4
|
+
module CLI
|
5
|
+
module Executor
|
6
|
+
class ExtracterRawBase < ExtracterBase
|
7
|
+
private
|
8
|
+
|
9
|
+
def _save_file(path, file_obj)
|
10
|
+
_write_data(path, file_obj.data)
|
11
|
+
end
|
12
|
+
|
13
|
+
def _write_data(path, data)
|
14
|
+
File.binwrite(path, data)
|
15
|
+
end
|
16
|
+
|
17
|
+
def _filter_filename(filename)
|
18
|
+
"#{super}.bin"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module SMPTool
|
4
4
|
module CLI
|
5
5
|
module Executor
|
6
|
-
class ExtracterTxt <
|
6
|
+
class ExtracterTxt < ExtracterTxtBase
|
7
7
|
private
|
8
8
|
|
9
9
|
def _extract_files
|
@@ -11,11 +11,6 @@ module SMPTool
|
|
11
11
|
@volume.f_extract_txt(fn)
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
15
|
-
def _write_file(path, file_obj)
|
16
|
-
dry_files = Dry::Files.new
|
17
|
-
dry_files.write(path, file_obj.data.join("\n"))
|
18
|
-
end
|
19
14
|
end
|
20
15
|
end
|
21
16
|
end
|
@@ -3,17 +3,12 @@
|
|
3
3
|
module SMPTool
|
4
4
|
module CLI
|
5
5
|
module Executor
|
6
|
-
class ExtracterTxtAll <
|
6
|
+
class ExtracterTxtAll < ExtracterTxtBase
|
7
7
|
private
|
8
8
|
|
9
9
|
def _extract_files
|
10
10
|
@volume.f_extract_txt_all
|
11
11
|
end
|
12
|
-
|
13
|
-
def _write_file(path, file_obj)
|
14
|
-
dry_files = Dry::Files.new
|
15
|
-
dry_files.write(path, file_obj.data.join("\n"))
|
16
|
-
end
|
17
12
|
end
|
18
13
|
end
|
19
14
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SMPTool
|
4
|
+
module CLI
|
5
|
+
module Executor
|
6
|
+
class ExtracterTxtBase < ExtracterBase
|
7
|
+
private
|
8
|
+
|
9
|
+
def _save_file(path, file_obj)
|
10
|
+
_write_data(path, file_obj.data.join("\n"))
|
11
|
+
end
|
12
|
+
|
13
|
+
def _write_data(path, data)
|
14
|
+
File.binwrite(path, data)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SMPTool
|
4
|
+
module CLI
|
5
|
+
module Executor
|
6
|
+
#
|
7
|
+
# Lists files on the volume.
|
8
|
+
#
|
9
|
+
class FileListInformer < VolReadOperator
|
10
|
+
def call
|
11
|
+
snapshot = @volume.snapshot
|
12
|
+
|
13
|
+
_list_files(snapshot[:volume_data])
|
14
|
+
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def _list_files(vol_data)
|
21
|
+
vol_data.reject { |e| e[:status] == "empty" }
|
22
|
+
.each { |e| puts e[:filename] }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SMPTool
|
4
|
+
module CLI
|
5
|
+
module Executor
|
6
|
+
module SqueezeMixin
|
7
|
+
private
|
8
|
+
|
9
|
+
def _squeeze
|
10
|
+
n_free_clusters = @volume.squeeze
|
11
|
+
@logger.es_info "#{n_free_clusters} clusters were joined into one section at the end of the volume"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -4,9 +4,10 @@ module SMPTool
|
|
4
4
|
module CLI
|
5
5
|
module Executor
|
6
6
|
class Squeezer < VolReadWriteOperator
|
7
|
+
include SqueezeMixin
|
8
|
+
|
7
9
|
def call
|
8
|
-
|
9
|
-
@logger.es_info "#{n_free_clusters} clusters were joined into one section at the end of the volume"
|
10
|
+
_squeeze
|
10
11
|
|
11
12
|
super
|
12
13
|
end
|
@@ -30,39 +30,14 @@ module SMPTool
|
|
30
30
|
# @return [SMPTool::VirtualVolume::Volume]
|
31
31
|
#
|
32
32
|
def _load_volume(path:, **_options)
|
33
|
-
|
34
|
-
@logger.info "Read data from the file: '#{path}'"
|
35
|
-
|
36
|
-
vol = _parse_volume(b_str)
|
37
|
-
@logger.debug "Volume parsed"
|
33
|
+
io = File.binread(path)
|
38
34
|
|
39
|
-
|
40
|
-
end
|
35
|
+
@logger.info "Read data from the file: '#{path}'"
|
41
36
|
|
42
|
-
#
|
43
|
-
# Parse binary string to create a volume obj.
|
44
|
-
#
|
45
|
-
# @param [String] b_str
|
46
|
-
#
|
47
|
-
# @return [SMPTool::VirtualVolume::Volume]
|
48
|
-
#
|
49
|
-
def _parse_volume(b_str)
|
50
37
|
SMPTool::VirtualVolume::Volume.read_io(
|
51
|
-
|
38
|
+
io
|
52
39
|
)
|
53
40
|
end
|
54
|
-
|
55
|
-
#
|
56
|
-
# Read a binary file.
|
57
|
-
#
|
58
|
-
# @param [String] path
|
59
|
-
#
|
60
|
-
# @return [String]
|
61
|
-
# Binary string with the file's content.
|
62
|
-
#
|
63
|
-
def _read_bin_file(path)
|
64
|
-
Dry::Files.new.read(path)
|
65
|
-
end
|
66
41
|
end
|
67
42
|
end
|
68
43
|
end
|
data/lib/smp_tool/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smp_tool-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 8bit-m8
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-cli
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/smp_tool/cli/commands/extract_all.rb
|
115
115
|
- lib/smp_tool/cli/commands/info.rb
|
116
116
|
- lib/smp_tool/cli/commands/input_command.rb
|
117
|
+
- lib/smp_tool/cli/commands/list_files.rb
|
117
118
|
- lib/smp_tool/cli/commands/new.rb
|
118
119
|
- lib/smp_tool/cli/commands/push.rb
|
119
120
|
- lib/smp_tool/cli/commands/rename.rb
|
@@ -127,13 +128,19 @@ files:
|
|
127
128
|
- lib/smp_tool/cli/executor/creator.rb
|
128
129
|
- lib/smp_tool/cli/executor/deleter.rb
|
129
130
|
- lib/smp_tool/cli/executor/extracter_base.rb
|
131
|
+
- lib/smp_tool/cli/executor/extracter_raw.rb
|
132
|
+
- lib/smp_tool/cli/executor/extracter_raw_all.rb
|
133
|
+
- lib/smp_tool/cli/executor/extracter_raw_base.rb
|
130
134
|
- lib/smp_tool/cli/executor/extracter_txt.rb
|
131
135
|
- lib/smp_tool/cli/executor/extracter_txt_all.rb
|
136
|
+
- lib/smp_tool/cli/executor/extracter_txt_base.rb
|
137
|
+
- lib/smp_tool/cli/executor/file_list_informer.rb
|
132
138
|
- lib/smp_tool/cli/executor/informer.rb
|
133
139
|
- lib/smp_tool/cli/executor/operator.rb
|
134
140
|
- lib/smp_tool/cli/executor/pusher.rb
|
135
141
|
- lib/smp_tool/cli/executor/renamer.rb
|
136
142
|
- lib/smp_tool/cli/executor/resizer.rb
|
143
|
+
- lib/smp_tool/cli/executor/squeeze_mixin.rb
|
137
144
|
- lib/smp_tool/cli/executor/squeezer.rb
|
138
145
|
- lib/smp_tool/cli/executor/vol_read_operator.rb
|
139
146
|
- lib/smp_tool/cli/executor/vol_read_write_operator.rb
|