milkode 0.2.4 → 0.2.9
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.rdoc +16 -0
- data/HISTORY.rdoc +25 -0
- data/Rakefile +3 -2
- data/VERSION +1 -1
- data/bin/gmilk +10 -0
- data/bin/milk +1 -1
- data/lib/milkode/cdstk/cdstk.rb +121 -6
- data/lib/milkode/cdstk/cdstk_command.rb +28 -0
- data/lib/milkode/cdstk/cdstk_yaml.rb +30 -3
- data/lib/milkode/cdstk/cli_cdstk.rb +37 -14
- data/lib/milkode/cdstk/cli_cdstksub.rb +36 -1
- data/lib/milkode/cdweb/app.rb +1 -1
- data/lib/milkode/cdweb/lib/coderay_wrapper.rb +4 -5
- data/lib/milkode/cdweb/lib/database.rb +2 -0
- data/lib/milkode/cdweb/lib/my_nokogiri.rb +34 -0
- data/lib/milkode/common/dbdir.rb +30 -1
- data/lib/milkode/common/util.rb +15 -3
- data/lib/milkode/findgrep/findgrep.rb +86 -18
- data/lib/milkode/findgrep/result.rb +2 -2
- data/lib/milkode/grep/cli_grep.rb +113 -0
- data/milkode.gemspec +32 -9
- data/test/data/a_project/cdstk.rb +634 -0
- data/test/data/a_project/cdstk_yaml.rb +130 -0
- data/test/data/b_project/runner.rb +11 -0
- data/test/data/b_project/test_dir.rb +21 -0
- data/test/milkode_test_work.rb +78 -0
- data/test/test_cdstk.rb +12 -2
- data/test/test_cdstk_command.rb +50 -0
- data/test/test_cdstk_yaml.rb +20 -3
- data/test/test_cli_cdstk.rb +71 -0
- data/test/test_cli_grep.rb +79 -0
- data/test/test_database.rb +1 -1
- data/test/test_dbdir.rb +11 -0
- metadata +43 -8
data/HISTORY.ja.rdoc
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
=== 0.2.9 2011/12/24
|
2
|
+
|
3
|
+
* gmilk
|
4
|
+
* grepのようにコマンドラインから検索可能に
|
5
|
+
* mcd
|
6
|
+
* データベースに登録したパッケージを簡単にディレクトリ移動することが出来る
|
7
|
+
* milk
|
8
|
+
* milk setdb を追加、デフォルトデータベースの切り替え
|
9
|
+
* milk update の改善、現在位置がパッケージなら
|
10
|
+
* milk dir を追加、指定パッケージのディレクトリ位置を表示
|
11
|
+
* milk mcd を追加、mcdコマンドのインストール用
|
12
|
+
* milk web
|
13
|
+
* Ruby1.8の時はhpricotを(文字化けが直る)、Ruby1.9の時はnokogiriを使うように(hpricotだと日本語検索が上手くいかない)。
|
14
|
+
* ファイルリストをフォルダ、名前で並べ替えるように
|
15
|
+
* MilkodeTestWorkクラスを追加、テスト向け環境構築を容易に
|
16
|
+
|
1
17
|
=== 0.2.4 2011/10/02
|
2
18
|
|
3
19
|
* gem 1.3.6, 1.3.7 でインストール出来ない問題を修正
|
data/HISTORY.rdoc
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
=== 0.2.9 2011/12/24
|
2
|
+
|
3
|
+
* gmilk
|
4
|
+
* 'gmilk' search from the command line available the grep.
|
5
|
+
* mcd
|
6
|
+
* 'mcd', you can easy directory move package registered in the database
|
7
|
+
* milk
|
8
|
+
* Add 'milk setdb'.
|
9
|
+
* Add 'milk update'.
|
10
|
+
* Add 'milk dir'.
|
11
|
+
* Add 'milk mcd'.
|
12
|
+
* milk web
|
13
|
+
* Ruby1.8 -> hpricot, Ruby1.9 -> nokogiri.
|
14
|
+
* Sort the file list folder, and name
|
15
|
+
* Add MilkodeTestWork class.
|
16
|
+
|
17
|
+
=== 0.2.4 2011/10/02
|
18
|
+
|
19
|
+
* Fixed not installing gem 1.3.6, 1.3.7.
|
20
|
+
|
21
|
+
=== 0.2.3 2011/09/29
|
22
|
+
|
23
|
+
* Search web interface speed.
|
24
|
+
* Corresponds to the Japan language file names.
|
25
|
+
|
1
26
|
=== 0.2.2 2011/08/26
|
2
27
|
|
3
28
|
* Add a file grep.
|
data/Rakefile
CHANGED
@@ -23,8 +23,8 @@ Jeweler::Tasks.new do |gem|
|
|
23
23
|
|
24
24
|
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
25
25
|
gem.add_runtime_dependency 'termcolor','>= 1.2.0'
|
26
|
-
gem.add_runtime_dependency 'rroonga','>= 1.
|
27
|
-
gem.add_runtime_dependency 'rack','>=1.
|
26
|
+
gem.add_runtime_dependency 'rroonga','>= 1.1.0'
|
27
|
+
gem.add_runtime_dependency 'rack','>=1.3.4'
|
28
28
|
gem.add_runtime_dependency 'sinatra', '>=1.2.6'
|
29
29
|
gem.add_runtime_dependency 'launchy', '>=0.3.7'
|
30
30
|
gem.add_runtime_dependency 'coderay', '=0.9.8'
|
@@ -33,6 +33,7 @@ Jeweler::Tasks.new do |gem|
|
|
33
33
|
gem.add_runtime_dependency 'haml', '>=3.1.2'
|
34
34
|
gem.add_runtime_dependency 'sass', '>=3.1.3'
|
35
35
|
gem.add_runtime_dependency 'nokogiri', '>=1.5.0'
|
36
|
+
gem.add_runtime_dependency 'hpricot', '>=0.8.2'
|
36
37
|
|
37
38
|
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
38
39
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.9
|
data/bin/gmilk
ADDED
data/bin/milk
CHANGED
data/lib/milkode/cdstk/cdstk.rb
CHANGED
@@ -19,6 +19,7 @@ rescue LoadError
|
|
19
19
|
end
|
20
20
|
require 'milkode/cdweb/lib/database'
|
21
21
|
require 'open-uri'
|
22
|
+
require 'milkode/cdstk/cdstk_command'
|
22
23
|
|
23
24
|
module Milkode
|
24
25
|
class Cdstk
|
@@ -60,20 +61,51 @@ module Milkode
|
|
60
61
|
db_open(db_file)
|
61
62
|
end
|
62
63
|
|
63
|
-
def
|
64
|
+
def update_all
|
64
65
|
print_result do
|
65
66
|
yaml = yaml_load
|
66
|
-
|
67
|
-
update_list = (!args || args.empty?) ? yaml_load.list : yaml_load.list(CdstkYaml::Query.new(args))
|
68
|
-
|
67
|
+
|
69
68
|
db_open(db_file)
|
70
69
|
|
71
|
-
|
70
|
+
yaml.list.each do |content|
|
72
71
|
update_dir_in(content["directory"])
|
73
72
|
end
|
74
73
|
end
|
75
74
|
end
|
76
75
|
|
76
|
+
def update(args, options)
|
77
|
+
if (options[:all])
|
78
|
+
update_all
|
79
|
+
else
|
80
|
+
if (args.empty?)
|
81
|
+
path = File.expand_path('.')
|
82
|
+
package = yaml_load.package_root( path )
|
83
|
+
|
84
|
+
if (package)
|
85
|
+
print_result do
|
86
|
+
db_open(db_file)
|
87
|
+
update_dir_in(package["directory"])
|
88
|
+
end
|
89
|
+
else
|
90
|
+
@out.puts "Not registered. If you want to add, 'milk add #{path}'."
|
91
|
+
end
|
92
|
+
else
|
93
|
+
print_result do
|
94
|
+
update_list = yaml_load.list CdstkYaml::Query.new(args)
|
95
|
+
db_open(db_file)
|
96
|
+
update_list.each do |content|
|
97
|
+
update_dir_in(content["directory"])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def update_package(dir)
|
105
|
+
db_open(db_file)
|
106
|
+
update_dir(dir)
|
107
|
+
end
|
108
|
+
|
77
109
|
def update_dir(dir)
|
78
110
|
update_dir_in(dir)
|
79
111
|
end
|
@@ -285,7 +317,7 @@ module Milkode
|
|
285
317
|
def rebuild
|
286
318
|
db_delete(db_file)
|
287
319
|
db_create(db_file)
|
288
|
-
|
320
|
+
update_all
|
289
321
|
end
|
290
322
|
|
291
323
|
def dump
|
@@ -305,6 +337,85 @@ module Milkode
|
|
305
337
|
@out.puts "total #{records.size} record."
|
306
338
|
end
|
307
339
|
|
340
|
+
def dir(args, options)
|
341
|
+
yaml = yaml_load
|
342
|
+
|
343
|
+
if args.empty?
|
344
|
+
path = File.expand_path('.')
|
345
|
+
package = yaml.package_root(path)
|
346
|
+
|
347
|
+
if (package)
|
348
|
+
@out.print package['directory'] + (options[:top] ? "" : "\n")
|
349
|
+
else
|
350
|
+
# Use mcd.
|
351
|
+
@out.print "Not registered." + (options[:top] ? "" : "\n")
|
352
|
+
end
|
353
|
+
else
|
354
|
+
dirs = yaml.list(CdstkYaml::Query.new(args)).map{|v|v['directory']}.reverse
|
355
|
+
|
356
|
+
if options[:top]
|
357
|
+
unless (dirs.empty?)
|
358
|
+
@out.print dirs[0]
|
359
|
+
else
|
360
|
+
@out.print ""
|
361
|
+
end
|
362
|
+
else
|
363
|
+
@out.puts dirs
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
def setdb(args, options)
|
369
|
+
if (options[:reset])
|
370
|
+
CdstkCommand.setdb_reset
|
371
|
+
@out.puts "Reset default db\n remove: #{Dbdir.milkode_db_dir}\n default_db: #{Dbdir.default_dir}"
|
372
|
+
elsif (args.empty?)
|
373
|
+
@out.puts Dbdir.default_dir
|
374
|
+
else
|
375
|
+
path = File.expand_path(args[0])
|
376
|
+
begin
|
377
|
+
CdstkCommand.setdb_set path
|
378
|
+
@out.puts "Set default db #{path}."
|
379
|
+
rescue CdstkCommand::NotExistDatabase
|
380
|
+
@out.puts "fatal: '#{path}' is not database."
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
def mcd(args, options)
|
386
|
+
@out.print <<EOF
|
387
|
+
# Copy to '.bashrc'.
|
388
|
+
mcd() {
|
389
|
+
local args="$1 $2 $3 $4 $5 $6 $7 $8 $9"
|
390
|
+
local dir=`milk dir --top $args`
|
391
|
+
|
392
|
+
if [ "$dir" = "" ]; then
|
393
|
+
echo "fatal: Not found package: $1 $2 $3 $4 $5 $6 $7 $8 $9"
|
394
|
+
elif [ "$dir" = "Not registered." ]; then
|
395
|
+
echo "fatal: Not a package dir: `pwd`"
|
396
|
+
else
|
397
|
+
cd $dir
|
398
|
+
pwd
|
399
|
+
fi
|
400
|
+
}
|
401
|
+
|
402
|
+
# For Cygwin.
|
403
|
+
mcd() {
|
404
|
+
local args="$1 $2 $3 $4 $5 $6 $7 $8 $9"
|
405
|
+
local dir=`milk.bat dir --top $args`
|
406
|
+
|
407
|
+
if [ "$dir" = "" ]; then
|
408
|
+
echo "fatal: Not found package: $1 $2 $3 $4 $5 $6 $7 $8 $9"
|
409
|
+
elif [ "$dir" = "Not registered." ]; then
|
410
|
+
echo "fatal: Not a package dir: `pwd`"
|
411
|
+
else
|
412
|
+
cd $dir
|
413
|
+
pwd
|
414
|
+
fi
|
415
|
+
}
|
416
|
+
EOF
|
417
|
+
end
|
418
|
+
|
308
419
|
private
|
309
420
|
|
310
421
|
def db_file
|
@@ -319,6 +430,10 @@ module Milkode
|
|
319
430
|
File.expand_path(@db_dir)
|
320
431
|
end
|
321
432
|
|
433
|
+
def custom_db?
|
434
|
+
db_dir_expand != Dbdir.default_dir
|
435
|
+
end
|
436
|
+
|
322
437
|
def yaml_file
|
323
438
|
CdstkYaml.yaml_file @db_dir
|
324
439
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# @file
|
4
|
+
# @brief cdstk command set (Only action, not display message.)
|
5
|
+
# @author ongaeshi
|
6
|
+
# @date 2011/12/12
|
7
|
+
|
8
|
+
require 'milkode/common/dbdir'
|
9
|
+
|
10
|
+
module Milkode
|
11
|
+
module CdstkCommand
|
12
|
+
module_function
|
13
|
+
|
14
|
+
def setdb_set(path)
|
15
|
+
raise NotExistDatabase unless Dbdir.dbdir?(path)
|
16
|
+
open(Dbdir.milkode_db_dir, "w") {|f| f.print path }
|
17
|
+
end
|
18
|
+
|
19
|
+
def setdb_reset
|
20
|
+
FileUtils.rm_f(Dbdir.milkode_db_dir)
|
21
|
+
end
|
22
|
+
|
23
|
+
# --- error ---
|
24
|
+
class NotExistDatabase < RuntimeError ; end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
@@ -36,6 +36,15 @@ module Milkode
|
|
36
36
|
def initialize(yaml_file, data)
|
37
37
|
@yaml_file = yaml_file
|
38
38
|
@data = data
|
39
|
+
normalize
|
40
|
+
end
|
41
|
+
|
42
|
+
def normalize
|
43
|
+
if (Util::platform_win?)
|
44
|
+
contents.each do |v|
|
45
|
+
v['directory'] = Util::normalize_filename v['directory']
|
46
|
+
end
|
47
|
+
end
|
39
48
|
end
|
40
49
|
|
41
50
|
def add(dirs)
|
@@ -44,7 +53,7 @@ module Milkode
|
|
44
53
|
end
|
45
54
|
|
46
55
|
def remove(query)
|
47
|
-
r = query.
|
56
|
+
r = query.select_any?(contents)
|
48
57
|
r.each {|v| contents.delete v}
|
49
58
|
end
|
50
59
|
|
@@ -69,7 +78,7 @@ module Milkode
|
|
69
78
|
end
|
70
79
|
|
71
80
|
def list(query = nil)
|
72
|
-
query ? query.
|
81
|
+
query ? query.select_all?(contents) : contents
|
73
82
|
end
|
74
83
|
|
75
84
|
def exist?(shortname)
|
@@ -94,6 +103,18 @@ module Milkode
|
|
94
103
|
end
|
95
104
|
end
|
96
105
|
|
106
|
+
def package_root(dir)
|
107
|
+
nd = Util::normalize_filename dir
|
108
|
+
@data['contents'].find do |v|
|
109
|
+
v if nd =~ /^#{v['directory']}/
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def package_root_dir(dir)
|
114
|
+
package = package_root(dir)
|
115
|
+
(package) ? package['directory'] : nil
|
116
|
+
end
|
117
|
+
|
97
118
|
def self.yaml_file(path)
|
98
119
|
Dbdir.yaml_path(path)
|
99
120
|
end
|
@@ -103,11 +124,17 @@ module Milkode
|
|
103
124
|
@keywords = keywords
|
104
125
|
end
|
105
126
|
|
106
|
-
def
|
127
|
+
def select_any?(contents)
|
107
128
|
contents.find_all do |v|
|
108
129
|
@keywords.any? {|s| File.basename(v['directory']).include? s }
|
109
130
|
end
|
110
131
|
end
|
132
|
+
|
133
|
+
def select_all?(contents)
|
134
|
+
contents.find_all do |v|
|
135
|
+
@keywords.all? {|s| File.basename(v['directory']).include? s }
|
136
|
+
end
|
137
|
+
end
|
111
138
|
end
|
112
139
|
end
|
113
140
|
end
|
@@ -4,6 +4,7 @@ require 'milkode/cdstk/cli_cdstksub'
|
|
4
4
|
require 'milkode/cdstk/cdstk'
|
5
5
|
require 'milkode/common/dbdir.rb'
|
6
6
|
require 'milkode/cdweb/cli_cdweb'
|
7
|
+
require 'milkode/grep/cli_grep'
|
7
8
|
include Milkode
|
8
9
|
|
9
10
|
module Milkode
|
@@ -13,24 +14,42 @@ module Milkode
|
|
13
14
|
#{File.basename($0)} COMMAND [ARGS]
|
14
15
|
|
15
16
|
The most commonly used #{File.basename($0)} are:
|
16
|
-
init Init db.
|
17
17
|
add Add packages.
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
cleanup Cleanup garbage records.
|
19
|
+
dir Disp package dir.
|
20
|
+
dump Dump records.
|
21
|
+
grep Print lines matching a pattern
|
22
|
+
init Init db.
|
21
23
|
list List packages.
|
24
|
+
mcd Print 'mcd' command.
|
22
25
|
pwd Disp current db.
|
23
|
-
cleanup Cleanup garbage records.
|
24
26
|
rebuild Rebuild db.
|
25
|
-
|
27
|
+
remove Remove packages.
|
28
|
+
setdb Set default db.
|
29
|
+
update Update packages.
|
30
|
+
web Run web-app.
|
26
31
|
EOF
|
27
32
|
|
33
|
+
opt.order!(arguments)
|
34
|
+
subcommand = arguments.shift
|
35
|
+
|
36
|
+
case subcommand
|
37
|
+
when 'grep'
|
38
|
+
Milkode::CLI_Grep.execute(stdout, arguments)
|
39
|
+
else
|
40
|
+
subcommand_default(stdout, opt, subcommand, arguments)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def self.subcommand_default(stdout, opt, subcommand, arguments)
|
28
47
|
subopt = Hash.new
|
29
48
|
suboptions = Hash.new
|
30
49
|
|
31
50
|
subopt['init'], suboptions['init'] = CLI_Cdstksub.setup_init
|
32
51
|
subopt['add'] = CLI_Cdstksub.setup_add
|
33
|
-
subopt['update'] =
|
52
|
+
subopt['update'], suboptions['update'] = CLI_Cdstksub.setup_update
|
34
53
|
subopt['remove'], suboptions['remove'] = CLI_Cdstksub.setup_remove
|
35
54
|
subopt['list'], suboptions['list'] = CLI_Cdstksub.setup_list
|
36
55
|
subopt['pwd'], suboptions['pwd'] = CLI_Cdstksub.setup_pwd
|
@@ -38,10 +57,10 @@ EOF
|
|
38
57
|
subopt['rebuild'] = OptionParser.new("#{File.basename($0)} rebuild")
|
39
58
|
subopt['dump'] = OptionParser.new("#{File.basename($0)} dump")
|
40
59
|
subopt['web'], suboptions['web'] = CLI_Cdstksub.setup_web
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
60
|
+
subopt['dir'], suboptions['dir'] = CLI_Cdstksub.setup_dir
|
61
|
+
subopt['setdb'], suboptions['setdb'] = CLI_Cdstksub.setup_setdb
|
62
|
+
subopt['mcd'], suboptions['mcd'] = CLI_Cdstksub.setup_mcd
|
63
|
+
|
45
64
|
if (subopt[subcommand])
|
46
65
|
subopt[subcommand].parse!(arguments) unless arguments.empty?
|
47
66
|
init_default = suboptions['init'][:init_default]
|
@@ -54,7 +73,7 @@ EOF
|
|
54
73
|
FileUtils.mkdir_p db_dir if (init_default)
|
55
74
|
obj.init
|
56
75
|
when 'update'
|
57
|
-
obj.update(arguments)
|
76
|
+
obj.update(arguments, suboptions[subcommand])
|
58
77
|
when 'add'
|
59
78
|
obj.add(arguments)
|
60
79
|
when 'remove'
|
@@ -72,6 +91,12 @@ EOF
|
|
72
91
|
when 'web'
|
73
92
|
obj.compatible?
|
74
93
|
Milkode::CLI_Cdweb.execute_with_options(stdout, suboptions[subcommand])
|
94
|
+
when 'dir'
|
95
|
+
obj.dir(arguments, suboptions[subcommand])
|
96
|
+
when 'setdb'
|
97
|
+
obj.setdb(arguments, suboptions[subcommand])
|
98
|
+
when 'mcd'
|
99
|
+
obj.mcd(arguments, suboptions[subcommand])
|
75
100
|
end
|
76
101
|
else
|
77
102
|
if subcommand
|
@@ -82,8 +107,6 @@ EOF
|
|
82
107
|
end
|
83
108
|
end
|
84
109
|
|
85
|
-
private
|
86
|
-
|
87
110
|
def self.select_dbdir(subcommand, init_default)
|
88
111
|
if (subcommand == 'init')
|
89
112
|
if (init_default)
|