gren 0.2.2 → 0.2.3
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.
- data/History.ja.txt +78 -0
- data/History.txt +12 -28
- data/Manifest.txt +3 -0
- data/bin/mkgrendb +1 -1
- data/lib/common/display_util.rb +48 -0
- data/lib/findgrep/result.rb +4 -42
- data/lib/gren.rb +1 -1
- data/lib/gren/findgrep.rb +215 -0
- data/lib/mkgrendb/mkgrendb.rb +23 -4
- metadata +7 -3
data/History.ja.txt
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
=== 0.2.3 2010/09/25
|
|
2
|
+
|
|
3
|
+
* mkgrendb
|
|
4
|
+
* ymal入力時にパスを展開していないバグを修正
|
|
5
|
+
* mkgrendbの最後に表示する基本情報を整理
|
|
6
|
+
* 入力ファイル
|
|
7
|
+
* 出力ファイル
|
|
8
|
+
* かかった時間
|
|
9
|
+
* ファイル数
|
|
10
|
+
* 更新ファイル数
|
|
11
|
+
* データベースの生成オプションを整理
|
|
12
|
+
* パトリシア木 .. テーブルの記録方式、ハッシュに比べて遅くなるが、前方一致検索可能に
|
|
13
|
+
* 正規化 .. 各語彙を正規化して登録(大文字、小文字を区別しない)
|
|
14
|
+
* with_position .. 転置索引に出現位置情報を合わせて格納
|
|
15
|
+
|
|
16
|
+
=== 0.2.2 2010/09/14
|
|
17
|
+
|
|
18
|
+
* mkgrendb
|
|
19
|
+
* 複数引数に対応
|
|
20
|
+
* 引数に、.rb, .yamlどちらを渡しても正しく動作するように
|
|
21
|
+
* --ddb, --defaultオプションを追加 (GRENDB_DEFAULT_DBで指定されているデータベースを更新)
|
|
22
|
+
* --dump データベースの中身をダンプする
|
|
23
|
+
* --full データベースを一度削除してから再構築
|
|
24
|
+
* --delete データベースを削除(yamlは消さない)
|
|
25
|
+
* ファイルのタイムスタンプを比較して、すでに更新されているものは再生成しないように
|
|
26
|
+
|
|
27
|
+
=== 0.2.1 2010/09/13
|
|
28
|
+
|
|
29
|
+
* デフォルトのignoreファイル追加 .d, .map, .MAP
|
|
30
|
+
* オプション名変更 : --sub → --not
|
|
31
|
+
|
|
32
|
+
=== 0.2.0 2010/09/13
|
|
33
|
+
|
|
34
|
+
* grooongaを利用して超高速検索を実現した、grendbをリリース
|
|
35
|
+
* mkgrendbでデータベース生成
|
|
36
|
+
* grendbでデータベース検索
|
|
37
|
+
|
|
38
|
+
=== 0.1.4 2010/08/14
|
|
39
|
+
|
|
40
|
+
* snipモード
|
|
41
|
+
* 一行が長過ぎる場合は適当に省略する機能を追加
|
|
42
|
+
* 圧縮したJavascript等で効果を発揮
|
|
43
|
+
|
|
44
|
+
=== 0.1.3 2010/08/13
|
|
45
|
+
|
|
46
|
+
* 含まれない検索、OR検索に対応
|
|
47
|
+
* --subで指定したキーワードは''含まれない''
|
|
48
|
+
* --orで指定したキーワードは''いずれかを含む''
|
|
49
|
+
|
|
50
|
+
* 自動エンコードに対応
|
|
51
|
+
* ファイルの文字コードがばらばらでも、自動的にシェルで使用している文字コードにあわせてくれるようにした
|
|
52
|
+
* -e, --encode ENCODE Specify encode(none, auto, jis, sjis, euc, ascii, utf8, utf16). Default is "auto"
|
|
53
|
+
|
|
54
|
+
=== 0.1.2 2010/08/05
|
|
55
|
+
|
|
56
|
+
* Bug fix.
|
|
57
|
+
* 読み込み禁止ディレクトリがあるとハングアップする問題を修正
|
|
58
|
+
|
|
59
|
+
=== 0.1.1 2010/08/04
|
|
60
|
+
|
|
61
|
+
* --depth, --this(== "--depth 0")、探索する階層数を指定出来るように
|
|
62
|
+
* -sでサイレントモード、マッチした行のみを表示する
|
|
63
|
+
* -f, --if, --idオプションを何個でも設定出来るように
|
|
64
|
+
* -cで色付き表示
|
|
65
|
+
|
|
66
|
+
=== 0.1.0 2010/08/02
|
|
67
|
+
|
|
68
|
+
* Update README.doc (to English).
|
|
69
|
+
|
|
70
|
+
=== 0.0.6 2010/07/29
|
|
71
|
+
|
|
72
|
+
* update github
|
|
73
|
+
* http://github.com/ongaeshi/gren
|
|
74
|
+
|
|
75
|
+
=== 0.0.1 2010-07-22
|
|
76
|
+
|
|
77
|
+
* 1 major enhancement:
|
|
78
|
+
* Initial release
|
data/History.txt
CHANGED
|
@@ -1,52 +1,36 @@
|
|
|
1
|
+
=== 0.2.3 2010/09/25
|
|
2
|
+
|
|
3
|
+
* mkgrendb
|
|
4
|
+
|
|
1
5
|
=== 0.2.2 2010/09/14
|
|
2
6
|
|
|
3
7
|
* mkgrendb
|
|
4
|
-
* 複数引数に対応
|
|
5
|
-
* 引数に、.rb, .yamlどちらを渡しても正しく動作するように
|
|
6
|
-
* --ddb, --defaultオプションを追加 (GRENDB_DEFAULT_DBで指定されているデータベースを更新)
|
|
7
|
-
* --dump データベースの中身をダンプする
|
|
8
|
-
* --full データベースを一度削除してから再構築
|
|
9
|
-
* --delete データベースを削除(yamlは消さない)
|
|
10
|
-
* ファイルのタイムスタンプを比較して、すでに更新されているものは再生成しないように
|
|
11
8
|
|
|
12
9
|
=== 0.2.1 2010/09/13
|
|
13
10
|
|
|
14
|
-
*
|
|
15
|
-
* オプション名変更 : --sub → --not
|
|
11
|
+
* gren
|
|
16
12
|
|
|
17
13
|
=== 0.2.0 2010/09/13
|
|
18
14
|
|
|
19
|
-
*
|
|
20
|
-
* mkgrendbでデータベース生成
|
|
21
|
-
* grendbでデータベース検索
|
|
15
|
+
* grendb
|
|
22
16
|
|
|
23
17
|
=== 0.1.4 2010/08/14
|
|
24
18
|
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* 圧縮したJavascript等で効果を発揮
|
|
19
|
+
* gren
|
|
20
|
+
* snip-mode
|
|
28
21
|
|
|
29
22
|
=== 0.1.3 2010/08/13
|
|
30
23
|
|
|
31
|
-
*
|
|
32
|
-
* --subで指定したキーワードは''含まれない''
|
|
33
|
-
* --orで指定したキーワードは''いずれかを含む''
|
|
34
|
-
|
|
35
|
-
* 自動エンコードに対応
|
|
36
|
-
* ファイルの文字コードがばらばらでも、自動的にシェルで使用している文字コードにあわせてくれるようにした
|
|
37
|
-
* -e, --encode ENCODE Specify encode(none, auto, jis, sjis, euc, ascii, utf8, utf16). Default is "auto"
|
|
24
|
+
* gren
|
|
38
25
|
|
|
39
26
|
=== 0.1.2 2010/08/05
|
|
40
27
|
|
|
41
|
-
*
|
|
42
|
-
*
|
|
28
|
+
* gren
|
|
29
|
+
* Bug fix.
|
|
43
30
|
|
|
44
31
|
=== 0.1.1 2010/08/04
|
|
45
32
|
|
|
46
|
-
*
|
|
47
|
-
* -sでサイレントモード、マッチした行のみを表示する
|
|
48
|
-
* -f, --if, --idオプションを何個でも設定出来るように
|
|
49
|
-
* -cで色付き表示
|
|
33
|
+
* gren
|
|
50
34
|
|
|
51
35
|
=== 0.1.0 2010/08/02
|
|
52
36
|
|
data/Manifest.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
History.ja.txt
|
|
1
2
|
History.txt
|
|
2
3
|
Manifest.txt
|
|
3
4
|
PostInstall.txt
|
|
@@ -6,6 +7,7 @@ Rakefile
|
|
|
6
7
|
bin/gren
|
|
7
8
|
bin/grendb
|
|
8
9
|
bin/mkgrendb
|
|
10
|
+
lib/common/display_util.rb
|
|
9
11
|
lib/common/grenfiletest.rb
|
|
10
12
|
lib/common/grensnip.rb
|
|
11
13
|
lib/common/platform.rb
|
|
@@ -14,6 +16,7 @@ lib/findgrep/findgrep.rb
|
|
|
14
16
|
lib/findgrep/result.rb
|
|
15
17
|
lib/gren.rb
|
|
16
18
|
lib/gren/cli.rb
|
|
19
|
+
lib/gren/findgrep.rb
|
|
17
20
|
lib/grendb/cli.rb
|
|
18
21
|
lib/mkgrendb/cli.rb
|
|
19
22
|
lib/mkgrendb/mkgrendb.rb
|
data/bin/mkgrendb
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
module Gren
|
|
4
|
+
module DisplayUtil
|
|
5
|
+
def time_s(time)
|
|
6
|
+
t = time.truncate
|
|
7
|
+
h = t / 3600
|
|
8
|
+
t = t % 3600
|
|
9
|
+
m = t / 60
|
|
10
|
+
t = t % 60
|
|
11
|
+
t += round(time - time.prec_i, 2)
|
|
12
|
+
|
|
13
|
+
if (h > 0 && m > 0)
|
|
14
|
+
"#{h}h #{m}m #{t}s"
|
|
15
|
+
elsif (m > 0)
|
|
16
|
+
"#{m}m #{t}s"
|
|
17
|
+
else
|
|
18
|
+
"#{t}sec"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
module_function :time_s
|
|
22
|
+
|
|
23
|
+
def round(n, d)
|
|
24
|
+
(n * 10 ** d).round / 10.0 ** d
|
|
25
|
+
end
|
|
26
|
+
module_function :round
|
|
27
|
+
|
|
28
|
+
def size_s(size)
|
|
29
|
+
tb = 1024 ** 4
|
|
30
|
+
gb = 1024 ** 3
|
|
31
|
+
mb = 1024 ** 2
|
|
32
|
+
kb = 1024
|
|
33
|
+
|
|
34
|
+
if (size >= tb)
|
|
35
|
+
round(size / tb.prec_f, 2).to_s + "TB"
|
|
36
|
+
elsif (size >= gb)
|
|
37
|
+
round(size / gb.prec_f, 2).to_s + "GB"
|
|
38
|
+
elsif (size >= mb)
|
|
39
|
+
round(size / mb.prec_f, 2).to_s + "MB"
|
|
40
|
+
elsif (size >= kb)
|
|
41
|
+
round(size / kb.prec_f, 2).to_s + "KB"
|
|
42
|
+
else
|
|
43
|
+
size.to_s + "Byte"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
module_function :size_s
|
|
47
|
+
end
|
|
48
|
+
end
|
data/lib/findgrep/result.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
require 'find'
|
|
3
|
+
require File.join(File.dirname(__FILE__), '../common/display_util')
|
|
4
|
+
include Gren
|
|
3
5
|
|
|
4
6
|
module FindGrep
|
|
5
7
|
class Result
|
|
@@ -31,49 +33,9 @@ module FindGrep
|
|
|
31
33
|
@end_time - @start_time
|
|
32
34
|
end
|
|
33
35
|
|
|
34
|
-
def time_s
|
|
35
|
-
t = time.truncate
|
|
36
|
-
h = t / 3600
|
|
37
|
-
t = t % 3600
|
|
38
|
-
m = t / 60
|
|
39
|
-
t = t % 60
|
|
40
|
-
t += round(time - time.prec_i, 2)
|
|
41
|
-
|
|
42
|
-
if (h > 0 && m > 0)
|
|
43
|
-
"#{h}h #{m}m #{t}s"
|
|
44
|
-
elsif (m > 0)
|
|
45
|
-
"#{m}m #{t}s"
|
|
46
|
-
else
|
|
47
|
-
"#{t}sec"
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def round(n, d)
|
|
52
|
-
(n * 10 ** d).round / 10.0 ** d
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def size_s(size)
|
|
56
|
-
tb = 1024 ** 4
|
|
57
|
-
gb = 1024 ** 3
|
|
58
|
-
mb = 1024 ** 2
|
|
59
|
-
kb = 1024
|
|
60
|
-
|
|
61
|
-
if (size >= tb)
|
|
62
|
-
round(size / tb.prec_f, 2).to_s + "TB"
|
|
63
|
-
elsif (size >= gb)
|
|
64
|
-
round(size / gb.prec_f, 2).to_s + "GB"
|
|
65
|
-
elsif (size >= mb)
|
|
66
|
-
round(size / mb.prec_f, 2).to_s + "MB"
|
|
67
|
-
elsif (size >= kb)
|
|
68
|
-
round(size / kb.prec_f, 2).to_s + "KB"
|
|
69
|
-
else
|
|
70
|
-
size.to_s + "Byte"
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
36
|
def print(stdout)
|
|
75
|
-
stdout.puts "dir : #{@start_dir} (#{time_s})"
|
|
76
|
-
stdout.puts "files : #{@search_count} in #{@count} (#{size_s(@search_size)} in #{size_s(@size)})"
|
|
37
|
+
stdout.puts "dir : #{@start_dir} (#{DisplayUtil::time_s(time)})"
|
|
38
|
+
stdout.puts "files : #{@search_count} in #{@count} (#{DisplayUtil::size_s(@search_size)} in #{DisplayUtil::size_s(@size)})"
|
|
77
39
|
stdout.puts "match : #{@match_file_count} files, #{match_count} hit"
|
|
78
40
|
end
|
|
79
41
|
|
data/lib/gren.rb
CHANGED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
require 'find'
|
|
3
|
+
require File.join(File.dirname(__FILE__), 'result')
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
require 'termcolor'
|
|
6
|
+
|
|
7
|
+
module Gren
|
|
8
|
+
class FindGrep
|
|
9
|
+
IGNORE_FILE = /(\A#.*#\Z)|(~\Z)|(\A\.#)/
|
|
10
|
+
IGNORE_DIR = /(\A\.svn\Z)|(\A\.git\Z)|(\ACVS\Z)/
|
|
11
|
+
|
|
12
|
+
Option = Struct.new(:directory,
|
|
13
|
+
:depth,
|
|
14
|
+
:ignoreCase,
|
|
15
|
+
:colorHighlight,
|
|
16
|
+
:isSilent,
|
|
17
|
+
:debugMode,
|
|
18
|
+
:filePatterns,
|
|
19
|
+
:ignoreFiles,
|
|
20
|
+
:ignoreDirs)
|
|
21
|
+
|
|
22
|
+
def initialize(patterns, option)
|
|
23
|
+
@option = option
|
|
24
|
+
@patternRegexps = strs2regs(patterns, @option.ignoreCase)
|
|
25
|
+
@filePatterns = strs2regs(option.filePatterns)
|
|
26
|
+
@ignoreFiles = strs2regs(option.ignoreFiles)
|
|
27
|
+
@ignoreDirs = strs2regs(option.ignoreDirs)
|
|
28
|
+
@result = Result.new(option.directory)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def strs2regs(strs, ignore = false)
|
|
32
|
+
regs = []
|
|
33
|
+
|
|
34
|
+
strs.each do |v|
|
|
35
|
+
option = 0
|
|
36
|
+
option |= Regexp::IGNORECASE if (ignore)
|
|
37
|
+
regs << Regexp.new(v, option)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
regs
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def searchAndPrint(stdout)
|
|
44
|
+
searchAndPrintIN(stdout, @option.directory, 0)
|
|
45
|
+
|
|
46
|
+
@result.time_stop
|
|
47
|
+
|
|
48
|
+
unless (@option.isSilent)
|
|
49
|
+
if (@option.debugMode)
|
|
50
|
+
stdout.puts
|
|
51
|
+
stdout.puts "--- search --------"
|
|
52
|
+
print_fpaths stdout, @result.search_files
|
|
53
|
+
stdout.puts "--- match --------"
|
|
54
|
+
print_fpaths stdout, @result.match_files
|
|
55
|
+
stdout.puts "--- ignore-file --------"
|
|
56
|
+
print_fpaths stdout, @result.ignore_files
|
|
57
|
+
stdout.puts "--- ignore-dir --------"
|
|
58
|
+
print_fpaths stdout, @result.prune_dirs
|
|
59
|
+
stdout.puts "--- unreadable --------"
|
|
60
|
+
print_fpaths stdout, @result.unreadable_files
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
unless (@option.colorHighlight)
|
|
64
|
+
stdout.puts
|
|
65
|
+
else
|
|
66
|
+
stdout.puts TermColor.parse("<7>------------------------------------------------------------</7>")
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
@result.print(stdout)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def searchAndPrintIN(stdout, dir, depth)
|
|
74
|
+
if (@option.depth != -1 && depth > @option.depth)
|
|
75
|
+
return
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
Dir.foreach(dir) do |name|
|
|
79
|
+
next if (name == '.' || name == '..')
|
|
80
|
+
|
|
81
|
+
fpath = File.join(dir,name)
|
|
82
|
+
fpath_disp = fpath.gsub(/^.\//, "")
|
|
83
|
+
|
|
84
|
+
# 除外ディレクトリならばパス
|
|
85
|
+
if ignoreDir?(fpath)
|
|
86
|
+
@result.prune_dirs << fpath_disp if (@option.debugMode)
|
|
87
|
+
next;
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# 読み込み不可ならばパス
|
|
91
|
+
unless FileTest.readable?(fpath)
|
|
92
|
+
@result.unreadable_files << fpath_disp if (@option.debugMode)
|
|
93
|
+
next
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# ファイルならば中身を探索、ディレクトリならば再帰
|
|
97
|
+
case File.ftype(fpath)
|
|
98
|
+
when "directory"
|
|
99
|
+
searchAndPrintIN(stdout, fpath, depth + 1)
|
|
100
|
+
when "file"
|
|
101
|
+
searchFile(stdout, fpath, fpath_disp)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
private :searchAndPrintIN
|
|
106
|
+
|
|
107
|
+
def print_fpaths(stdout, data)
|
|
108
|
+
stdout.print data.join("\n")
|
|
109
|
+
stdout.puts if data.count > 0
|
|
110
|
+
stdout.puts "total: #{data.count}"
|
|
111
|
+
stdout.puts
|
|
112
|
+
end
|
|
113
|
+
private :print_fpaths
|
|
114
|
+
|
|
115
|
+
def ignoreDir?(fpath)
|
|
116
|
+
FileTest.directory?(fpath) &&
|
|
117
|
+
(IGNORE_DIR.match(File.basename(fpath)) || ignoreDirUser?(fpath))
|
|
118
|
+
end
|
|
119
|
+
private :ignoreDir?
|
|
120
|
+
|
|
121
|
+
def ignoreDirUser?(fpath)
|
|
122
|
+
@ignoreDirs.any? {|v| v.match File.basename(fpath) }
|
|
123
|
+
end
|
|
124
|
+
private :ignoreDirUser?
|
|
125
|
+
|
|
126
|
+
def ignoreFile?(fpath)
|
|
127
|
+
!correctFileUser?(fpath) ||
|
|
128
|
+
IGNORE_FILE.match(File.basename(fpath)) ||
|
|
129
|
+
ignoreFileUser?(fpath) ||
|
|
130
|
+
binary?(fpath)
|
|
131
|
+
end
|
|
132
|
+
private :ignoreFile?
|
|
133
|
+
|
|
134
|
+
def correctFileUser?(fpath)
|
|
135
|
+
@filePatterns.empty? ||
|
|
136
|
+
@filePatterns.any? {|v| v.match File.basename(fpath) }
|
|
137
|
+
end
|
|
138
|
+
private :correctFileUser?
|
|
139
|
+
|
|
140
|
+
def ignoreFileUser?(fpath)
|
|
141
|
+
@ignoreFiles.any? {|v| v.match File.basename(fpath) }
|
|
142
|
+
end
|
|
143
|
+
private :ignoreFileUser?
|
|
144
|
+
|
|
145
|
+
def binary?(file)
|
|
146
|
+
s = File.read(file, 1024) or return false
|
|
147
|
+
return s.index("\x00")
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def searchFile(stdout, fpath, fpath_disp)
|
|
151
|
+
@result.count += 1
|
|
152
|
+
@result.size += FileTest.size(fpath)
|
|
153
|
+
|
|
154
|
+
# 除外ファイル
|
|
155
|
+
if ignoreFile?(fpath)
|
|
156
|
+
@result.ignore_files << fpath_disp if (@option.debugMode)
|
|
157
|
+
return
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
@result.search_count += 1
|
|
161
|
+
@result.search_size += FileTest.size(fpath)
|
|
162
|
+
|
|
163
|
+
# 検索本体
|
|
164
|
+
@result.search_files << fpath_disp if (@option.debugMode)
|
|
165
|
+
|
|
166
|
+
open(fpath, "r") { |file|
|
|
167
|
+
match_file = false
|
|
168
|
+
file.each() { |line|
|
|
169
|
+
line.chomp!
|
|
170
|
+
|
|
171
|
+
result, match_datas = match?(line)
|
|
172
|
+
|
|
173
|
+
if ( result )
|
|
174
|
+
unless (@option.colorHighlight)
|
|
175
|
+
stdout.puts "#{fpath_disp}:#{file.lineno}:#{line}"
|
|
176
|
+
else
|
|
177
|
+
header = "#{fpath_disp}:#{file.lineno}"
|
|
178
|
+
|
|
179
|
+
begin
|
|
180
|
+
stdout.puts TermColor.parse("<34>#{header}</34>:") + coloring(line, match_datas)
|
|
181
|
+
rescue REXML::ParseException
|
|
182
|
+
stdout.puts header + line
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
unless match_file
|
|
187
|
+
@result.match_file_count += 1
|
|
188
|
+
@result.match_files << fpath_disp if (@option.debugMode)
|
|
189
|
+
match_file = true
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
@result.match_count += 1
|
|
193
|
+
end
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
end
|
|
197
|
+
private :searchFile
|
|
198
|
+
|
|
199
|
+
def match?(line)
|
|
200
|
+
match_datas = []
|
|
201
|
+
@patternRegexps.each {|v| match_datas << v.match(line)}
|
|
202
|
+
return match_datas.all?, match_datas
|
|
203
|
+
end
|
|
204
|
+
private :match?
|
|
205
|
+
|
|
206
|
+
def coloring(line, match_datas)
|
|
207
|
+
match_datas.each do |m|
|
|
208
|
+
line = line.split(m[0]).join(TermColor.parse("<42>#{m[0]}</42>"))
|
|
209
|
+
end
|
|
210
|
+
line
|
|
211
|
+
end
|
|
212
|
+
private :coloring
|
|
213
|
+
|
|
214
|
+
end
|
|
215
|
+
end
|
data/lib/mkgrendb/mkgrendb.rb
CHANGED
|
@@ -5,15 +5,20 @@ require 'pathname'
|
|
|
5
5
|
require 'rubygems'
|
|
6
6
|
require 'groonga'
|
|
7
7
|
require File.join(File.dirname(__FILE__), '../common/grenfiletest')
|
|
8
|
+
require File.join(File.dirname(__FILE__), '../common/display_util')
|
|
9
|
+
include Gren
|
|
8
10
|
|
|
9
11
|
module Mkgrendb
|
|
10
12
|
class Mkgrendb
|
|
11
13
|
def initialize(input)
|
|
14
|
+
input = File.expand_path(input)
|
|
12
15
|
@input_yaml = input.sub(/\.db$/, ".yaml")
|
|
13
16
|
@output_db = input.sub(/\.yaml$/, ".db")
|
|
14
17
|
puts "input_yaml : #{@input_yaml} found."
|
|
15
18
|
@src = YAML.load(open(@input_yaml).read())
|
|
16
19
|
@file_count = 0
|
|
20
|
+
@update_count = 0
|
|
21
|
+
@start_time = Time.now
|
|
17
22
|
end
|
|
18
23
|
|
|
19
24
|
def update
|
|
@@ -22,6 +27,8 @@ module Mkgrendb
|
|
|
22
27
|
@src["directory"].each do |dir|
|
|
23
28
|
db_add_dir(File.expand_path(dir))
|
|
24
29
|
end
|
|
30
|
+
@end_time = Time.now
|
|
31
|
+
print_result
|
|
25
32
|
end
|
|
26
33
|
|
|
27
34
|
def delete
|
|
@@ -33,6 +40,18 @@ module Mkgrendb
|
|
|
33
40
|
update
|
|
34
41
|
end
|
|
35
42
|
|
|
43
|
+
def time
|
|
44
|
+
@end_time - @start_time
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def print_result
|
|
48
|
+
puts
|
|
49
|
+
puts "input_yaml : #{@input_yaml} (#{DisplayUtil::time_s(time)})"
|
|
50
|
+
puts "output_db : #{@output_db}*"
|
|
51
|
+
puts "files : #{@file_count}"
|
|
52
|
+
puts "updates : #{@update_count}"
|
|
53
|
+
end
|
|
54
|
+
|
|
36
55
|
def dump()
|
|
37
56
|
db_open(@output_db)
|
|
38
57
|
|
|
@@ -44,7 +63,6 @@ module Mkgrendb
|
|
|
44
63
|
puts "content :", record.content[0..64]
|
|
45
64
|
puts
|
|
46
65
|
end
|
|
47
|
-
|
|
48
66
|
end
|
|
49
67
|
|
|
50
68
|
def db_create(filename)
|
|
@@ -65,9 +83,9 @@ module Mkgrendb
|
|
|
65
83
|
:type => :patricia_trie,
|
|
66
84
|
:key_normalize => true,
|
|
67
85
|
:default_tokenizer => "TokenBigram") do |table|
|
|
68
|
-
table.index("documents.path")
|
|
69
|
-
table.index("documents.content")
|
|
70
|
-
table.index("documents.timestamp")
|
|
86
|
+
table.index("documents.path", :with_position => true)
|
|
87
|
+
table.index("documents.content", :with_position => true)
|
|
88
|
+
table.index("documents.timestamp", :with_position => true)
|
|
71
89
|
end
|
|
72
90
|
end
|
|
73
91
|
puts "create : #{filename} created."
|
|
@@ -139,6 +157,7 @@ module Mkgrendb
|
|
|
139
157
|
if (isNewFile)
|
|
140
158
|
puts "add_file : #{value}"
|
|
141
159
|
else
|
|
160
|
+
@update_count += 1
|
|
142
161
|
puts "update : #{value}"
|
|
143
162
|
end
|
|
144
163
|
end
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 2
|
|
8
|
-
-
|
|
9
|
-
version: 0.2.
|
|
8
|
+
- 3
|
|
9
|
+
version: 0.2.3
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- ongaeshi
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2010-09-
|
|
17
|
+
date: 2010-09-26 00:00:00 +09:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
@@ -83,11 +83,13 @@ executables:
|
|
|
83
83
|
extensions: []
|
|
84
84
|
|
|
85
85
|
extra_rdoc_files:
|
|
86
|
+
- History.ja.txt
|
|
86
87
|
- History.txt
|
|
87
88
|
- Manifest.txt
|
|
88
89
|
- PostInstall.txt
|
|
89
90
|
- README.rdoc
|
|
90
91
|
files:
|
|
92
|
+
- History.ja.txt
|
|
91
93
|
- History.txt
|
|
92
94
|
- Manifest.txt
|
|
93
95
|
- PostInstall.txt
|
|
@@ -96,6 +98,7 @@ files:
|
|
|
96
98
|
- bin/gren
|
|
97
99
|
- bin/grendb
|
|
98
100
|
- bin/mkgrendb
|
|
101
|
+
- lib/common/display_util.rb
|
|
99
102
|
- lib/common/grenfiletest.rb
|
|
100
103
|
- lib/common/grensnip.rb
|
|
101
104
|
- lib/common/platform.rb
|
|
@@ -104,6 +107,7 @@ files:
|
|
|
104
107
|
- lib/findgrep/result.rb
|
|
105
108
|
- lib/gren.rb
|
|
106
109
|
- lib/gren/cli.rb
|
|
110
|
+
- lib/gren/findgrep.rb
|
|
107
111
|
- lib/grendb/cli.rb
|
|
108
112
|
- lib/mkgrendb/cli.rb
|
|
109
113
|
- lib/mkgrendb/mkgrendb.rb
|