milkode 0.7.1 → 0.8.0

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.
Files changed (53) hide show
  1. data/Gemfile +17 -4
  2. data/HISTORY.ja.rdoc +27 -0
  3. data/HISTORY.rdoc +27 -0
  4. data/LICENSE.txt +23 -1
  5. data/Rakefile +1 -16
  6. data/VERSION +1 -1
  7. data/bin/gmilk +1 -1
  8. data/bin/milk +1 -1
  9. data/lib/milkode/cdstk/cdstk.rb +171 -168
  10. data/lib/milkode/cdstk/milkode_yaml.rb +1 -1
  11. data/lib/milkode/cdweb/app.rb +11 -3
  12. data/lib/milkode/cdweb/lib/command.rb +43 -0
  13. data/lib/milkode/cdweb/lib/database.rb +58 -210
  14. data/lib/milkode/cdweb/lib/mkurl.rb +10 -1
  15. data/lib/milkode/cdweb/lib/package_list.rb +61 -0
  16. data/lib/milkode/cdweb/lib/search_files.rb +2 -1
  17. data/lib/milkode/cdweb/public/css/bootstrap-responsive.min.css +9 -0
  18. data/lib/milkode/cdweb/public/css/bootstrap.min.css +9 -0
  19. data/lib/milkode/cdweb/public/css/milkode.css +44 -9
  20. data/lib/milkode/cdweb/public/img/glyphicons-halflings-white.png +0 -0
  21. data/lib/milkode/cdweb/public/img/glyphicons-halflings.png +0 -0
  22. data/lib/milkode/cdweb/public/js/bootstrap.min.js +6 -0
  23. data/lib/milkode/cdweb/views/index.haml +52 -16
  24. data/lib/milkode/cdweb/views/packages.haml +11 -0
  25. data/lib/milkode/cli.rb +8 -0
  26. data/lib/milkode/common/array_diff.rb +18 -0
  27. data/lib/milkode/common/util.rb +16 -0
  28. data/lib/milkode/database/document_record.rb +64 -0
  29. data/lib/milkode/database/document_table.rb +341 -0
  30. data/lib/milkode/database/groonga_database.rb +105 -0
  31. data/lib/milkode/database/package_table.rb +98 -0
  32. data/lib/milkode/findgrep/findgrep.rb +20 -124
  33. data/lib/milkode/grep/cli_grep.rb +3 -1
  34. data/milkode.gemspec +32 -2
  35. data/test/data/.gitignore +4 -0
  36. data/test/data/c_project/a.txt +1 -0
  37. data/test/data/c_project/abc.c +2 -0
  38. data/test/data/c_project/abc.h +3 -0
  39. data/test/data/c_project/b.txt +1 -0
  40. data/test/data/c_project/c.txt +1 -0
  41. data/test/data/c_project/cc.txt +1 -0
  42. data/test/data/c_project/to/file.rb +1 -0
  43. data/test/test_cdstk.rb +4 -4
  44. data/test/test_cli.rb +9 -2
  45. data/test/test_database.rb +5 -14
  46. data/test/test_document_record.rb +77 -0
  47. data/test/test_document_table.rb +317 -0
  48. data/test/test_groonga_database.rb +58 -0
  49. data/test/test_mkurl.rb +2 -0
  50. data/test/test_package_list.rb +21 -0
  51. data/test/test_package_table.rb +215 -0
  52. data/test/test_util.rb +8 -0
  53. metadata +57 -5
@@ -1,3 +1,7 @@
1
+ # -----------------------------
2
+ # For test/test_ignore_setting.rb
3
+ # -----------------------------
4
+
1
5
  # rcov generated
2
6
  coverage
3
7
 
@@ -0,0 +1 @@
1
+ a
@@ -0,0 +1,2 @@
1
+ abcdef
2
+ 123456
@@ -0,0 +1,3 @@
1
+ defghi
2
+ 456789
3
+
@@ -0,0 +1 @@
1
+ b
@@ -0,0 +1 @@
1
+ c
@@ -0,0 +1 @@
1
+ cc
@@ -0,0 +1 @@
1
+ puts "a"
@@ -39,6 +39,7 @@ class TestCdstk < Test::Unit::TestCase
39
39
  obj.add(['../data/nodir_abc_xpi.xpi'], {})
40
40
  obj.add(['http://ongaeshi.me/test_data/http_nodir_abc.zip'], {})
41
41
  obj.add(['git://github.com/ongaeshi/duplicate-thing.git'], {})
42
+ # obj.add(['git@github.com:ongaeshi/kodeworld.git'], {})
42
43
  assert_raise(OpenURI::HTTPError) { obj.add(['http://ongaeshi.me/test_data/not_found.zip'], {}) }
43
44
  obj.add(['../data/no_auto_ignore'], {:no_auto_ignore => true})
44
45
 
@@ -54,7 +55,7 @@ class TestCdstk < Test::Unit::TestCase
54
55
  io.puts('--- update_all ---')
55
56
  FileUtils.touch('packages/zip/abc/c.txt')
56
57
  FileUtils.touch('packages/zip/abc/d.txt')
57
- obj.update_all
58
+ obj.update_all({})
58
59
 
59
60
  io.puts('--- update --all ---')
60
61
  FileUtils.touch('packages/zip/abc/e.txt')
@@ -66,7 +67,7 @@ class TestCdstk < Test::Unit::TestCase
66
67
  # obj.update([], {})
67
68
  end
68
69
 
69
- Database.instance.yaml_reload
70
+ # Database.instance.yaml_reload
70
71
 
71
72
  io.puts('--- remove ---')
72
73
  obj.remove(['findgrep'], {:force => true})
@@ -78,8 +79,7 @@ class TestCdstk < Test::Unit::TestCase
78
79
  obj.list(['com'], {:verbose => false})
79
80
 
80
81
  io.puts('--- cleanup ---')
81
- # 何故か 'rake test' で実行すると上手く動かないので、一旦テストから外す
82
- # obj.cleanup({:force=>true})
82
+ obj.cleanup({:force=>true})
83
83
 
84
84
  io.puts('--- rebuild ---')
85
85
  obj.rebuild([], {:all => true})
@@ -9,7 +9,7 @@ require 'milkode/cli.rb'
9
9
  require 'test_helper'
10
10
  require 'milkode_test_work'
11
11
 
12
- class TestCLI_Cdstk < Test::Unit::TestCase
12
+ class TestCLI < Test::Unit::TestCase
13
13
  def setup
14
14
  $stdout = StringIO.new
15
15
  @first_default_dir = Dbdir.default_dir
@@ -61,8 +61,15 @@ class TestCLI_Cdstk < Test::Unit::TestCase
61
61
  assert_equal @first_default_dir, Dbdir.default_dir
62
62
  end
63
63
 
64
+ def test_fav
65
+ command("fav")
66
+ command("fav a_not_found_package_xxxxxxx")
67
+ # command("fav package")
68
+ # command("fav -d package")
69
+ end
70
+
64
71
  def test_help_with_h_option
65
- commands = ["init", "add", "update", "remove", "list", "pwd", "cleanup", "rebuild", "dump", "dir", "setdb", "mcd", "info", "ignore", "web"]
72
+ commands = ["init", "add", "update", "remove", "list", "pwd", "cleanup", "rebuild", "dump", "dir", "setdb", "mcd", "info", "ignore", "web", "fav"]
66
73
  commands.each do |cmd|
67
74
  assert_match "Usage:", command("#{ cmd } -h")
68
75
  end
@@ -11,6 +11,7 @@ require 'test_helper'
11
11
  require 'file_test_utils'
12
12
  require 'stringio'
13
13
  require 'milkode/cdstk/cdstk'
14
+ require 'milkode/cdstk/package'
14
15
  require 'milkode/cdweb/lib/database'
15
16
 
16
17
  module Milkode
@@ -22,8 +23,12 @@ module Milkode
22
23
  io = StringIO.new
23
24
  @obj = Cdstk.new(io)
24
25
  @obj.init({})
26
+
25
27
  @obj.add(['../../test'], {})
28
+
29
+ FileUtils.touch('../../lib/delete_on.cleanup_package_name')
26
30
  @obj.add(['../../lib'], {})
31
+ FileUtils.rm('../../lib/delete_on.cleanup_package_name')
27
32
 
28
33
  FileUtils.touch('notfound.file')
29
34
  @obj.add(['notfound.file'], {})
@@ -42,8 +47,6 @@ module Milkode
42
47
  setup_db
43
48
  t_open
44
49
  t_fileList
45
- t_cleanup # 何故か 'rake test' で実行すると上手く動かないので、一旦テストから外す
46
- t_remove
47
50
  end
48
51
 
49
52
  def t_open
@@ -59,18 +62,6 @@ module Milkode
59
62
  assert_equal nil, db.fileList('lib/milkode/cdstk/cdstk.rb')[0]
60
63
  end
61
64
 
62
- def t_cleanup
63
- db = Database.instance
64
- db.cleanup
65
- end
66
-
67
- def t_remove
68
- db = Database.instance
69
- db.remove_fpath(File.expand_path '../../test')
70
- db.remove_fpath(File.expand_path '../../lib')
71
- assert_equal 0, db.totalRecords
72
- end
73
-
74
65
  def teardown
75
66
  teardown_custom(true)
76
67
  # teardown_custom(false)
@@ -0,0 +1,77 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2010/xx/xxxx
7
+
8
+ require 'test_helper'
9
+ require 'milkode/database/groonga_database'
10
+ require 'milkode/database/document_table'
11
+ require 'milkode/database/document_record'
12
+ require 'fileutils'
13
+
14
+ module Milkode
15
+ class TestDocumentTable < Test::Unit::TestCase
16
+ def test_database
17
+ begin
18
+ t_setup
19
+ t_open
20
+ t_read
21
+ ensure
22
+ t_cleanup
23
+ end
24
+ end
25
+
26
+ # -----------------------------------------------
27
+ private
28
+
29
+ def t_setup
30
+ @obj = GroongaDatabase.new
31
+ @tmp_dir = expand("groonga_database_work")
32
+ @b_project = expand('data/b_project')
33
+ @c_project = expand('data/c_project')
34
+ end
35
+
36
+ def t_cleanup
37
+ # 本当は明示的にcloseした方が行儀が良いのだけれど、
38
+ # 単体テストの時にSementationFaultが出るのでコメントアウト
39
+ # @obj.close
40
+
41
+ # データベース削除
42
+ @obj = nil
43
+ FileUtils.rm_rf(@tmp_dir)
44
+
45
+ # time.txt削除
46
+ FileUtils.rm_f(File.join(@c_project, 'time.txt'))
47
+ end
48
+
49
+ def t_open
50
+ @obj.open(@tmp_dir)
51
+ @documents = @obj.documents
52
+ # @obj.close
53
+ end
54
+
55
+ def t_read
56
+ @documents.add(@c_project, 'a.txt')
57
+ @documents.add(@c_project, 'b.txt')
58
+
59
+ result = @documents.search(:restpaths => ['a.txt'])
60
+
61
+ r = DocumentRecord.new(result[0])
62
+ assert_equal 'c_project', r.package
63
+ assert_equal 'a.txt', r.restpath
64
+ assert_equal 'c_project/a.txt', r.shortpath
65
+ assert_equal 'txt', r.suffix
66
+ # p r
67
+
68
+ @documents.remove_all
69
+ end
70
+
71
+ # -----------------------------------------------
72
+
73
+ def expand(path)
74
+ File.expand_path(File.join(File.dirname(__FILE__), path))
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,317 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # @file
4
+ # @brief
5
+ # @author ongaeshi
6
+ # @date 2010/xx/xxxx
7
+
8
+ require 'test_helper'
9
+ require 'milkode/database/groonga_database'
10
+ require 'milkode/common/dbdir'
11
+ require 'milkode/cdstk/package.rb'
12
+ require 'fileutils'
13
+
14
+ module Milkode
15
+ class TestDocumentTable < Test::Unit::TestCase
16
+ def test_database
17
+ begin
18
+ t_setup
19
+ t_open
20
+ t_documents
21
+ t_remove
22
+ t_shortpath
23
+ t_grndb_cleanup
24
+ t_search
25
+ t_search2
26
+ t_search_packages
27
+ t_search_paths
28
+ t_search_suffixs
29
+ t_search_keywords
30
+ t_cleanup_package_name
31
+ t_remove_match_path
32
+ t_add_package_name
33
+ t_shortpath_below
34
+ ensure
35
+ t_cleanup
36
+ end
37
+ end
38
+
39
+ def t_setup
40
+ @obj = GroongaDatabase.new
41
+ @tmp_dir = expand("groonga_database_work")
42
+ @b_project = expand('data/b_project')
43
+ @c_project = expand('data/c_project')
44
+ end
45
+
46
+ def expand(path)
47
+ File.expand_path(File.join(File.dirname(__FILE__), path))
48
+ end
49
+
50
+ def t_cleanup
51
+ # 本当は明示的にcloseした方が行儀が良いのだけれど、
52
+ # 単体テストの時にSementationFaultが出るのでコメントアウト
53
+ # @obj.close
54
+
55
+ # データベース削除
56
+ @obj = nil
57
+ FileUtils.rm_rf(@tmp_dir)
58
+
59
+ # time.txt削除
60
+ FileUtils.rm_f(File.join(@c_project, 'time.txt'))
61
+ end
62
+
63
+ def t_open
64
+ @obj.open(@tmp_dir)
65
+ @documents = @obj.documents
66
+ # @obj.close
67
+ end
68
+
69
+ # -----------------------------------------------
70
+
71
+ def t_documents
72
+ documents = @obj.documents
73
+ assert_equal 0, documents.size
74
+
75
+ assert_equal :newfile, documents.add(@c_project, 'a.txt')
76
+ assert_equal 1, documents.size
77
+
78
+ assert_equal :newfile, documents.add(@c_project, 'b.txt')
79
+ assert_equal 2, documents.size
80
+
81
+ assert_equal nil, documents.add(@c_project, 'b.txt')
82
+ assert_equal 2, documents.size
83
+
84
+ # documents.dump
85
+
86
+ # ファイルの作成
87
+ current = Time.now
88
+ touch(File.join(@c_project, 'time.txt'), current - 1)
89
+ documents.add(@c_project, 'time.txt')
90
+ assert_equal 3, documents.size
91
+
92
+ # c_project/time.txt を現在時刻で書き換えて更新テスト
93
+ touch(File.join(@c_project, 'time.txt'), current)
94
+ assert_equal :update, documents.add(@c_project, 'time.txt')
95
+
96
+ # documents.dump
97
+
98
+ documents.remove_all
99
+ assert_equal 0, documents.size
100
+ end
101
+
102
+ def t_remove
103
+ documents = @obj.documents
104
+ assert_equal :newfile, documents.add(@c_project, 'a.txt')
105
+ assert_equal :newfile, documents.add(@c_project, 'b.txt')
106
+ assert_equal 2, documents.size
107
+
108
+ documents.remove(File.join(@c_project, 'a.txt'))
109
+ assert_equal 1, documents.size
110
+ # documents.dump
111
+
112
+ documents.remove_all
113
+ end
114
+
115
+ def t_shortpath
116
+ documents = @obj.documents
117
+ documents.add(@c_project, 'a.txt')
118
+ documents.add(@c_project, 'b.txt')
119
+ documents.add(@c_project, 'time.txt')
120
+
121
+ assert_equal 'b.txt', documents.find_shortpath('c_project/b.txt').restpath
122
+ assert_equal 'time.txt', documents.find_shortpath('c_project/time.txt').restpath
123
+ assert_nil documents.find_shortpath('c_project/c.txt')
124
+
125
+ documents.remove_all
126
+ end
127
+
128
+ def t_grndb_cleanup
129
+ documents = @obj.documents
130
+
131
+ tmp_dir = expand("groonga_database_work")
132
+ tmp_filename = File.join(tmp_dir, 'test.c')
133
+ open(tmp_filename, "w") do |file|
134
+ file.write(Time.now)
135
+ end
136
+ documents.add(tmp_dir, 'test.c')
137
+ assert_equal 1, documents.size
138
+
139
+ FileUtils.rm_f tmp_filename
140
+ documents.cleanup
141
+ assert_equal 0, documents.size
142
+
143
+ documents.remove_all
144
+ end
145
+
146
+ def t_search
147
+ @documents.add(@c_project, 'a.txt')
148
+ @documents.add(@c_project, 'b.txt')
149
+ @documents.add(@c_project, 'c.txt')
150
+ @documents.add(@c_project, 'cc.txt')
151
+
152
+ records = @documents.search(:patterns => ['a'])
153
+ assert_equal 1, records.size
154
+ assert_equal 'a.txt', records[0].restpath
155
+
156
+ records = @documents.search(:patterns => ['b'])
157
+ assert_equal 1, records.size
158
+ assert_equal 'b.txt', records[0].restpath
159
+
160
+ records = @documents.search(:patterns => ['c'])
161
+ assert_equal 2, records.size
162
+ assert_equal 'c.txt', records[0].restpath
163
+ assert_equal 'cc.txt', records[1].restpath
164
+
165
+ # @documents.dump
166
+
167
+ @documents.remove_all
168
+ end
169
+
170
+ def t_search2
171
+ @documents.add(@c_project, 'abc.c')
172
+ @documents.add(@c_project, 'abc.h')
173
+
174
+ records = @documents.search(:patterns => ['def', '456'])
175
+ assert_equal 2, records.size
176
+
177
+ records = @documents.search(:patterns => ['def', '123'])
178
+ assert_equal 1, records.size
179
+
180
+ # @documents.dump
181
+
182
+ @documents.remove_all
183
+ end
184
+
185
+ def t_search_packages
186
+ @documents.add(@c_project, 'abc.c')
187
+ @documents.add(@b_project, 'runner.rb')
188
+
189
+ records = @documents.search(:packages => ['b_project'])
190
+
191
+ assert_equal 1, records.size
192
+ assert_equal 'runner.rb', records[0].restpath
193
+
194
+ @documents.remove_all
195
+ end
196
+
197
+ def t_search_paths
198
+ @documents.add(@c_project, 'abc.c')
199
+ @documents.add(@c_project, 'abc.h')
200
+
201
+ records = @documents.search(:paths => ['abc'])
202
+ assert_equal 2, records.size
203
+
204
+ records = @documents.search(:restpaths => ['h'])
205
+ assert_equal 1, records.size
206
+
207
+ # @documents.dump
208
+
209
+ @documents.remove_all
210
+ end
211
+
212
+ def t_search_suffixs
213
+ @documents.add(@c_project, 'a.txt')
214
+ @documents.add(@c_project, 'b.txt')
215
+ @documents.add(@c_project, 'abc.c')
216
+ @documents.add(@c_project, 'abc.h')
217
+
218
+ records = @documents.search(:suffixs => ['c'])
219
+ assert_equal 1, records.size
220
+
221
+ records = @documents.search(:suffixs => ['h'])
222
+ assert_equal 1, records.size
223
+
224
+ records = @documents.search(:suffixs => ['h', 'c'])
225
+ assert_equal 2, records.size
226
+
227
+ records = @documents.search(:suffixs => ['txt'])
228
+ assert_equal 2, records.size
229
+
230
+ # @documents.dump
231
+
232
+ @documents.remove_all
233
+ end
234
+
235
+ def t_search_keywords
236
+ @documents.add(@c_project, 'a.txt')
237
+ @documents.add(@c_project, 'b.txt')
238
+ @documents.add(@c_project, 'abc.c')
239
+ @documents.add(@c_project, 'abc.h')
240
+
241
+ records = @documents.search(:keywords => ['txt'])
242
+ assert_equal 2, records.size
243
+
244
+ records = @documents.search(:keywords => ['a'])
245
+ assert_equal 3, records.size
246
+
247
+ records = @documents.search(:keywords => ['project'])
248
+ assert_equal 4, records.size
249
+
250
+ @documents.remove_all
251
+ end
252
+
253
+ def t_cleanup_package_name
254
+ @documents.add(@c_project, 'a.txt')
255
+ add_and_remove(@c_project, 'time.txt')
256
+ add_and_remove(@b_project, 'time.txt')
257
+
258
+ @documents.cleanup_package_name('c_project')
259
+ assert_equal 2, @documents.size
260
+
261
+ @documents.cleanup_package_name('b_project')
262
+ assert_equal 1, @documents.size
263
+
264
+ @documents.remove_all
265
+ end
266
+
267
+ def t_remove_match_path
268
+ @documents.add(@c_project, 'a.txt')
269
+ @documents.add(@c_project, 'b.txt')
270
+ @documents.add(@b_project, 'runner.rb')
271
+
272
+ @documents.remove_match_path(@c_project)
273
+ assert_equal 1, @documents.size
274
+
275
+ @documents.remove_all
276
+ end
277
+
278
+ def t_add_package_name
279
+ @documents.add(@c_project, 'a.txt', 'other_package')
280
+ @documents.add(@c_project, 'b.txt')
281
+
282
+ assert_equal nil, @documents.find_shortpath('c_project/a.txt')
283
+ assert_equal 'other_package', @documents.find_shortpath('other_package/a.txt').package
284
+ assert_equal 'c_project', @documents.find_shortpath('c_project/b.txt').package
285
+
286
+ @documents.remove_all
287
+ end
288
+
289
+ def t_shortpath_below
290
+ @documents.add(@c_project, 'a.txt')
291
+ @documents.add(@c_project, 'b.txt')
292
+ @documents.add(@c_project, 'to/file.rb')
293
+ @documents.add(@b_project, 'runner.rb')
294
+
295
+ assert_equal 4, @documents.find_shortpath_below('').size
296
+ assert_equal 3, @documents.find_shortpath_below('c_project').size
297
+ assert_equal 1, @documents.find_shortpath_below('c_project/to').size
298
+ assert_equal 1, @documents.find_shortpath_below('c_project/to/').size
299
+
300
+ @documents.remove_all
301
+ end
302
+
303
+ private
304
+
305
+ def touch(filename, timestamp)
306
+ FileUtils.touch(filename, :mtime => timestamp)
307
+ # open(filename, "w") {|dst| dst.write(Time.now) }
308
+ end
309
+
310
+ def add_and_remove(project_dir, restpath)
311
+ tmp_filename = File.join(project_dir, restpath)
312
+ touch(tmp_filename, Time.now)
313
+ @documents.add(project_dir, restpath)
314
+ FileUtils.rm_f tmp_filename
315
+ end
316
+ end
317
+ end