crowdin-cli 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c8c5c019062f19c359479358118e10573fddc1d
4
- data.tar.gz: d6889a079c07e20094d36f257ce151c113a5545c
3
+ metadata.gz: c178a88fbbd85d28ee2bbc8e3b88a79eb4d0cd46
4
+ data.tar.gz: d5032076e80d9bc7fff12c3cf9a40ad27759018d
5
5
  SHA512:
6
- metadata.gz: 713ece1d9226a909ce6a4a9325aebc7fafc32e7e335b4a39339109c21f807b88ec5d6f6afd9e0d20d63c119186286a2293e514e5c2d7349f1024509c4161a60d
7
- data.tar.gz: 25f10f64608b8ca072882ed73dbcd4b652b21a104718a1dd02d8f06aab9ba15c11259fa3d59178af6bc9291c2e953684a33387841aaa30b9fcd9e4872798b415
6
+ metadata.gz: c6d09b538ad1efc838e1abe5b1d6ae7da6336ef954a505fbc5cf3a9804c7cbb37bbde3dd15ad090c33026c86ae9500b1304aadd9a6cc7aaebcdb69146afdf002
7
+ data.tar.gz: aab99a8aeeff33da9f056d4816109be366379cd8d57a3c8f48c1a578eaec3323d74c7c5ff74709cc251532f7e760f8a09092291ebabc93be88583c38afe516d2
@@ -87,7 +87,7 @@ end
87
87
  #
88
88
  def construct_export_pattern(path, source, translation)
89
89
  pattern_regexp = translate_pattern_to_regexp(source)
90
- if path.match(pattern_regexp)
90
+ if pattern_regexp.names.include?('double_asterisk') and path.match(pattern_regexp)
91
91
  double_asterisk = path.match(pattern_regexp)['double_asterisk']
92
92
  translation = translation.sub('**', double_asterisk)
93
93
  end
@@ -97,19 +97,22 @@ def construct_export_pattern(path, source, translation)
97
97
  return export_pattern
98
98
  end
99
99
 
100
- # Translate a glob pattern to a regular expression
100
+ # Provides a partial implementation of translate a glob +pattern+ to a regular expression
101
+ # NOTE:
102
+ # `**` surrounded by backslashes `/` in the +pattern+
103
+ # `**` used only once in the +pattern+
101
104
  #
102
- def translate_pattern_to_regexp(pat)
105
+ def translate_pattern_to_regexp(pattern)
103
106
  i = 0
104
- n = pat.size
107
+ n = pattern.size
105
108
  res = ''
106
109
  while i < n
107
- c = pat[i]
110
+ c = pattern[i]
108
111
  i = i + 1
109
112
  if c == '*'
110
113
  j = i
111
- if j < n and pat[j] == '*'
112
- res << '(?<double_asterisk>.*)'
114
+ if j < n and pattern[j] == '*'
115
+ res[-1] = '(\/)?(?<double_asterisk>.*)?'
113
116
  i = j + 1
114
117
  else
115
118
  res << '(.*)'
@@ -174,7 +177,7 @@ def unzip_file(zip, dest, files_list)
174
177
 
175
178
  Zip::ZipFile.open(zip) do |zip_file|
176
179
  zip_file.select{ |f| f.file? }.each do |f|
177
- file = files_list[f.name]
180
+ file = files_list['/' + f.name]
178
181
  if file
179
182
  f_path = File.join(dest, file)
180
183
  FileUtils.mkdir_p(File.dirname(f_path))
@@ -247,9 +250,10 @@ EOS
247
250
  end
248
251
 
249
252
  if File.exist?("#{@base_path}#{file['source']}")
250
- dest_files << file['source']
253
+ dest = file['source']
254
+ dest_files << dest
251
255
 
252
- local_file = { dest: file['source'], source: "#{@base_path}#{file['source']}", export_pattern: file['translation'] }
256
+ local_file = { dest: dest, source: "#{@base_path}#{file['source']}", export_pattern: file['translation'] }
253
257
  # Used only when uploading CSV file to define data columns mapping.
254
258
  local_file.merge!({ sheme: file['scheme'] }) if file.has_key?('scheme')
255
259
  local_file.merge!({ first_line_contains_header: file['first_line_contains_header'] }) if file.has_key?('first_line_contains_header')
@@ -275,7 +279,7 @@ EOS
275
279
  exit_now!("nothing to upload. See http://crowdin.net/page/cli-tool#configuration-file for more details.")
276
280
  end
277
281
 
278
- common_dir = find_common_directory_path(dest_files)
282
+ common_dir = @preserve_hierarchy ? '' : find_common_directory_path(dest_files)
279
283
 
280
284
  local_project_tree = get_local_files_hierarchy(local_files.collect{ |h| h[:dest].sub(common_dir, '') })
281
285
 
@@ -296,7 +300,7 @@ EOS
296
300
  update_files = local_project_tree[:files] & remote_project_tree[:files]
297
301
  files_for_upload = local_files.select{ |file| update_files.include?(file[:dest]) }
298
302
  files_for_upload.each do |file|
299
- print "Updating file `#{file[:dest]}'"
303
+ print "Updating source file `#{file[:dest]}'"
300
304
 
301
305
  params = {}
302
306
  params[:scheme] = file.delete(:sheme)
@@ -305,9 +309,9 @@ EOS
305
309
  resp = @crowdin.update_file([] << file, params)
306
310
  case resp['files'].first[1]
307
311
  when 'skipped'
308
- puts "\rUpdating file `#{file[:dest]}' - Skipped"
312
+ puts "\rUpdating source file `#{file[:dest]}' - Skipped"
309
313
  when 'updated'
310
- puts "\rUpdating file `#{file[:dest]}' - OK"
314
+ puts "\rUpdating source file `#{file[:dest]}' - OK"
311
315
  end
312
316
  end
313
317
  end
@@ -317,14 +321,14 @@ EOS
317
321
  add_files = local_project_tree[:files] - remote_project_tree[:files]
318
322
  files_for_add = local_files.select{ |file| add_files.include?(file[:dest]) }
319
323
  files_for_add.each do |file|
320
- print "Uploading file `#{file[:dest]}'"
324
+ print "Uploading source file `#{file[:dest]}'"
321
325
 
322
326
  params = {}
323
327
  params[:scheme] = file.delete(:sheme)
324
328
  params[:first_line_contains_header] = file.delete(:first_line_contains_header)
325
329
 
326
330
  resp = @crowdin.add_file([] << file, params)
327
- puts "\rUploading file `#{file[:dest]}' - OK"
331
+ puts "\rUploading source file `#{file[:dest]}' - OK"
328
332
  end
329
333
 
330
334
  end # action
@@ -416,7 +420,7 @@ EOS
416
420
  exit_now!("Warning: nothing to upload. See http://crowdin.net/page/cli-tool#configuration-file for more details.")
417
421
  end
418
422
 
419
- common_dir = find_common_directory_path(dest_files)
423
+ common_dir = @preserve_hierarchy ? '' : find_common_directory_path(dest_files)
420
424
 
421
425
  translated_files.each do |language, files|
422
426
  files.each do |file|
@@ -424,14 +428,14 @@ EOS
424
428
 
425
429
  if remote_project_tree[:files].include?(file[:dest])
426
430
  if File.exist?(file[:source])
427
- print "Uploading `#{file[:source].sub(@base_path, '')}'"
431
+ print "Uploading translation file `#{file[:source].sub(@base_path, '')}'"
428
432
 
429
433
  resp = @crowdin.upload_translation([] << file, language, params)
430
434
  case resp['files'].first[1]
431
435
  when 'skipped'
432
- puts "\rUploading `#{file[:source].sub(@base_path, '')}' - Skipped"
436
+ puts "\rUploading translation `#{file[:source].sub(@base_path, '')}' - Skipped"
433
437
  when 'uploaded'
434
- puts "\rUploading `#{file[:source].sub(@base_path, '')}' - OK"
438
+ puts "\rUploading translation `#{file[:source].sub(@base_path, '')}' - OK"
435
439
  end
436
440
  else
437
441
  puts "Warning: Local file `#{file[:source]}' does not exists"
@@ -559,7 +563,7 @@ EOS
559
563
  Can't find configuration file (default `crowdin.yaml').
560
564
  Type `crowdin-cli help` to know how to specify custom configuration file
561
565
 
562
- See http://crowdin.net/page/cli-client#configuration-file for more details
566
+ See http://crowdin.net/page/cli-tool#configuration-file for more details
563
567
  EOS
564
568
  end
565
569
 
@@ -567,17 +571,26 @@ EOS
567
571
  file['source'] = '/' + file['source'] unless file['source'].start_with?('/')
568
572
  file['translation'] = '/' + file['translation'] unless file['translation'].start_with?('/')
569
573
 
570
- if file['source'].scan('**').size > 1
571
- exit_now! <<EOS
572
- Pattern `#{file['source']}` is not valid. The mask `**` can be used only once in the source pattern.
574
+ if file['source'].include?('**')
575
+ if file['source'].scan('**').size > 1
576
+ exit_now! <<EOS
577
+ Source pattern `#{file['source']}` is not valid. The mask `**` can be used only once in the source pattern.
573
578
  EOS
574
- elsif file['source'].scan('**').size == 1 and !file['source'].match(/\/\*\*\//)
575
- exit_now! <<EOS
576
- Pattern `#{file['source']}` is not valid. The mask `**` must be surrounded by backslashes `/` in the source pattern.
579
+ elsif file['source'].scan('**').size == 1 and !file['source'].match(/\/\*\*\//)
580
+ exit_now! <<EOS
581
+ Source pattern `#{file['source']}` is not valid. The mask `**` must be surrounded by backslashes `/` in the source pattern.
577
582
  EOS
583
+ end
584
+ else
585
+ if file['translation'].include?('**')
586
+ exit_now! <<EOS
587
+ Translation pattern `#{file['translation']}` is not valid. The mask `**` can't be used.
588
+ When using `**` in 'translation' pattern it will always contain sub-path from 'source' for certain file.
589
+ EOS
590
+ end
578
591
  end
579
592
 
580
- end
593
+ end # @config['files']
581
594
 
582
595
  if @config['base_path']
583
596
  @base_path = @config['base_path']
@@ -588,6 +601,26 @@ Warning: Configuration file misses parameter `base_path` that defines your proje
588
601
  EOS
589
602
  end
590
603
 
604
+ if @config['target_path']
605
+ @target_path = @config['target_path']
606
+ else
607
+ @target_path = ''
608
+ end
609
+
610
+ @preserve_hierarchy = false
611
+ if @config['preserve_hierarchy']
612
+ @preserve_hierarchy = case @config['preserve_hierarchy']
613
+ when true
614
+ true
615
+ when false
616
+ false
617
+ else
618
+ exit_now! <<EOS
619
+ Parameter `preserve_hierarchy` allows values of true or false.
620
+ EOS
621
+ end
622
+ end
623
+
591
624
  Crowdin::API.log = Logger.new($stderr) if global[:v]
592
625
  @crowdin = Crowdin::API.new(api_key: @config['api_key'], project_id: @config['project_identifier'], base_url: @config['base_url'] || 'http://api.crowdin.net')
593
626
  begin
@@ -1,5 +1,5 @@
1
1
  module Crowdin
2
2
  module CLI
3
- VERSION = '0.1.5'
3
+ VERSION = '0.1.6'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crowdin-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Crowdin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-23 00:00:00.000000000 Z
11
+ date: 2013-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake