epdiff 1.0.3 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +20 -0
- data/README.md +24 -0
- data/bin/epdiff +2 -0
- data/epdiff.gemspec +2 -0
- data/lib/epdiff.rb +87 -18
- data/lib/epdiff/version.rb +2 -2
- metadata +34 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eafa093559fc567ce2560dbfd67aa6f9b712374167063319a0270002c1b0fcd7
|
4
|
+
data.tar.gz: 0a83e2294ad9e7058f9e386c16150141357596065455a08918d8d534cde40f3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49e7e7a25ae0ba32eb883f7e97b5d21ebffbd254c28ccee7527026be7ba68cf59a31e0b974acd4d75e10a465cbe55e17fae63a71e58129602f7f802c9486a4ce
|
7
|
+
data.tar.gz: 487381af5949d9f08889dc2a5f09c0974f277113368fd72aa2dc245bef4cc894583ce13842e0fe28773c055fe08cc42f6f4b0baa0e70ba7ad68dba915f8d3615
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Masayoshi Takahashi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# epdiff
|
2
|
+
|
3
|
+
`epdiff` is a CLI tool to show diff of EPUB files.
|
4
|
+
|
5
|
+
## usage
|
6
|
+
|
7
|
+
$ epdiff <file1> <file2>
|
8
|
+
|
9
|
+
'file1' and 'file2' are EPUB files.
|
10
|
+
|
11
|
+
|
12
|
+
## Note on Patches/Pull Requests
|
13
|
+
|
14
|
+
* Fork the project.
|
15
|
+
* Make your feature addition or bug fix.
|
16
|
+
* Add tests for it. This is important so I don't break it in a
|
17
|
+
future version unintentionally.
|
18
|
+
* Commit, do not mess with rakefile, version, or history.
|
19
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
20
|
+
* Send me a pull request. Bonus points for topic branches.
|
21
|
+
|
22
|
+
## Copyright
|
23
|
+
|
24
|
+
Copyright (c) 2010 Masayoshi Takahashi. See LICENSE for details.
|
data/bin/epdiff
CHANGED
data/epdiff.gemspec
CHANGED
@@ -16,4 +16,6 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.add_runtime_dependency "rubyzip", "~> 2.3.0"
|
19
|
+
s.add_runtime_dependency "pastel"
|
20
|
+
s.add_runtime_dependency "tty-file"
|
19
21
|
end
|
data/lib/epdiff.rb
CHANGED
@@ -3,30 +3,89 @@ require 'optparse'
|
|
3
3
|
require 'tmpdir'
|
4
4
|
require 'fileutils'
|
5
5
|
require 'zip'
|
6
|
+
require 'pastel'
|
7
|
+
require 'tty/file'
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
|
10
|
+
class Epdiff
|
11
|
+
TEXT_EXT = %w(xhtml html xml opf css txt)
|
12
|
+
|
13
|
+
def self.execute(*args)
|
14
|
+
new.execute(*args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@pastel = Pastel.new(enabled: true)
|
19
|
+
@green = @pastel.green.detach
|
20
|
+
@red = @pastel.red.detach
|
21
|
+
@cyan = @pastel.cyan.detach
|
22
|
+
end
|
9
23
|
|
10
24
|
def unzip(filename, dir)
|
11
25
|
Zip::InputStream.open(filename) do |zio|
|
12
26
|
while entry = zio.get_next_entry
|
13
|
-
|
14
|
-
|
15
|
-
FileUtils.mkdir_p File.dirname(entry_filename)
|
16
|
-
elsif entry.file?
|
27
|
+
if entry.file?
|
28
|
+
entry_filename = File.join(dir, entry.name)
|
17
29
|
FileUtils.mkdir_p File.dirname(entry_filename)
|
18
|
-
File.
|
19
|
-
|
30
|
+
File.binwrite(entry_filename, zio.read)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def show_diff(file1, file2, work_dir)
|
37
|
+
Dir.chdir(work_dir) do
|
38
|
+
files1 = Dir.glob("file1/**/*")
|
39
|
+
files2 = Dir.glob("file2/**/*")
|
40
|
+
files1_s = files1.map{|d| d.sub(%r{^file1/}, '')}
|
41
|
+
files2_s = files2.map{|d| d.sub(%r{^file2/}, '')}
|
42
|
+
files_common = files1_s & files2_s
|
43
|
+
files_common.each do |path|
|
44
|
+
if File.file?("file1/#{path}")
|
45
|
+
if text_file?("file1/#{path}")
|
46
|
+
text_diff(path, "file1/#{path}", "file2/#{path}")
|
47
|
+
else
|
48
|
+
binary_diff(path, "file1/#{path}", "file2/#{path}")
|
20
49
|
end
|
21
50
|
end
|
22
51
|
end
|
52
|
+
(files1_s - files2_s).each do |diff1|
|
53
|
+
print @red.call("DIFF: #{diff1} only exists in 1st.\n")
|
54
|
+
end
|
55
|
+
(files2_s - files1_s).each do |diff2|
|
56
|
+
print @green.call("DIFF: #{diff2} only exists in 2nd.\n")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def text_file?(path)
|
62
|
+
extname = File.extname(path).sub(/\A\./, '')
|
63
|
+
if TEXT_EXT.include?(extname)
|
64
|
+
extname
|
65
|
+
else
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def text_diff(_path, path1, path2)
|
71
|
+
diff = TTY::File.diff(path1, path2, verbose: false)
|
72
|
+
if diff != "No differences found\n"
|
73
|
+
print diff
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def binary_diff(path, path1, path2)
|
78
|
+
content1 = File.binread(path1)
|
79
|
+
content2 = File.binread(path2)
|
80
|
+
if content1 != content2
|
81
|
+
print @cyan.call("DIFF: #{path} has some differences.\n")
|
23
82
|
end
|
24
83
|
end
|
25
84
|
|
26
85
|
def execute(*args)
|
27
86
|
|
28
|
-
tmpdir =
|
29
|
-
diff_path =
|
87
|
+
tmpdir = work_dir = nil
|
88
|
+
diff_path = nil
|
30
89
|
unzip_path = nil
|
31
90
|
|
32
91
|
opts = OptionParser.new do |opts|
|
@@ -65,25 +124,35 @@ module Epdiff
|
|
65
124
|
exit
|
66
125
|
end
|
67
126
|
|
127
|
+
work_dir = tmpdir || Dir.mktmpdir
|
128
|
+
|
68
129
|
file1, file2 = *args
|
69
|
-
FileUtils.mkdir_p(
|
70
|
-
FileUtils.mkdir_p(
|
130
|
+
FileUtils.mkdir_p(work_dir+"/file1")
|
131
|
+
FileUtils.mkdir_p(work_dir+"/file2")
|
71
132
|
|
72
133
|
if unzip_path
|
73
|
-
%x("#{unzip_path}" "#{file1}" -d "#{
|
74
|
-
%x("#{unzip_path}" "#{file2}" -d "#{
|
134
|
+
%x("#{unzip_path}" "#{file1}" -d "#{work_dir}/file1")
|
135
|
+
%x("#{unzip_path}" "#{file2}" -d "#{work_dir}/file2")
|
75
136
|
else
|
76
|
-
unzip(file1, "#{
|
77
|
-
unzip(file2, "#{
|
137
|
+
unzip(file1, "#{work_dir}/file1")
|
138
|
+
unzip(file2, "#{work_dir}/file2")
|
78
139
|
end
|
79
140
|
|
80
|
-
|
81
|
-
|
141
|
+
if diff_path
|
142
|
+
IO.popen("'#{diff_path}' -r -u '#{work_dir}/file1' '#{work_dir}/file2'") do |io|
|
143
|
+
print io.read.gsub(/#{Regexp.escape(work_dir)}/, "")
|
144
|
+
end
|
145
|
+
else
|
146
|
+
show_diff(file1, file2, work_dir)
|
82
147
|
end
|
83
148
|
|
84
149
|
rescue => e
|
85
150
|
warn e
|
86
151
|
puts opts
|
152
|
+
ensure
|
153
|
+
if work_dir && !tmpdir
|
154
|
+
FileUtils.rm_rf(work_dir)
|
155
|
+
end
|
87
156
|
end
|
88
157
|
end
|
89
158
|
|
data/lib/epdiff/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "
|
1
|
+
class Epdiff
|
2
|
+
VERSION = "2.0.0.rc1"
|
3
3
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epdiff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- takahashim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pastel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tty-file
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
description: diff command for EPUB files.
|
28
56
|
email:
|
29
57
|
- maki@rubycolor.org
|
@@ -34,6 +62,8 @@ extra_rdoc_files: []
|
|
34
62
|
files:
|
35
63
|
- ".gitignore"
|
36
64
|
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
37
67
|
- Rakefile
|
38
68
|
- bin/epdiff
|
39
69
|
- epdiff.gemspec
|
@@ -53,9 +83,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
83
|
version: '0'
|
54
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
85
|
requirements:
|
56
|
-
- - "
|
86
|
+
- - ">"
|
57
87
|
- !ruby/object:Gem::Version
|
58
|
-
version:
|
88
|
+
version: 1.3.1
|
59
89
|
requirements: []
|
60
90
|
rubygems_version: 3.1.2
|
61
91
|
signing_key:
|