gren 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/bin/mkgrendb +1 -1
- data/lib/gren.rb +1 -1
- data/lib/mkgrendb/cli.rb +29 -4
- data/lib/mkgrendb/mkgrendb.rb +71 -22
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
=== 0.2.2 2010/09/14
|
2
|
+
|
3
|
+
* mkgrendb
|
4
|
+
* 複数引数に対応
|
5
|
+
* 引数に、.rb, .yamlどちらを渡しても正しく動作するように
|
6
|
+
* --ddb, --defaultオプションを追加 (GRENDB_DEFAULT_DBで指定されているデータベースを更新)
|
7
|
+
* --dump データベースの中身をダンプする
|
8
|
+
* --full データベースを一度削除してから再構築
|
9
|
+
* --delete データベースを削除(yamlは消さない)
|
10
|
+
* ファイルのタイムスタンプを比較して、すでに更新されているものは再生成しないように
|
11
|
+
|
1
12
|
=== 0.2.1 2010/09/13
|
2
13
|
|
3
14
|
* デフォルトのignoreファイル追加 .d, .map, .MAP
|
data/bin/mkgrendb
CHANGED
data/lib/gren.rb
CHANGED
data/lib/mkgrendb/cli.rb
CHANGED
@@ -5,13 +5,38 @@ require File.join(File.dirname(__FILE__), 'mkgrendb')
|
|
5
5
|
module Mkgrendb
|
6
6
|
class CLI
|
7
7
|
def self.execute(stdout, arguments=[])
|
8
|
+
input_yamls = []
|
9
|
+
isDump = false
|
10
|
+
isFull = false
|
11
|
+
isDelete = false
|
12
|
+
|
8
13
|
opt = OptionParser.new "#{File.basename($0)} INPUT_YAML1 [INPUT_YAML2 ...]"
|
14
|
+
opt.on('--ddb', "--default-db", "Create or Update default DB. (Plase set ENV['GRENDB_DEFAULT_DB'])") {|v| input_yamls << ENV['GRENDB_DEFAULT_DB']}
|
15
|
+
opt.on('--full', "Full update DB. (Delete and create)") {|v| isFull = true }
|
16
|
+
opt.on('--delete', "Delete DB. (Not delete yaml)") {|v| isDelete = true }
|
17
|
+
opt.on('--dump', "Dump DB.") {|v| isDump = true }
|
9
18
|
opt.parse!(arguments)
|
10
19
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
20
|
+
input_yamls.concat arguments
|
21
|
+
|
22
|
+
if (input_yamls.size >= 1)
|
23
|
+
input_yamls.each do |input_yaml|
|
24
|
+
obj = Mkgrendb.new(input_yaml)
|
25
|
+
|
26
|
+
if (isFull)
|
27
|
+
obj.full
|
28
|
+
stdout.puts
|
29
|
+
elsif (isDelete)
|
30
|
+
obj.delete
|
31
|
+
stdout.puts
|
32
|
+
elsif (isDump)
|
33
|
+
obj.dump
|
34
|
+
else
|
35
|
+
obj.update
|
36
|
+
stdout.puts
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
15
40
|
else
|
16
41
|
stdout.puts opt.help
|
17
42
|
end
|
data/lib/mkgrendb/mkgrendb.rb
CHANGED
@@ -1,34 +1,52 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
require 'yaml'
|
4
|
-
|
5
4
|
require 'pathname'
|
6
|
-
|
7
|
-
base_directory = Pathname(__FILE__).dirname + ".."
|
8
|
-
$LOAD_PATH.unshift((base_directory + "ext").to_s)
|
9
|
-
$LOAD_PATH.unshift((base_directory + "lib").to_s)
|
10
|
-
|
11
5
|
require 'rubygems'
|
12
6
|
require 'groonga'
|
13
|
-
|
14
7
|
require File.join(File.dirname(__FILE__), '../common/grenfiletest')
|
15
8
|
|
16
9
|
module Mkgrendb
|
17
10
|
class Mkgrendb
|
18
|
-
def initialize(
|
19
|
-
@
|
20
|
-
@
|
21
|
-
|
11
|
+
def initialize(input)
|
12
|
+
@input_yaml = input.sub(/\.db$/, ".yaml")
|
13
|
+
@output_db = input.sub(/\.yaml$/, ".db")
|
14
|
+
puts "input_yaml : #{@input_yaml} found."
|
15
|
+
@src = YAML.load(open(@input_yaml).read())
|
16
|
+
@file_count = 0
|
22
17
|
end
|
23
18
|
|
24
19
|
def update
|
20
|
+
db_create(@output_db)
|
25
21
|
db_open(@output_db)
|
26
|
-
|
27
22
|
@src["directory"].each do |dir|
|
28
23
|
db_add_dir(File.expand_path(dir))
|
29
24
|
end
|
30
25
|
end
|
31
26
|
|
27
|
+
def delete
|
28
|
+
db_delete(@output_db)
|
29
|
+
end
|
30
|
+
|
31
|
+
def full
|
32
|
+
delete
|
33
|
+
update
|
34
|
+
end
|
35
|
+
|
36
|
+
def dump()
|
37
|
+
db_open(@output_db)
|
38
|
+
|
39
|
+
documents = Groonga::Context.default["documents"]
|
40
|
+
records = documents.select
|
41
|
+
records.each do |record|
|
42
|
+
puts "path : #{record.path}"
|
43
|
+
puts "timestamp : #{record.timestamp.strftime('%Y/%m/%d %H:%M:%S')}"
|
44
|
+
puts "content :", record.content[0..64]
|
45
|
+
puts
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
32
50
|
def db_create(filename)
|
33
51
|
dbfile = Pathname(File.expand_path(filename))
|
34
52
|
dbdir = dbfile.dirname
|
@@ -40,6 +58,7 @@ module Mkgrendb
|
|
40
58
|
schema.create_table("documents") do |table|
|
41
59
|
table.string("path")
|
42
60
|
table.text("content")
|
61
|
+
table.time("timestamp")
|
43
62
|
end
|
44
63
|
|
45
64
|
schema.create_table("terms",
|
@@ -48,23 +67,33 @@ module Mkgrendb
|
|
48
67
|
:default_tokenizer => "TokenBigram") do |table|
|
49
68
|
table.index("documents.path")
|
50
69
|
table.index("documents.content")
|
70
|
+
table.index("documents.timestamp")
|
51
71
|
end
|
52
72
|
end
|
53
|
-
puts "create
|
73
|
+
puts "create : #{filename} created."
|
54
74
|
else
|
55
|
-
puts "message
|
75
|
+
puts "message : #{filename} already exist."
|
56
76
|
end
|
57
77
|
end
|
58
78
|
private :db_create
|
79
|
+
|
80
|
+
def db_delete(filename)
|
81
|
+
raise "Illegal file name : #{filename}." unless filename =~ /\.db$/
|
82
|
+
Dir.glob("#{filename}*").each do |f|
|
83
|
+
puts "delete : #{f}"
|
84
|
+
File.unlink(f)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
private :db_delete
|
59
88
|
|
60
89
|
def db_open(filename)
|
61
90
|
dbfile = Pathname(File.expand_path(filename))
|
62
91
|
|
63
92
|
if dbfile.exist?
|
64
93
|
Groonga::Database.open(dbfile.to_s)
|
65
|
-
puts
|
94
|
+
puts "open : #{dbfile} open."
|
66
95
|
else
|
67
|
-
raise "error
|
96
|
+
raise "error : #{dbfile.to_s} not found!!"
|
68
97
|
end
|
69
98
|
end
|
70
99
|
private :db_open
|
@@ -78,25 +107,43 @@ module Mkgrendb
|
|
78
107
|
# 格納するデータ
|
79
108
|
values = {
|
80
109
|
:path => filename,
|
81
|
-
:content =>
|
110
|
+
:content => nil,
|
111
|
+
:timestamp => File.mtime(filename),
|
82
112
|
}
|
83
113
|
|
84
|
-
#
|
114
|
+
# 検索するデータベース
|
85
115
|
documents = Groonga::Context.default["documents"]
|
116
|
+
|
117
|
+
# 既に登録されているファイルならばそれを上書き、そうでなければ新規レコードを作成
|
86
118
|
_documents = documents.select do |record|
|
87
119
|
record["path"] == values[:path]
|
88
120
|
end
|
89
121
|
|
122
|
+
isNewFile = false
|
123
|
+
|
90
124
|
if _documents.size.zero?
|
91
125
|
document = documents.add
|
126
|
+
isNewFile = true
|
92
127
|
else
|
93
128
|
document = _documents.to_a[0].key
|
94
129
|
end
|
95
130
|
|
96
|
-
#
|
97
|
-
|
98
|
-
|
99
|
-
|
131
|
+
# タイムスタンプが新しければデータベースに格納
|
132
|
+
if (document[:timestamp] < values[:timestamp])
|
133
|
+
# 実際に使うタイミングでファイルの内容を読み込み
|
134
|
+
values[:content] = open(filename).read
|
135
|
+
|
136
|
+
# データベースに格納
|
137
|
+
values.each do |key, value|
|
138
|
+
if (key == :path)
|
139
|
+
if (isNewFile)
|
140
|
+
puts "add_file : #{value}"
|
141
|
+
else
|
142
|
+
puts "update : #{value}"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
document[key] = value
|
146
|
+
end
|
100
147
|
end
|
101
148
|
|
102
149
|
end
|
@@ -121,6 +168,8 @@ module Mkgrendb
|
|
121
168
|
when "file"
|
122
169
|
unless ignoreFile?(fpath)
|
123
170
|
db_add_file(stdout, fpath)
|
171
|
+
@file_count += 1
|
172
|
+
puts "file_count : #{@file_count}" if (@file_count % 100 == 0)
|
124
173
|
end
|
125
174
|
end
|
126
175
|
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
|
+
- 2
|
9
|
+
version: 0.2.2
|
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-17 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|