file_crawler 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45df35c34f7ff2a5e69f405be973487b8ca554e50e47d978ccd3dc4faa151591
|
4
|
+
data.tar.gz: c4547234a5584dea2643a9e0c9fd2240fef7edb37c08a2ed87a42d84a7edce4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9649659653a60d57256d2133d0fb4334acbbb13add40380cb9790aaf4a4e24bd208894aaaca3ffdf60f67929c4c72a701508bbaf16f3472f7f8cdaf0e508b88e
|
7
|
+
data.tar.gz: 95c70d9348993daa531229ef4e9053dc4ebc2cda2413204ad8b935ceb5cb0c4899392a09a2977ef3aa67fbd0fd2ac55d04b0d1f0433085302cd3d2513c2e8a36
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# FileCrawler
|
2
2
|
|
3
|
+
[](https://rubygems.org/gems/file_crawler) [](https://travis-ci.org/hirohisa/file_crawler)
|
4
|
+
|
3
5
|
## Installation
|
4
6
|
|
5
7
|
Add this line to your application's Gemfile:
|
@@ -18,6 +20,64 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
23
|
+
- Create Instance
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
finder = FileCrawler::Finder.new
|
27
|
+
```
|
28
|
+
|
29
|
+
- Find directories
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
path = '.'
|
33
|
+
|
34
|
+
finder.search(path)
|
35
|
+
p finder.directories #=> ["./bin", "./lib", "./spec", ...]
|
36
|
+
p finder.dirs #=> ["./bin", "./lib", "./spec", ...] # directories's shortname
|
37
|
+
|
38
|
+
finder.search(path, maxdepth: 1)
|
39
|
+
p finder.dirs #=> ["./bin", "./lib", "./spec"]
|
40
|
+
|
41
|
+
finder.search(path, maxdepth: 1, grep: 'sample')
|
42
|
+
p finder.dirs #=> []
|
43
|
+
|
44
|
+
```
|
45
|
+
|
46
|
+
- Create groups per label decided by directory name
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# collect use `directories`
|
50
|
+
# directories = ['/path/path1/[abcd] defg', '/path/path2/(abcd) defg', '/path/path1/test 123', ...
|
51
|
+
finder.collect(regexs: ['[]', '()'])
|
52
|
+
p finder.collections
|
53
|
+
#=> { 'abcd': ['/path/path1/[abcd] defg', '/path/path2/(abcd) defg'], 'test 123': ['/path/path1/test 123'], ... }
|
54
|
+
```
|
55
|
+
|
56
|
+
- Move directory to destination
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
# move use `directories` or `collections`
|
60
|
+
# files = #=> ["./bin", "./lib", ...]
|
61
|
+
destination = '/var'
|
62
|
+
finder.move(destination)
|
63
|
+
|
64
|
+
# ensure destination
|
65
|
+
# [ [from, to], ... ]
|
66
|
+
p finder.targets #=> [["./bin", "/var/bin"] , ["./lib", "/var/lib"], ...]
|
67
|
+
|
68
|
+
# command output
|
69
|
+
p finder.output_mv #=> [ "mv ./bin /var/bin", "mv ./lib /var/lib", ...]
|
70
|
+
|
71
|
+
# run
|
72
|
+
finder.move(destination, dry_run: false)
|
73
|
+
```
|
74
|
+
|
75
|
+
- Chain
|
76
|
+
```ruby
|
77
|
+
finder.search(source, grep: 'sample').collect(regexs: ['[]']).move(destination)
|
78
|
+
```
|
79
|
+
|
80
|
+
|
21
81
|
## Contributing
|
22
82
|
|
23
83
|
Bug reports and pull requests are welcome on GitHub at https://github.com/hirohisa/file_crawler.
|
@@ -6,7 +6,7 @@ module FileCrawler::Finder::Command
|
|
6
6
|
|
7
7
|
def move(destination, options={dry_run: true})
|
8
8
|
tap {
|
9
|
-
target = @collections.empty? ? @
|
9
|
+
target = @collections.empty? ? @directories : @collections
|
10
10
|
fixer = Fixer.new
|
11
11
|
@targets = fixer.make_new_path(target, destination)
|
12
12
|
|
@@ -18,8 +18,8 @@ module FileCrawler::Finder::Command
|
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
return
|
21
|
+
def output_mv
|
22
|
+
return [] if @targets.nil?
|
23
23
|
|
24
24
|
fixer = Fixer.new
|
25
25
|
fixer.make_mv(@targets)
|
@@ -44,7 +44,7 @@ module FileCrawler::Finder::Command
|
|
44
44
|
cmds = []
|
45
45
|
mkdirs = []
|
46
46
|
make_fixed_paths(filepaths).map {|file|
|
47
|
-
mkdirs << "mkdir -p #{File.dirname(file[1])}"
|
47
|
+
mkdirs << "mkdir -p #{File.dirname(file[1]).inspect}"
|
48
48
|
cmds << "mv #{file[0].inspect} #{file[1].inspect}"
|
49
49
|
}
|
50
50
|
|
@@ -5,7 +5,7 @@ module FileCrawler::Finder::Command
|
|
5
5
|
|
6
6
|
def search(path, options={})
|
7
7
|
tap {
|
8
|
-
@
|
8
|
+
@directories = search_directories(path, options)
|
9
9
|
}
|
10
10
|
end
|
11
11
|
|
@@ -16,7 +16,7 @@ module FileCrawler::Finder::Command
|
|
16
16
|
cmd = "find #{path} -maxdepth #{options[:maxdepth]} -type d"
|
17
17
|
end
|
18
18
|
if options[:grep]
|
19
|
-
cmd += "| grep #{options[:grep]}"
|
19
|
+
cmd += "| grep #{options[:grep].inspect}"
|
20
20
|
end
|
21
21
|
|
22
22
|
exec(cmd).each_line {|item|
|
data/lib/file_crawler/finder.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative 'finder/command'
|
|
3
3
|
module FileCrawler
|
4
4
|
|
5
5
|
class Finder
|
6
|
-
|
6
|
+
attr_reader :directories, :dirs, :collections
|
7
7
|
|
8
8
|
include Command::Collect
|
9
9
|
include Command::Move
|
@@ -11,7 +11,10 @@ module FileCrawler
|
|
11
11
|
|
12
12
|
def initialize
|
13
13
|
@rows = []
|
14
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
def dirs
|
17
|
+
@directories
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
data/lib/file_crawler/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: file_crawler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hirohisa Kawasaki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|