milkode 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,11 +2,10 @@ source "http://rubygems.org"
2
2
  # Add dependencies required to use your gem here.
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
-
5
+ gemspec
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
- gem "bundler", "~> 1.0.0"
10
- gem "jeweler", "~> 1.5.2"
11
- gem "rcov", ">= 0"
9
+ gem "bundler"
10
+ gem "jeweler"
12
11
  end
@@ -1,3 +1,24 @@
1
+ === 0.7.0 2012/05/05
2
+
3
+ * milk
4
+ * 'milk add git://..' に対応、update時に`git pull`するように
5
+ * Thor を利用するように (thanks tomykaira)
6
+
7
+ * gmilk
8
+ * gotolineモード(-g)で、複数のパスを渡せるように
9
+ * 例: gmilk -g VERSION:1 bin/milk:9 bin/gmilk:9 lib/milkode/cdweb/app.rb:23
10
+ * Windows環境(SJIS) + Ruby1.9 でエンコーディングエラーが起きる問題を修正
11
+
12
+ * milk web
13
+ * カスタマイズしても<title></title>部分がMilkodeのままになっていた問題を修正
14
+ * 現在位置検索が正しく動いてない問題を修正
15
+
16
+ * common
17
+ * Package#options[:update_with_git_pull] を追加
18
+ * Gemfile.lock を無視した (thanks tomykaira)
19
+ * Remove dependency on rcov (thanks tomykaira)
20
+ * 環境によってYAMLオブジェクトの構文が異なり、テストが落ちる可能性があるのを対策 (thanks tomykaira)
21
+
1
22
  === 0.6.0 2012/03/28
2
23
 
3
24
  * milk web
@@ -1,3 +1,17 @@
1
+ === 0.7.0 2012/05/05
2
+
3
+ * milk
4
+ * `milk add git://..` to enabled. When you update `git pull` like you.
5
+ * Use Thor
6
+ * gmilk
7
+ * gotoline mode(-g) enabled multi args.
8
+ * Sample: gmilk -g VERSION:1 bin/milk:9 bin/gmilk:9 lib/milkode/cdweb/app.rb:23
9
+ * Windows(SJIS) + Ruby1.9 support
10
+ * milk web
11
+ * Bug fix
12
+ * common
13
+ * Bug fix
14
+
1
15
  === 0.6.0 2012/03/28
2
16
 
3
17
  * milk web
data/Rakefile CHANGED
@@ -32,6 +32,7 @@ Jeweler::Tasks.new do |gem|
32
32
  gem.add_runtime_dependency 'archive-zip', '>=0.4.0'
33
33
  gem.add_runtime_dependency 'haml', '>=3.1.2'
34
34
  gem.add_runtime_dependency 'sass', '>=3.1.3'
35
+ gem.add_runtime_dependency 'thor', '~> 0.15.0'
35
36
 
36
37
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
37
38
  # gem.add_development_dependency 'rspec', '> 1.2.3'
@@ -67,13 +68,6 @@ task :test_all do
67
68
  system('rake test')
68
69
  end
69
70
 
70
- # require 'rcov/rcovtask'
71
- # Rcov::RcovTask.new do |test|
72
- # test.libs << 'test'
73
- # test.pattern = 'test/**/test_*.rb'
74
- # test.verbose = true
75
- # end
76
-
77
71
  task :default => :test
78
72
 
79
73
  require 'rdoc/task'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.3
1
+ 0.7.0
data/bin/gmilk CHANGED
@@ -6,5 +6,5 @@
6
6
  require 'rubygems'
7
7
  require 'milkode/grep/cli_grep'
8
8
 
9
- Version = "0.6.0"
9
+ Version = "0.7.0"
10
10
  Milkode::CLI_Grep.execute(STDOUT, ARGV)
data/bin/milk CHANGED
@@ -4,7 +4,7 @@
4
4
  # Copyright (c) 2010. All rights reserved.
5
5
 
6
6
  require 'rubygems'
7
- require 'milkode/cdstk/cli_cdstk'
7
+ require 'milkode/cli'
8
8
 
9
- Version = "0.6.0"
10
- Milkode::CLI_Cdstk.execute(STDOUT, ARGV)
9
+ Version = "0.7.0"
10
+ Milkode::CLI.start(ARGV)
@@ -9,6 +9,7 @@ require 'pathname'
9
9
  require 'milkode/common/grenfiletest'
10
10
  require 'milkode/common/util'
11
11
  require 'milkode/common/dir'
12
+ require 'milkode/findgrep/findgrep'
12
13
  include Milkode
13
14
  require 'kconv'
14
15
  begin
@@ -66,7 +67,7 @@ module Milkode
66
67
  end
67
68
  end
68
69
 
69
- def compatible?
70
+ def assert_compatible
70
71
  db_open(db_file)
71
72
  end
72
73
 
@@ -75,7 +76,7 @@ module Milkode
75
76
  db_open(db_file)
76
77
 
77
78
  @yaml.contents.each do |package|
78
- update_dir_in(package.directory)
79
+ update_package_in(package)
79
80
  end
80
81
  end
81
82
  end
@@ -93,7 +94,7 @@ module Milkode
93
94
  if (package)
94
95
  print_result do
95
96
  db_open(db_file)
96
- update_dir_in(package.directory)
97
+ update_package_in(package)
97
98
  end
98
99
  else
99
100
  @out.puts "Not registered. If you want to add, 'milk add #{path}'."
@@ -104,7 +105,7 @@ module Milkode
104
105
  args.each do |name|
105
106
  package = @yaml.find_name(name)
106
107
  if (package)
107
- update_dir_in(package.directory)
108
+ update_package_in(package)
108
109
  else
109
110
  @out.puts "Not found package '#{name}'."
110
111
  return
@@ -115,12 +116,8 @@ module Milkode
115
116
  end
116
117
  end
117
118
 
118
- def update_package(dir)
119
+ def update_for_grep(dir)
119
120
  db_open(db_file)
120
- update_dir(dir)
121
- end
122
-
123
- def update_dir(dir)
124
121
  update_dir_in(dir)
125
122
  end
126
123
 
@@ -140,10 +137,13 @@ module Milkode
140
137
  # YAMLに追加
141
138
  package = Package.create(dir, options[:ignore])
142
139
  add_yaml(package)
143
- set_yaml_options(package, options)
140
+
141
+ # オプション設定
142
+ is_update_with_git_pull = git_url?(v)
143
+ set_yaml_options(package, options, is_update_with_git_pull)
144
144
 
145
145
  # アップデート
146
- update_dir(dir)
146
+ update_dir_in(dir)
147
147
  end
148
148
  rescue ConvetError
149
149
  return
@@ -151,23 +151,30 @@ module Milkode
151
151
  end
152
152
  end
153
153
 
154
- def set_yaml_options(package, src)
154
+ def set_yaml_options(package, options, is_update_with_git_pull)
155
155
  is_dirty = false
156
156
 
157
- if src[:no_auto_ignore]
157
+ if options[:no_auto_ignore]
158
158
  dst = package.options
159
159
  dst[:no_auto_ignore] = true
160
160
  package.set_options(dst)
161
161
  is_dirty = true
162
162
  end
163
163
 
164
- if src[:name]
164
+ if options[:name]
165
165
  dst = package.options
166
166
  dst[:name] = src[:name]
167
167
  package.set_options(dst)
168
168
  is_dirty = true
169
169
  end
170
170
 
171
+ if is_update_with_git_pull
172
+ dst = package.options
173
+ dst[:update_with_git_pull] = is_update_with_git_pull
174
+ package.set_options(dst)
175
+ is_dirty = true
176
+ end
177
+
171
178
  if is_dirty
172
179
  @yaml.update(package)
173
180
  @yaml.save
@@ -177,7 +184,7 @@ module Milkode
177
184
  def add_dir(dir, no_yaml = false)
178
185
  add_yaml(Package.create(dir)) unless no_yaml
179
186
  db_open(db_file)
180
- update_dir(dir)
187
+ update_dir_in(dir)
181
188
  end
182
189
 
183
190
  # yamlにパッケージを追加
@@ -236,11 +243,18 @@ module Milkode
236
243
  def download_file(src)
237
244
  if (src =~ /^https?:/)
238
245
  download_file_in(src)
246
+ elsif (git_url? src)
247
+ git_clone_in(src)
239
248
  else
240
249
  src
241
250
  end
242
251
  end
243
252
 
253
+ def git_url?(src)
254
+ (src =~ /^git:/) != nil
255
+ end
256
+ private :git_url?
257
+
244
258
  def download_file_in(url)
245
259
  alert("download", "#{url}")
246
260
 
@@ -258,6 +272,23 @@ module Milkode
258
272
  filename
259
273
  end
260
274
 
275
+ def git_clone_in(url)
276
+ alert("git", url)
277
+
278
+ dst_dir = File.join(@db_dir, "packages/git")
279
+ # FileUtils.mkdir_p dst_dir
280
+
281
+ filename = File.join(dst_dir, File.basename(url).sub(/\.git\Z/, ""))
282
+
283
+ # git output progress to stderr.
284
+ # `git clone #{url} #{filename} 2>&1`
285
+
286
+ # with output
287
+ system("git clone #{url} #{filename}")
288
+
289
+ filename
290
+ end
291
+
261
292
  def remove_all
262
293
  print_result do
263
294
  list([], {:verbose => true})
@@ -481,14 +512,14 @@ module Milkode
481
512
  end
482
513
  end
483
514
 
484
- def setdb(args, options)
515
+ def setdb(dbpath, options)
485
516
  if (options[:reset])
486
517
  CdstkCommand.setdb_reset
487
518
  @out.puts "Reset default db\n remove: #{Dbdir.milkode_db_dir}\n default_db: #{Dbdir.default_dir}"
488
- elsif (args.empty?)
519
+ elsif (dbpath.nil?)
489
520
  @out.puts Dbdir.default_dir
490
521
  else
491
- path = File.expand_path(args[0])
522
+ path = File.expand_path(dbpath)
492
523
  begin
493
524
  CdstkCommand.setdb_set path
494
525
  @out.puts "Set default db #{path}."
@@ -498,8 +529,9 @@ module Milkode
498
529
  end
499
530
  end
500
531
 
501
- def mcd(args, options)
502
- @out.print <<EOF
532
+ def mcd(options)
533
+ if options[:shell] != 'cygwin'
534
+ @out.print <<EOF
503
535
  # Copy to '.bashrc'.
504
536
  mcd() {
505
537
  local args="$1 $2 $3 $4 $5 $6 $7 $8 $9"
@@ -514,7 +546,11 @@ mcd() {
514
546
  pwd
515
547
  fi
516
548
  }
549
+ EOF
550
+ end
517
551
 
552
+ if options[:shell] != 'sh'
553
+ @out.print <<EOF
518
554
  # For Cygwin.
519
555
  mcd() {
520
556
  local args="$1 $2 $3 $4 $5 $6 $7 $8 $9"
@@ -530,9 +566,10 @@ mcd() {
530
566
  fi
531
567
  }
532
568
  EOF
569
+ end
533
570
  end
534
571
 
535
- def info(args, options)
572
+ def info
536
573
  milkode_info
537
574
  end
538
575
 
@@ -547,12 +584,12 @@ EOF
547
584
  raise IgnoreError, "Not a package dir: '#{current_dir}'" unless package
548
585
  end
549
586
 
550
- if options[:test]
587
+ if options[:dry_run]
551
588
  # Test mode
552
589
  db_open(db_file)
553
590
  @is_display_info = true
554
591
  @is_silent = true
555
- update_dir(package.directory)
592
+ update_dir_in(package.directory)
556
593
  elsif options[:delete_all]
557
594
  # Delete all
558
595
  package.set_ignore([])
@@ -613,6 +650,14 @@ EOF
613
650
  YamlFileWrapper.yaml_file @db_dir
614
651
  end
615
652
 
653
+ def update_package_in(package)
654
+ if package.options[:update_with_git_pull]
655
+ Dir.chdir(package.directory) { system("git pull") }
656
+ end
657
+
658
+ update_dir_in(package.directory)
659
+ end
660
+
616
661
  def update_dir_in(dir)
617
662
  alert("package", File.basename(dir) )
618
663
  @package_count += 1
@@ -20,7 +20,7 @@ set :haml, :format => :html5
20
20
 
21
21
  get '/' do
22
22
  @setting = WebSetting.new
23
- @version = "0.6.0"
23
+ @version = "0.7.0"
24
24
  @package_num = Database.instance.yaml_package_num
25
25
  @file_num = Database.instance.totalRecords
26
26
  haml :index
@@ -64,13 +64,20 @@ module Milkode
64
64
  return [], 0 if packages.empty?
65
65
  else
66
66
  # パッケージ名未指定の時は現在位置もfpathsに含める
67
- fpaths << current_path + "/" unless current_path == ""
67
+ if current_path != ""
68
+ fpaths << path2fpath(current_path)
69
+ end
68
70
  end
69
71
 
70
72
  # @todo fpathを厳密に検索するには、検索結果からさらに先頭からのパスではないものを除外する
71
73
  records, total_records = searchMain(patterns, packages, fpaths, suffixs, offset, limit)
72
74
  end
73
75
 
76
+ def path2fpath(path)
77
+ pa = path.split("/")
78
+ File.join(convert_packages([pa[0]])[0], pa[1..-1].join('/'))
79
+ end
80
+
74
81
  def selectAll(offset = 0, limit = -1)
75
82
  table = @documents.select
76
83
 
@@ -3,7 +3,7 @@
3
3
  %html(lang='ja')
4
4
  %head
5
5
  %meta(charset='utf-8')
6
- %title= [@title, 'Milkode'].compact.join(' - ')
6
+ %title= [@title, @setting.home_title].compact.join(' - ')
7
7
  %link(rel="stylesheet" href="/css/milkode.css" type="text/css" media="all")
8
8
  %link(rel="stylesheet" href="/css/coderay.css" type="text/css" media="all")
9
9
  %link(rel="stylesheet" href="/css/coderay-patch.css" type="text/css" media="all")
@@ -0,0 +1,249 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'thor'
3
+ require 'milkode/cdstk/cdstk'
4
+ require 'milkode/common/dbdir.rb'
5
+ require 'milkode/cdweb/cli_cdweb'
6
+ require 'milkode/grep/cli_grep'
7
+
8
+ module Milkode
9
+ class CLI < Thor
10
+ desc "init [db_dir]", "Initialize database directory. If db_dir is omitted"
11
+ option :default, :type => :boolean, :desc => "Init default db, ENV['MILKODE_DEFAULT_DIR'] or ~/.milkode."
12
+ option :setdb, :type => :boolean, :aliases => '-s', :desc => 'Run setdb after initialization.'
13
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
14
+ def init(db_dir = nil)
15
+ if options[:help]
16
+ CLI.task_help(shell, "init")
17
+ else
18
+ db_dir = db_dir || Dbdir.default_dir
19
+ FileUtils.mkdir_p db_dir
20
+ cdstk(db_dir).init(options)
21
+ end
22
+ end
23
+
24
+ desc "add PATH", <<EOF
25
+ Add package(s) to milkode
26
+
27
+ Samples:
28
+ milk add /path/to/dir1
29
+ milk add /path/to/dir2 /path/to/dir3
30
+ milk add /path/is/*
31
+ milk add /path/to/zipfile.zip
32
+ milk add /path/to/addon.xpi
33
+ milk add http://example.com/urlfile.zip
34
+ milk add git://github.com/ongaeshi/milkode.git
35
+ EOF
36
+ option :ignore, :type => :array, :aliases => '-i', :desc => 'Ignore path.'
37
+ option :no_auto_ignore, :type => :boolean, :desc => 'Disable auto ignore (.gitignore).'
38
+ option :verbose, :type => :boolean, :aliases => '-v', :desc => 'Be verbose.'
39
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
40
+ def add(*args)
41
+ if options[:help] || args.empty?
42
+ CLI.task_help(shell, "add")
43
+ else
44
+ cdstk.add(args, options)
45
+ end
46
+ end
47
+
48
+ desc "update [keyword1 keyword2 ...]", "Update database"
49
+ option :all, :type => :boolean, :desc => "Update all."
50
+ option :verbose, :type => :boolean, :aliases => '-v', :desc => 'Be verbose.'
51
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
52
+ def update(*args)
53
+ if options[:help]
54
+ CLI.task_help(shell, "update")
55
+ else
56
+ cdstk.update(args, options)
57
+ end
58
+ end
59
+
60
+ desc "remove keyword1 [keyword2 ...]", "Remove package"
61
+ option :all, :type => :boolean, :desc => 'Remove all.'
62
+ option :force, :type => :boolean, :aliases => '-f', :desc => 'Force remove.'
63
+ option :verbose, :type => :boolean, :aliases => '-v', :desc => 'Be verbose.'
64
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
65
+ def remove(*args)
66
+ if options[:help]
67
+ CLI.task_help(shell, "remove")
68
+ else
69
+ cdstk.remove(args, options)
70
+ end
71
+ end
72
+
73
+ desc "list [package1 package2 ...]", "List package"
74
+ option :verbose, :type => :boolean, :aliases => '-v', :desc => 'Be verbose.'
75
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
76
+ def list(*args)
77
+ if options[:help]
78
+ CLI.task_help(shell, "list")
79
+ else
80
+ cdstk.list(args, options)
81
+ end
82
+ end
83
+
84
+ desc "pwd", "Display the current database"
85
+ option :default, :type => :boolean, :desc => 'Show default db, ENV[\'MILKODE_DEFAULT_DIR\'] or ~/.milkode.'
86
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
87
+ def pwd()
88
+ if options[:help]
89
+ CLI.task_help(shell, "pwd")
90
+ else
91
+ cdstk.pwd(options)
92
+ end
93
+ end
94
+
95
+ desc "cleanup", "Creanup garbage recoeds"
96
+ option :force, :type => :boolean, :aliases => '-f', :desc => 'Force cleanup.'
97
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
98
+ def cleanup
99
+ if options[:help]
100
+ CLI.task_help(shell, "cleanup")
101
+ else
102
+ cdstk.cleanup(options)
103
+ end
104
+ end
105
+
106
+ desc "rebuild [keyword1 keyword2]", "Rebuild database"
107
+ option :all, :type => :boolean, :desc => 'Rebuild all.'
108
+ option :verbose, :type => :boolean, :aliases => '-v', :desc => 'Be verbose.'
109
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
110
+ def rebuild(*args)
111
+ if options[:help]
112
+ CLI.task_help(shell, "rebuild")
113
+ else
114
+ cdstk.rebuild(args, options)
115
+ end
116
+ end
117
+
118
+ desc "dump", "Dump records"
119
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
120
+ def dump
121
+ if options[:help]
122
+ CLI.task_help(shell, "dump")
123
+ else
124
+ cdstk.dump
125
+ end
126
+ end
127
+
128
+ desc "dir [package1 package2]", "Print project root directory"
129
+ option :top, :type => :boolean
130
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
131
+ def dir(*args)
132
+ if options[:help]
133
+ CLI.task_help(shell, "dir")
134
+ else
135
+ cdstk.dir(args, options)
136
+ end
137
+ end
138
+
139
+ desc "setdb [dbpath]", "Set default db to dbpath"
140
+ option :reset, :type => :boolean, :aliases => '--default', :desc => 'Reset to the system default database.'
141
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
142
+ def setdb(dbpath = nil)
143
+ if options[:help]
144
+ CLI.task_help(shell, "setdb")
145
+ else
146
+ cdstk.setdb(dbpath, options)
147
+ end
148
+ end
149
+
150
+ desc "mcd", "Generate `mcd' command"
151
+ option :shell, :desc => 'Type of shell. bash or cygwin'
152
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
153
+ def mcd
154
+ if options[:help]
155
+ CLI.task_help(shell, "mcd")
156
+ else
157
+ cdstk.mcd(options)
158
+ end
159
+ end
160
+
161
+ desc "info", "Information of milkode status"
162
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
163
+ def info
164
+ if options[:help]
165
+ CLI.task_help(shell, "info")
166
+ else
167
+ cdstk.info
168
+ end
169
+ end
170
+
171
+ desc "ignore [path ...]", "Ignore a file or directory"
172
+ option :package, :aliases => '-p', :desc => "Package to ignore."
173
+ option :delete, :type => :boolean, :aliases => '-d', :desc => "Delete ignore setting."
174
+ option :delete_all, :type => :boolean, :desc => "Delete all ignore setting."
175
+ option :dry_run, :type => :boolean, :aliases => '-n', :desc => "Ignore setting test."
176
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
177
+ def ignore(*paths)
178
+ if options[:help]
179
+ CLI.task_help(shell, "ignore")
180
+ else
181
+ begin
182
+ cdstk.ignore(paths, options)
183
+ rescue IgnoreError => e
184
+ $stdout.puts e.message
185
+ end
186
+ end
187
+ end
188
+
189
+ desc "web", "Startup web interface"
190
+ option :db, :default => Milkode::CLI_Cdweb::select_dbdir
191
+ option :host, :default => '127.0.0.1', :aliases => '-o'
192
+ option :port, :default => 9292, :aliases => '-p'
193
+ option :server, :default => 'thin', :aliases => '-s'
194
+ option :no_browser, :type => :boolean, :default => false, :aliases => '-n', :type => :boolean, :desc => 'Do not launch browser.'
195
+ option :customize, :type => :boolean, :desc => 'Create customize file.'
196
+ option :help, :type => :boolean, :aliases => '-h', :desc => 'Help message.'
197
+ def web
198
+ if options[:help]
199
+ CLI.task_help(shell, "web")
200
+ else
201
+ opts = {
202
+ :environment => ENV['RACK_ENV'] || "development",
203
+ :pid => nil,
204
+ :Port => options[:port],
205
+ :Host => options[:host],
206
+ :AccessLog => [],
207
+ :config => "config.ru",
208
+ # ----------------------------
209
+ :server => options[:server],
210
+ :LaunchBrowser => !options[:no_browser],
211
+ :DbDir => options[:db],
212
+ }
213
+ opts[:customize] = options[:customize]
214
+ cdstk(opts[:DbDir]).assert_compatible
215
+ Milkode::CLI_Cdweb.execute_with_options($stdout, opts)
216
+ end
217
+ end
218
+
219
+ desc "grep", "Search projects"
220
+ long_desc "Search projects. See `milk grep -h` for detail."
221
+ def grep(*args)
222
+ Milkode::CLI_Grep.execute($stdout, args)
223
+ end
224
+
225
+ # --------------------------------------------------------------------------
226
+
227
+ no_tasks do
228
+ def shell
229
+ @shell ||= Thor::Base.shell.new
230
+ end
231
+ end
232
+
233
+ private
234
+
235
+ def cdstk(dir = nil)
236
+ Cdstk.new($stdout, dir || db_dir)
237
+ end
238
+
239
+ # init からはアクセスしてはいけない
240
+ def db_dir
241
+ if (Dbdir.dbdir?('.') || !Dbdir.dbdir?(Dbdir.default_dir))
242
+ '.'
243
+ else
244
+ Dbdir.default_dir
245
+ end
246
+ end
247
+
248
+ end
249
+ end