epdiff 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3edd747165f0606765c30d7248d38fd9ec4cc520
4
+ data.tar.gz: 828bd050102f0b1d226fac87473395efccb9b130
5
+ SHA512:
6
+ metadata.gz: 32692e555d3bd5b498e879587bc7631904f83b7aeb6a4226edae08b0f314f258eca5e1b7e9dd9730ab22438cacd8e811f74cef4f27798c345933b4a0ff726124
7
+ data.tar.gz: 553bceb158a5d5654dbc436ebabc12bff98d9c86f789df060eb98e9371fa8fbe75a84a17807d5c31a7bd938dad440d96a3d4174ef9c1c9b0c2a97c08b79a39e1
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in epdiff.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/epdiff ADDED
@@ -0,0 +1,2 @@
1
+ require 'epdiff'
2
+ Epdiff.execute(*ARGV)
data/epdiff.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "epdiff/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "epdiff"
7
+ s.version = Epdiff::VERSION
8
+ s.authors = ["takahashim"]
9
+ s.email = ["maki@rubycolor.org"]
10
+ s.homepage = ""
11
+ s.summary = %q{diff command for EPUB files.}
12
+ s.description = %q{diff command for EPUB files.}
13
+
14
+ s.rubyforge_project = "epdiff"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ s.add_runtime_dependency "rubyzip", "~> 1.1.0"
21
+ end
data/lib/epdiff.rb ADDED
@@ -0,0 +1,86 @@
1
+ require "epdiff/version"
2
+ require 'optparse'
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+ require 'zip'
6
+
7
+ module Epdiff
8
+ extend self
9
+
10
+ def unzip(filename, dir)
11
+ Zip::InputStream.open(filename) do |zio|
12
+ while (entry = zio.get_next_entry)
13
+ entry_filename = File.join(dir, entry.name)
14
+ FileUtils.mkdir_p File.dirname(entry_filename)
15
+ File.open(entry_filename, "wb") do |f|
16
+ f.write zio.read
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ def execute(*args)
23
+
24
+ tmpdir = Dir.mktmpdir
25
+ diff_path = "diff"
26
+ unzip_path = nil
27
+
28
+ opts = OptionParser.new do |opts|
29
+ opts.banner = "Usage: epdiff [options] [filename] [filename]\n"
30
+
31
+ opts.on('-t','--tmpdir DIR', 'Set tepmorary directory') do |dir|
32
+ tmpdir = dir
33
+ end
34
+
35
+ opts.on('--diff-command PATH', 'Specify diff command path') do |path|
36
+ diff_path = path
37
+ end
38
+
39
+ opts.on('--unzip-command PATH', 'Specify unzip command path') do |path|
40
+ unzip_path = path
41
+ end
42
+
43
+ opts.on('-h', '--help', 'Show this help message') do
44
+ puts opts
45
+ exit
46
+ end
47
+
48
+ opts.on('-v', '--version', 'Show version number') do
49
+ puts Epdiff::VERSION
50
+ exit
51
+ end
52
+ end
53
+
54
+ begin
55
+
56
+ opts.parse!(args)
57
+
58
+ if args.size != 2
59
+ # invalid option
60
+ puts opts
61
+ exit
62
+ end
63
+
64
+ file1, file2 = *args
65
+ FileUtils.mkdir_p(tmpdir+"/file1")
66
+ FileUtils.mkdir_p(tmpdir+"/file2")
67
+
68
+ if unzip_path
69
+ %x("#{unzip_path}" "#{file1}" -d "#{tmpdir}/file1")
70
+ %x("#{unzip_path}" "#{file2}" -d "#{tmpdir}/file2")
71
+ else
72
+ unzip(file1, "#{tmpdir}/file1")
73
+ unzip(file2, "#{tmpdir}/file2")
74
+ end
75
+
76
+ IO.popen("'#{diff_path}' -r -u '#{tmpdir}/file1' '#{tmpdir}/file2'") do |io|
77
+ print io.read.gsub(/#{Regexp.escape(tmpdir)}/, "")
78
+ end
79
+
80
+ rescue => e
81
+ warn e
82
+ puts opts
83
+ end
84
+ end
85
+
86
+ end
@@ -0,0 +1,3 @@
1
+ module Epdiff
2
+ VERSION = "1.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: epdiff
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - takahashim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubyzip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ description: diff command for EPUB files.
28
+ email:
29
+ - maki@rubycolor.org
30
+ executables:
31
+ - epdiff
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - Gemfile
37
+ - Rakefile
38
+ - bin/epdiff
39
+ - epdiff.gemspec
40
+ - lib/epdiff.rb
41
+ - lib/epdiff/version.rb
42
+ homepage: ''
43
+ licenses: []
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project: epdiff
61
+ rubygems_version: 2.1.5
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: diff command for EPUB files.
65
+ test_files: []