duplicated_filename_checker 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +78 -0
- data/Rakefile +9 -0
- data/bin/dup-filename +20 -0
- data/duplicated_filename_checker.gemspec +24 -0
- data/lib/duplicated_filename_checker.rb +6 -0
- data/lib/duplicated_filename_checker/check.rb +36 -0
- data/lib/duplicated_filename_checker/file_profile.rb +19 -0
- data/lib/duplicated_filename_checker/version.rb +3 -0
- data/test/minitest_helper.rb +17 -0
- data/test/sample_for_test/dir_a1/duplicate_filename.sample +1 -0
- data/test/sample_for_test/dir_b1/dir_b2/duplicate_filename.sample +1 -0
- data/test/test_check.rb +28 -0
- data/test/test_file_profile.rb +24 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a702495c905bd44346916ee09d8e24c7abb0615
|
4
|
+
data.tar.gz: c49ed7dbf3a1659cb5231af315dc3d367e8b6893
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b423ef8e3882fa8367e6cd1690e965938c3e8c68cd580adc4b9de7560e3efee212d537518b085c3722249cbe5013759eb6d8a233142a7e367ee8a15d6f62b84b
|
7
|
+
data.tar.gz: 578eec4739ae1f619cca5d3acfceda0601179c0295f5b05c812f5540126e4148cfab18e9c782719c31d105c13063003dc33c47cbd66c8196895ada65c189ca09
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Shinya131
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/Shinya131/duplicated_filename_checker.svg?branch=master)](https://travis-ci.org/Shinya131/duplicated_filename_checker)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/Shinya131/duplicated_filename_checker/badge.svg?branch=master)](https://coveralls.io/r/Shinya131/duplicated_filename_checker?branch=master)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/Shinya131/duplicated_filename_checker/badges/gpa.svg)](https://codeclimate.com/github/Shinya131/duplicated_filename_checker)
|
4
|
+
|
5
|
+
# DuplicatedFilenameChecker
|
6
|
+
|
7
|
+
`duplicated_filename_checker` is duplicate file name checker in multiple directory with subdirectory.
|
8
|
+
This tool is checking only filename, not checking file content.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
install:
|
13
|
+
|
14
|
+
$ gem install duplicated_filename_checker
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
```
|
18
|
+
$ dup-filename ./survey_dir1_root ./survey_dir2_root
|
19
|
+
|
20
|
+
## dupfilename1.png
|
21
|
+
/Users/shinya131/survey_dir1_root/dupfilename1.png
|
22
|
+
/Users/shinya131/survey_dir2_root/subdirectory/dupfilename1.png
|
23
|
+
|
24
|
+
## dupfilename2.png
|
25
|
+
/Users/shinya131/survey_dir1_root/dupfilename2.png
|
26
|
+
/Users/shinya131/survey_dir1_root/dupfilename2.png
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage `duplicated_filename_checker` as library
|
30
|
+
|
31
|
+
You can use `duplicated_filename_checker` in ruby program.
|
32
|
+
|
33
|
+
#### install
|
34
|
+
|
35
|
+
Add this line to your application's Gemfile:
|
36
|
+
```ruby
|
37
|
+
gem 'duplicated_filename_checker'
|
38
|
+
```
|
39
|
+
|
40
|
+
And then execute:
|
41
|
+
|
42
|
+
$ bundle install
|
43
|
+
|
44
|
+
Or install it yourself as:
|
45
|
+
|
46
|
+
$ gem install duplicated_filename_checker
|
47
|
+
|
48
|
+
#### example
|
49
|
+
```ruby
|
50
|
+
require 'duplicated_filename_checker'
|
51
|
+
|
52
|
+
servey_root_paths = ['./survey_dir1_root', './survey_dir2_root']
|
53
|
+
duplicate_file_profile_list = DuplicatedFilenameChecker::Check.new(*servey_root_paths).execute
|
54
|
+
|
55
|
+
p duplicate_file_profile_list
|
56
|
+
#=>
|
57
|
+
# {
|
58
|
+
# "dupfilename1.png"=>
|
59
|
+
# [
|
60
|
+
# #<DuplicatedFilenameChecker::FileProfile:0x007f9aa4878188 @file_path=...>,
|
61
|
+
# #<DuplicatedFilenameChecker::FileProfile:0x007f9aa48633a0 @file_path=...>
|
62
|
+
# ],
|
63
|
+
# "dupfilename2.png"=>
|
64
|
+
# [
|
65
|
+
# #<DuplicatedFilenameChecker::FileProfile:0x007f9aa4878160 @file_path=...>,
|
66
|
+
# #<DuplicatedFilenameChecker::FileProfile:0x007f9aa4863210 @file_path=...>
|
67
|
+
# ]
|
68
|
+
# }
|
69
|
+
|
70
|
+
duplicate_file_profiles = duplicate_file_profile_list['dupfilename1.png']
|
71
|
+
duplicate_file_profile = duplicate_file_profiles.first
|
72
|
+
|
73
|
+
p duplicate_file_profiles[0].path
|
74
|
+
#=> /Users/shinya131/survey_dir1_root/dupfilename1.png
|
75
|
+
|
76
|
+
p duplicate_file_profiles[1].path
|
77
|
+
#=> /Users/shinya131/survey_dir2_root/subdirectory/dupfilename1.png
|
78
|
+
```
|
data/Rakefile
ADDED
data/bin/dup-filename
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'duplicated_filename_checker'
|
4
|
+
|
5
|
+
unless ARGV.size > 0
|
6
|
+
raise ArgumentError.new('Specify the argument. Argument is survey target root paths.')
|
7
|
+
end
|
8
|
+
|
9
|
+
servey_root_paths = ARGV
|
10
|
+
duplicated_file_profiles = DuplicatedFilenameChecker::Check.new(*servey_root_paths).execute
|
11
|
+
|
12
|
+
duplicated_file_profiles.each do |basename, file_profiles|
|
13
|
+
puts "## #{basename}"
|
14
|
+
|
15
|
+
file_profiles.each do |file_profile|
|
16
|
+
puts "#{file_profile.path}"
|
17
|
+
end
|
18
|
+
|
19
|
+
puts "\n"
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'duplicated_filename_checker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "duplicated_filename_checker"
|
8
|
+
spec.version = DuplicatedFilenameChecker::VERSION
|
9
|
+
spec.authors = ["Shinya131"]
|
10
|
+
spec.email = ["nagai3mt5b@gmail.com"]
|
11
|
+
spec.summary = "This gem is check duplicated filename in multiple directory."
|
12
|
+
spec.description = "duplicated_filename_checker is check duplicated filename in multiple directory with subdirectory."
|
13
|
+
spec.homepage = "https://github.com/Shinya131/duplicated_filename_checker"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class DuplicatedFilenameChecker::Check
|
2
|
+
def initialize(*survey_direcotry_roots)
|
3
|
+
@survey_target_paths = survey_target_paths_by(survey_direcotry_roots)
|
4
|
+
end
|
5
|
+
|
6
|
+
def execute
|
7
|
+
duplicate_paths.group_by(&:basename)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# select duplicate paths from survey target paths
|
13
|
+
def duplicate_paths
|
14
|
+
@survey_target_paths.select do |path|
|
15
|
+
is_duplicate?(path.basename)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def is_duplicate?(basename)
|
20
|
+
survey_paths_basename_list.count(basename) > 1
|
21
|
+
end
|
22
|
+
|
23
|
+
# Baseames of survey_paths. It list is not uniq.
|
24
|
+
# @example ['basename1', 'basename1', 'basename2', 'basename3']
|
25
|
+
def survey_paths_basename_list
|
26
|
+
@basename_list ||= @survey_target_paths.map(&:basename) #memorize
|
27
|
+
end
|
28
|
+
|
29
|
+
def survey_target_paths_by(root_paths)
|
30
|
+
# get paths in subdirectory
|
31
|
+
paths = root_paths.map{|root| Dir.glob("#{root}/**/*.*") }.flatten
|
32
|
+
|
33
|
+
# exchange to FileProfile
|
34
|
+
paths.map{|path| DuplicatedFilenameChecker::FileProfile.new(path) }
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'digest/md5'
|
2
|
+
|
3
|
+
class DuplicatedFilenameChecker::FileProfile
|
4
|
+
def initialize(file_path)
|
5
|
+
@file_path = file_path
|
6
|
+
end
|
7
|
+
|
8
|
+
def basename
|
9
|
+
File.basename @file_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def path
|
13
|
+
File.absolute_path @file_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def md5_digest
|
17
|
+
Digest::MD5.file(path).to_s
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# coveralls
|
2
|
+
require 'coveralls'
|
3
|
+
Coveralls.wear!
|
4
|
+
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
Coveralls::SimpleCov::Formatter
|
8
|
+
]
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
11
|
+
require 'duplicated_filename_checker'
|
12
|
+
|
13
|
+
require 'minitest/autorun'
|
14
|
+
|
15
|
+
def test_fullpath
|
16
|
+
File.dirname(__FILE__)
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
sample text.
|
@@ -0,0 +1 @@
|
|
1
|
+
sample text.
|
data/test/test_check.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
class TestCheck < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
survey_dir_path_1 = './test/sample_for_test/dir_a1'
|
6
|
+
survey_dir_path_2 = './test/sample_for_test/dir_b1'
|
7
|
+
@sample_filename = 'duplicate_filename.sample'
|
8
|
+
|
9
|
+
@check = DuplicatedFilenameChecker::Check.new(survey_dir_path_1, survey_dir_path_2)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_execute
|
13
|
+
duplicate_file_paths = @check.execute
|
14
|
+
|
15
|
+
assert(duplicate_file_paths.class == Hash)
|
16
|
+
|
17
|
+
# key is duplicate filename
|
18
|
+
basename = duplicate_file_paths.keys.first
|
19
|
+
assert(basename == @sample_filename)
|
20
|
+
|
21
|
+
# value is duplicate file paths
|
22
|
+
filepaths = duplicate_file_paths.values.first
|
23
|
+
|
24
|
+
assert filepaths.all?{ |path| path.class == DuplicatedFilenameChecker::FileProfile }
|
25
|
+
assert filepaths.all?{ |path| path.basename == @sample_filename } # all basename is same
|
26
|
+
assert filepaths.map(&:path) == filepaths.map(&:path).uniq # all path is different
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'minitest_helper'
|
2
|
+
|
3
|
+
class TestFileProfile < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@sample_filename = 'duplicate_filename.sample'
|
6
|
+
@sample_relative_path = File.join('./test/sample_for_test/dir_a1/', @sample_filename)
|
7
|
+
@sample_fullpath = File.join(test_fullpath, 'sample_for_test/dir_a1/', @sample_filename)
|
8
|
+
@sample_md5_digest = '5258bf47639b8f906c1a17aee86c54dd'
|
9
|
+
|
10
|
+
@file_profile = DuplicatedFilenameChecker::FileProfile.new(@sample_relative_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_basename
|
14
|
+
assert @file_profile.basename == @sample_filename
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_path
|
18
|
+
assert @file_profile.path == @sample_fullpath
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_md5_digest
|
22
|
+
assert @file_profile.md5_digest == @sample_md5_digest
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: duplicated_filename_checker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shinya131
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: duplicated_filename_checker is check duplicated filename in multiple
|
56
|
+
directory with subdirectory.
|
57
|
+
email:
|
58
|
+
- nagai3mt5b@gmail.com
|
59
|
+
executables:
|
60
|
+
- dup-filename
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".coveralls.yml"
|
65
|
+
- ".gitignore"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/dup-filename
|
72
|
+
- duplicated_filename_checker.gemspec
|
73
|
+
- lib/duplicated_filename_checker.rb
|
74
|
+
- lib/duplicated_filename_checker/check.rb
|
75
|
+
- lib/duplicated_filename_checker/file_profile.rb
|
76
|
+
- lib/duplicated_filename_checker/version.rb
|
77
|
+
- test/minitest_helper.rb
|
78
|
+
- test/sample_for_test/dir_a1/duplicate_filename.sample
|
79
|
+
- test/sample_for_test/dir_b1/dir_b2/duplicate_filename.sample
|
80
|
+
- test/test_check.rb
|
81
|
+
- test/test_file_profile.rb
|
82
|
+
homepage: https://github.com/Shinya131/duplicated_filename_checker
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.2.0
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: This gem is check duplicated filename in multiple directory.
|
106
|
+
test_files:
|
107
|
+
- test/minitest_helper.rb
|
108
|
+
- test/sample_for_test/dir_a1/duplicate_filename.sample
|
109
|
+
- test/sample_for_test/dir_b1/dir_b2/duplicate_filename.sample
|
110
|
+
- test/test_check.rb
|
111
|
+
- test/test_file_profile.rb
|