logaling-command 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,13 @@
1
+ = 0.1.4 / 2012-03-29
2
+
3
+ * インデックス時にオフラインインデックスを利用することで速度が改善されました。(groonga >= 2.0.0)
4
+
5
+ * --logaling-home に存在しない path を渡すと例外があがってしまう不具合を修正しました。
6
+
7
+ * windows で import 実行時に CSV読み込みエラーが起こる不具合を修正しました。
8
+
9
+ * windows でインストール直後に コマンドを実行してもエラーが起こる不具合を修正しました。
10
+
1
11
  = 0.1.3 / 2012-02-29
2
12
 
3
13
  * Mozilla Japan プロジェクトの対訳用語集をインポートできるようにしました。(kdmsnr さん)
@@ -17,6 +17,7 @@
17
17
 
18
18
  require 'thor'
19
19
  require 'rainbow'
20
+ require 'pathname'
20
21
  require "logaling/repository"
21
22
  require "logaling/glossary"
22
23
  require "logaling/config"
@@ -92,6 +93,8 @@ module Logaling::Command
92
93
  @repository.import(Logaling::ExternalGlossary.get(external_glossary))
93
94
  @repository.index
94
95
  end
96
+ rescue Logaling::CommandFailed => e
97
+ say e.message
95
98
  rescue Logaling::ExternalGlossaryNotFound
96
99
  say "'#{external_glossary}' can't find in import list."
97
100
  say "Try 'loga import --list' and confirm import list."
@@ -124,17 +127,25 @@ module Logaling::Command
124
127
  say "#{@config.glossary} is not yet registered."
125
128
  end
126
129
 
127
- desc 'config [KEY] [VALUE] [--global(optional)]', 'Set config.'
128
- method_option "global", type: :boolean, default: false
129
- def config(key, value)
130
- config_path = options["global"] ? File.join(@logaling_home, "config") : @project_config_path
131
- config = Logaling::Config.load(config_path)
132
- config.add(key, value)
133
- config.save(config_path)
134
- say "Successfully set config."
135
- rescue Logaling::CommandFailed => e
136
- say e.message
137
- end
130
+ desc 'config [KEY] [VALUE] [--global(optional)]', 'Set config.'
131
+ method_option "global", type: :boolean, default: false
132
+ def config(key, value)
133
+ if options["global"]
134
+ unless File.exist?(@logaling_home)
135
+ FileUtils.mkdir_p(@logaling_home) rescue raise Logaling::CommandFailed, "Imput existing directory as logaling-home."
136
+ end
137
+ config_path = File.join(@logaling_home, "config")
138
+ else
139
+ raise Logaling::CommandFailed, "Can't found .logaling" unless @project_config_path
140
+ config_path = @project_config_path
141
+ end
142
+ config = Logaling::Config.load(config_path)
143
+ config.add(key, value)
144
+ config.save(config_path)
145
+ say "Successfully set config."
146
+ rescue Logaling::CommandFailed => e
147
+ say e.message
148
+ end
138
149
 
139
150
  desc 'add [SOURCE TERM] [TARGET TERM] [NOTE(optional)]', 'Add term to glossary.'
140
151
  def add(source_term, target_term, note='')
@@ -144,6 +155,7 @@ module Logaling::Command
144
155
  "target-language" => "input target-language code '-T <target-language code>'"
145
156
  }
146
157
  @config.check_required_option(required_options)
158
+ check_logaling_home_exists
147
159
  @repository.index
148
160
 
149
161
  if @repository.bilingual_pair_exists?(source_term, target_term, @config.glossary)
@@ -153,6 +165,8 @@ module Logaling::Command
153
165
  glossary.add(source_term, target_term, note)
154
166
  rescue Logaling::CommandFailed, Logaling::TermError => e
155
167
  say e.message
168
+ rescue Logaling::GlossaryNotFound => e
169
+ say "Try 'loga new or register' first."
156
170
  end
157
171
 
158
172
  desc 'delete [SOURCE TERM] [TARGET TERM(optional)] [--force(optional)]', 'Delete term.'
@@ -164,6 +178,7 @@ module Logaling::Command
164
178
  "target-language" => "input target-language code '-T <target-language code>'"
165
179
  }
166
180
  @config.check_required_option(required_options)
181
+ check_logaling_home_exists
167
182
 
168
183
  if target_term
169
184
  glossary.delete(source_term, target_term)
@@ -184,6 +199,7 @@ module Logaling::Command
184
199
  "target-language" => "input target-language code '-T <target-language code>'"
185
200
  }
186
201
  @config.check_required_option(required_options)
202
+ check_logaling_home_exists
187
203
  @repository.index
188
204
 
189
205
  if @repository.bilingual_pair_exists_and_has_same_note?(source_term, new_target_term, note, @config.glossary)
@@ -203,6 +219,7 @@ module Logaling::Command
203
219
  method_option "no-color", type: :boolean, default: false
204
220
  method_option "dictionary", type: :boolean, default: false, aliases: "--dict"
205
221
  def lookup(source_term)
222
+ check_logaling_home_exists
206
223
  @repository.index
207
224
  terms = @repository.lookup(source_term, glossary, options["dictionary"])
208
225
  unless terms.empty?
@@ -243,6 +260,7 @@ module Logaling::Command
243
260
  "target-language" => "input target-language code '-T <target-language code>'"
244
261
  }
245
262
  @config.check_required_option(required_options)
263
+ check_logaling_home_exists
246
264
  @repository.index
247
265
  terms = @repository.show_glossary(glossary)
248
266
  unless terms.empty?
@@ -264,6 +282,7 @@ module Logaling::Command
264
282
  desc 'list', 'Show glossary list.'
265
283
  method_option "no-pager", type: :boolean, default: false
266
284
  def list
285
+ check_logaling_home_exists
267
286
  @repository.index
268
287
  glossaries = @repository.list
269
288
  unless glossaries.empty?
@@ -280,6 +299,10 @@ module Logaling::Command
280
299
  end
281
300
 
282
301
  private
302
+ def windows?
303
+ RUBY_PLATFORM =~ /win32|mingw32/i
304
+ end
305
+
283
306
  def glossary
284
307
  @glossary ||= Logaling::Glossary.new(@config.glossary, @config.source_language, @config.target_language, @logaling_home)
285
308
  end
@@ -292,12 +315,12 @@ module Logaling::Command
292
315
  def find_dotfile
293
316
  dir = Dir.pwd
294
317
  searched_path = []
295
- while(dir) do
318
+ loop do
296
319
  path = File.join(dir, '.logaling')
297
320
  if File.exist?(path)
298
321
  return path
299
322
  else
300
- if dir != "/"
323
+ unless Pathname.new(dir).root?
301
324
  searched_path << dir
302
325
  dir = File.dirname(dir)
303
326
  else
@@ -318,7 +341,7 @@ module Logaling::Command
318
341
  # http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby
319
342
  def run_pager
320
343
  return if options["no-pager"]
321
- return if ::RUBY_PLATFORM =~ /win32/
344
+ return if windows?
322
345
  return unless STDOUT.tty?
323
346
 
324
347
  read, write = IO.pipe
@@ -353,6 +376,12 @@ module Logaling::Command
353
376
  display_string
354
377
  end
355
378
 
379
+ def check_logaling_home_exists
380
+ unless File.exist?(@logaling_home)
381
+ raise Logaling::CommandFailed, "Imput existing directory as logaling-home."
382
+ end
383
+ end
384
+
356
385
  def printer(source_string, target_string, note=nil,
357
386
  glossary_name, max_str_size, i, last)
358
387
  case options["output"]
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Logaling
19
19
  module Command
20
- VERSION = "0.1.3"
20
+ VERSION = "0.1.4"
21
21
  end
22
22
  end
@@ -53,7 +53,7 @@ module Logaling
53
53
 
54
54
  def load_glossary_csv(path, sep=",")
55
55
  glossary = []
56
- CSV.open(path, "r", {:col_sep => sep}) do |csv|
56
+ CSV.open(path, "r:utf-8", {:col_sep => sep}) do |csv|
57
57
  csv.each do |row|
58
58
  glossary << {"source_term" => row[0], "target_term" => row[1], "note" => ""} if row.size >= 2
59
59
  end
@@ -76,6 +76,8 @@ module Logaling
76
76
  glossary = Glossary.load_glossary(source_path)
77
77
  glossary << build_term(source_term, target_term, note)
78
78
  dump_glossary(glossary)
79
+ rescue
80
+ raise GlossaryNotFound
79
81
  end
80
82
 
81
83
  def update(source_term, target_term, new_target_term, note)
@@ -69,6 +69,8 @@ module Logaling
69
69
  end
70
70
 
71
71
  def index_glossary(glossary, glossary_name, glossary_source, source_language, target_language, indexed_at)
72
+ delete_terms if offline_index?
73
+
72
74
  deindex_glossary(glossary_name, glossary_source)
73
75
 
74
76
  add_glossary_source(glossary_source, indexed_at)
@@ -79,6 +81,8 @@ module Logaling
79
81
  note = term['note']
80
82
  add_translation(glossary_name, glossary_source, source_language, target_language, source_term, target_term, note)
81
83
  end
84
+
85
+ create_terms if offline_index?
82
86
  end
83
87
 
84
88
  def lookup(source_term, glossary_source=nil)
@@ -267,6 +271,27 @@ module Logaling
267
271
  records.expression.close
268
272
  end
269
273
 
274
+ def delete_terms
275
+ if Groonga['terms']
276
+ Groonga::Schema.define do |schema|
277
+ schema.remove_table("terms")
278
+ end
279
+ end
280
+ end
281
+
282
+ def create_terms
283
+ Groonga::Schema.define do |schema|
284
+ schema.create_table("terms",
285
+ :type => :patricia_trie,
286
+ :key_type => "ShortText",
287
+ :key_normalize => true,
288
+ :default_tokenizer => "TokenBigram") do |table|
289
+ table.index("translations.source_term")
290
+ table.index("translations.target_term")
291
+ end
292
+ end
293
+ end
294
+
270
295
  def add_translation(glossary_name, glossary_source, source_language, target_language, source_term, target_term, note)
271
296
  Groonga["translations"].add(:glossary => glossary_name,
272
297
  :glossary_source => glossary_source,
@@ -314,16 +339,8 @@ module Logaling
314
339
  table.text("target_term")
315
340
  table.text("note")
316
341
  end
317
-
318
- schema.create_table("terms",
319
- :type => :patricia_trie,
320
- :key_type => "ShortText",
321
- :key_normalize => true,
322
- :default_tokenizer => "TokenBigram") do |table|
323
- table.index("translations.source_term")
324
- table.index("translations.target_term")
325
- end
326
342
  end
343
+ create_terms
327
344
  end
328
345
 
329
346
  def remove_schema
@@ -396,5 +413,10 @@ module Logaling
396
413
  def add_config(conf_key, conf_value)
397
414
  Groonga["configurations"].add(:conf_key => conf_key, :conf_value => conf_value)
398
415
  end
416
+
417
+ def offline_index?
418
+ # use online index if LOGALING_OFFLINE_INDEX=no
419
+ ENV["LOGALING_OFFLINE_INDEX"] != "no"
420
+ end
399
421
  end
400
422
  end
@@ -32,6 +32,8 @@ module Logaling
32
32
  else
33
33
  raise GlossaryAlreadyRegistered, register_name
34
34
  end
35
+ rescue
36
+ raise Logaling::CommandFailed, "Failed register #{register_name} to #{logaling_projects_path}."
35
37
  end
36
38
 
37
39
  def unregister(register_name)
@@ -48,6 +50,8 @@ module Logaling
48
50
  Dir.chdir(cache_path) do
49
51
  glossary.import
50
52
  end
53
+ rescue
54
+ raise Logaling::CommandFailed, "Failed import #{glossary.class.name} to #{cache_path}."
51
55
  end
52
56
 
53
57
  def lookup(source_term, glossary_source, dictionary=false)
@@ -28,7 +28,7 @@ describe Logaling::Command::Application do
28
28
  let(:repository) { Logaling::Repository.new(logaling_home) }
29
29
 
30
30
  before do
31
- FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
31
+ FileUtils.rm_rf(File.join(logaling_home, 'projects', 'spec'))
32
32
  end
33
33
 
34
34
  describe '#new' do
@@ -89,7 +89,7 @@ describe Logaling::Command::Application do
89
89
 
90
90
  context "when can not find .logaling" do
91
91
  before(:all) do
92
- FileUtils.remove_entry_secure(logaling_config, true)
92
+ FileUtils.rm_rf(logaling_config)
93
93
  @stdout = capture(:stdout) {command.register}
94
94
  end
95
95
 
@@ -122,7 +122,7 @@ describe Logaling::Command::Application do
122
122
 
123
123
  context "when can not find .logaling" do
124
124
  before do
125
- #FileUtils.remove_entry_secure(logaling_config, true)
125
+ #FileUtils.rm_rf(logaling_config)
126
126
  end
127
127
 
128
128
  context "and call without option" do
@@ -217,7 +217,40 @@ describe Logaling::Command::Application do
217
217
  end
218
218
 
219
219
  after do
220
- FileUtils.remove_entry_secure(global_config, true)
220
+ FileUtils.rm_rf(global_config)
221
+ end
222
+ end
223
+
224
+ context 'when logaling_home not exists' do
225
+ context 'with argument "target-language"' do
226
+ before do
227
+ command.new('spec', 'en')
228
+ FileUtils.rm_rf(@logaling_home)
229
+ command.config("target-language", "fr")
230
+ end
231
+
232
+ it 'should overwrite target-language' do
233
+ should include "--target-language fr"
234
+ end
235
+ end
236
+
237
+ context 'with argument "--global" and "target-language"' do
238
+ before do
239
+ command.options = base_options.merge("global" => true)
240
+ command.new('spec', 'en')
241
+ FileUtils.rm_rf(@logaling_home)
242
+ command.config("target-language", "ja")
243
+ end
244
+
245
+ subject { File.read(global_config) }
246
+
247
+ it 'should create {logaling_home}/config and write target-language' do
248
+ should include "--target-language ja"
249
+ end
250
+
251
+ after do
252
+ FileUtils.rm_rf(global_config)
253
+ end
221
254
  end
222
255
  end
223
256
  end
@@ -281,7 +314,7 @@ describe Logaling::Command::Application do
281
314
  end
282
315
 
283
316
  after do
284
- FileUtils.remove_entry_secure(global_config, true)
317
+ FileUtils.rm_rf(global_config)
285
318
  end
286
319
  end
287
320
  end
@@ -393,8 +426,8 @@ describe Logaling::Command::Application do
393
426
 
394
427
  context "and called with '--force=true'" do
395
428
  before do
396
- FileUtils.remove_entry_secure(logaling_config, true)
397
- FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
429
+ FileUtils.rm_rf(logaling_config)
430
+ FileUtils.rm_rf(File.join(logaling_home, 'projects', 'spec'))
398
431
  command.options = base_options.merge("force" => true)
399
432
  command.new('spec', 'en', 'ja')
400
433
  command.add('term', '用語1', '備考')
@@ -437,7 +470,7 @@ describe Logaling::Command::Application do
437
470
  end
438
471
 
439
472
  after do
440
- FileUtils.remove_entry_secure(csv_path, true)
473
+ FileUtils.rm_rf(csv_path)
441
474
  end
442
475
  end
443
476
 
@@ -472,7 +505,7 @@ describe Logaling::Command::Application do
472
505
  end
473
506
 
474
507
  after do
475
- FileUtils.remove_entry_secure(logaling_config, true)
476
- FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
508
+ FileUtils.rm_rf(logaling_config)
509
+ FileUtils.rm_rf(File.join(logaling_home, 'projects', 'spec'))
477
510
  end
478
511
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logaling-command
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,11 +13,11 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2012-02-29 00:00:00.000000000Z
16
+ date: 2012-03-29 00:00:00.000000000Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: thor
20
- requirement: &2154467460 !ruby/object:Gem::Requirement
20
+ requirement: &2154363820 !ruby/object:Gem::Requirement
21
21
  none: false
22
22
  requirements:
23
23
  - - ! '>='
@@ -25,10 +25,10 @@ dependencies:
25
25
  version: 0.14.6
26
26
  type: :runtime
27
27
  prerelease: false
28
- version_requirements: *2154467460
28
+ version_requirements: *2154363820
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: bundler
31
- requirement: &2154466980 !ruby/object:Gem::Requirement
31
+ requirement: &2154363340 !ruby/object:Gem::Requirement
32
32
  none: false
33
33
  requirements:
34
34
  - - ! '>='
@@ -36,10 +36,10 @@ dependencies:
36
36
  version: '1.0'
37
37
  type: :runtime
38
38
  prerelease: false
39
- version_requirements: *2154466980
39
+ version_requirements: *2154363340
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rroonga
42
- requirement: &2154466500 !ruby/object:Gem::Requirement
42
+ requirement: &2154362860 !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements:
45
45
  - - ! '>='
@@ -47,10 +47,10 @@ dependencies:
47
47
  version: 1.3.0
48
48
  type: :runtime
49
49
  prerelease: false
50
- version_requirements: *2154466500
50
+ version_requirements: *2154362860
51
51
  - !ruby/object:Gem::Dependency
52
52
  name: rainbow
53
- requirement: &2154466120 !ruby/object:Gem::Requirement
53
+ requirement: &2154362480 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
56
  - - ! '>='
@@ -58,10 +58,10 @@ dependencies:
58
58
  version: '0'
59
59
  type: :runtime
60
60
  prerelease: false
61
- version_requirements: *2154466120
61
+ version_requirements: *2154362480
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: nokogiri
64
- requirement: &2154465660 !ruby/object:Gem::Requirement
64
+ requirement: &2154362020 !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ! '>='
@@ -69,10 +69,10 @@ dependencies:
69
69
  version: '0'
70
70
  type: :runtime
71
71
  prerelease: false
72
- version_requirements: *2154465660
72
+ version_requirements: *2154362020
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: activesupport
75
- requirement: &2154465240 !ruby/object:Gem::Requirement
75
+ requirement: &2154361600 !ruby/object:Gem::Requirement
76
76
  none: false
77
77
  requirements:
78
78
  - - ! '>='
@@ -80,10 +80,10 @@ dependencies:
80
80
  version: '0'
81
81
  type: :runtime
82
82
  prerelease: false
83
- version_requirements: *2154465240
83
+ version_requirements: *2154361600
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: rake
86
- requirement: &2156056340 !ruby/object:Gem::Requirement
86
+ requirement: &2154361180 !ruby/object:Gem::Requirement
87
87
  none: false
88
88
  requirements:
89
89
  - - ! '>='
@@ -91,10 +91,10 @@ dependencies:
91
91
  version: '0'
92
92
  type: :development
93
93
  prerelease: false
94
- version_requirements: *2156056340
94
+ version_requirements: *2154361180
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: rspec
97
- requirement: &2156055920 !ruby/object:Gem::Requirement
97
+ requirement: &2154360760 !ruby/object:Gem::Requirement
98
98
  none: false
99
99
  requirements:
100
100
  - - ! '>='
@@ -102,7 +102,7 @@ dependencies:
102
102
  version: '0'
103
103
  type: :development
104
104
  prerelease: false
105
- version_requirements: *2156055920
105
+ version_requirements: *2154360760
106
106
  description: A command line interface for logaling.
107
107
  email:
108
108
  - koji.shimada@enishi-tech.com