crowdin-cli 0.6.1 → 0.7.0

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
- SHA1:
3
- metadata.gz: ca670246e92cc0a4e9af4f79a32762d67b4c33c6
4
- data.tar.gz: deec43f00c30bb9d2c7cdeafa0142da169e0c1e2
2
+ SHA256:
3
+ metadata.gz: 2da15f71e0b105a4512367c3c427c88d6c174291cc0fe6885016b5bfe465e303
4
+ data.tar.gz: 6e5ad8754ed18528031226bda5177fc8864482def65a40dfdf681d73bac9612d
5
5
  SHA512:
6
- metadata.gz: 7009d7b1074c12834278b452c25ecd1f16cc337c071210e10e693201f00868b1dcdd8783a0b743eeb83a71b87f239b3e3767966d55fef3b46b007a517c71da6c
7
- data.tar.gz: 7b8d0757f24bbfa593cf6a5137c0370a5fd5328fba279b2861354f0a427e3c1228c30edaf0f58c98e08b94baa026c9414f150383c8e7dda43a0ab15ac3deb137
6
+ metadata.gz: 7f355013fad4c9fef321c3f97b9a94241b1486c23c78b6afc15e4fe7fe85a6cdee98308cc8b7ea8a7168f0b67d6f07cba053ee66fedeaa1c0bd7b281fe11d84d
7
+ data.tar.gz: 115737435f24e8807fc47d8d81285a515b27eff01fd0553794f251f0a89b4ce7623cacc905b9a4d1c54260839a9696f2226ff66c0232f45fd73c6a392bc845ed
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Crowdin-CLI Ruby is now deprecated
2
2
 
3
- [crowdin-cli-2](https://github.com/crowdin/crowdin-cli-2) is a ground-up rewrite in Java with a new flow, incredible speed, but the same core idea.
4
- This repository remains available for existing applications built on what we now call Crowdin-CLI Ruby.
3
+ > [crowdin-cli-2](https://github.com/crowdin/crowdin-cli-2) is a ground-up rewrite in Java with a new flow, incredible speed, but the same core idea.
4
+ > This repository remains available for existing applications built on what we now call Crowdin-CLI Ruby.
5
5
 
6
6
  ## Crowdin-CLI Ruby
7
7
 
@@ -480,54 +480,70 @@ command :upload do |c|
480
480
  # array containing elements common to the two arrays
481
481
  update_files = local_project_tree[:files] & remote_project_tree[:files]
482
482
  files_for_upload = local_files.select { |file| update_files.include?(file[:dest]) }
483
- files_for_upload.each do |file|
484
- file[:dest].slice!(0) if file[:dest].start_with?('/')
485
483
 
486
- params = {}
487
- params[:branch] = @branch_name if @branch_name
484
+ thread_count = 12 # tweak this number for maximum performance.
485
+ resps = []
486
+ mutex = Mutex.new
488
487
 
489
- @allowed_options.each do |option|
490
- params[option.to_sym] = file.delete(option.to_sym)
491
- end
488
+ thread_count.times.map {
489
+ Thread.new(files_for_upload, resps) do |files_for_upload, resps|
490
+ while file = mutex.synchronize { files_for_upload.pop }
491
+ file[:dest].slice!(0) if file[:dest].start_with?('/')
492
+
493
+ params = {}
494
+ params[:branch] = @branch_name if @branch_name
492
495
 
493
- print "Updating source file `#{file[:dest]}'"
496
+ @allowed_options.each do |option|
497
+ params[option.to_sym] = file.delete(option.to_sym)
498
+ end
494
499
 
495
- resp = @crowdin.update_file([] << file, params)
500
+ resp = @crowdin.update_file([] << file, params)
496
501
 
497
- case resp['files'].first[1]
498
- when 'skipped'
499
- puts "\rUpdating source file `#{file[:dest]}' - Skipped"
500
- when 'updated'
501
- puts "\rUpdating source file `#{file[:dest]}' - OK"
502
+ case resp['files'].first[1]
503
+ when 'skipped'
504
+ puts "Updating source file `#{file[:dest]}' - Skipped"
505
+ when 'updated'
506
+ puts "Updating source file `#{file[:dest]}' - OK"
507
+ end
508
+ mutex.synchronize { resps << resp }
509
+ end
502
510
  end
503
- end
511
+ }.each(&:join)
504
512
  end
505
513
 
506
514
  # Add new files to Crowdin project
507
515
  #
508
516
  add_files = local_project_tree[:files] - remote_project_tree[:files]
509
517
  files_for_add = local_files.select { |file| add_files.include?(file[:dest]) }
510
- files_for_add.each do |file|
511
- # If file path starts with / Crowdin returns error
512
- # 17: Specified directory was not found
513
- # make sure that file[:dest] not start with '/'
514
- file[:dest].slice!(0) if file[:dest].start_with?('/')
515
518
 
516
- params = {}
517
- params[:type] = file.delete(:type) if file[:type]
518
- params[:branch] = @branch_name if @branch_name
519
+ thread_count = 12
520
+ resps = []
521
+ mutex = Mutex.new
519
522
 
520
- @allowed_options.each do |option|
521
- params[option.to_sym] = file.delete(option.to_sym)
522
- end
523
+ thread_count.times.map {
524
+ Thread.new(files_for_add, resps) do |files_for_add, resps|
525
+ while file = mutex.synchronize { files_for_add.pop }
526
+ # If file path starts with / Crowdin returns error
527
+ # 17: Specified directory was not found
528
+ # make sure that file[:dest] not start with '/'
529
+ file[:dest].slice!(0) if file[:dest].start_with?('/')
530
+
531
+ params = {}
532
+ params[:type] = file.delete(:type) if file[:type]
533
+ params[:branch] = @branch_name if @branch_name
523
534
 
524
- print "Uploading source file `#{file[:dest]}'"
535
+ @allowed_options.each do |option|
536
+ params[option.to_sym] = file.delete(option.to_sym)
537
+ end
525
538
 
526
- @crowdin.add_file([] << file, params)
539
+ resp = @crowdin.add_file([] << file, params)
527
540
 
528
- puts "\rUploading source file `#{file[:dest]}' - OK"
529
- end
541
+ puts "Uploading source file `#{file[:dest]}' - OK"
530
542
 
543
+ mutex.synchronize { resps << resp }
544
+ end
545
+ end
546
+ }.each(&:join)
531
547
  end # action
532
548
  end # upload sources
533
549
 
@@ -599,7 +615,7 @@ command :upload do |c|
599
615
 
600
616
  translation_languages = supported_languages.select { |lang| project_languages.include?(lang['crowdin_code']) }
601
617
 
602
- translated_files = Hash.new{ |hash, key| hash[key] = Array.new }
618
+ translated_files = []
603
619
  dest_files = []
604
620
 
605
621
  @config['files'].each do |file|
@@ -627,7 +643,7 @@ command :upload do |c|
627
643
 
628
644
  file_translation_languages.each do |lang|
629
645
  source = export_pattern_to_path(dest, file['translation'], lang, languages_mapping)
630
- translated_files[lang['crowdin_code']] << { source: File.join(@base_path, source), dest: dest }
646
+ translated_files << { crowdin_code: lang['crowdin_code'], source: File.join(@base_path, source), dest: dest }
631
647
  end
632
648
  else
633
649
  Find.find(@base_path) do |source_path|
@@ -648,12 +664,10 @@ command :upload do |c|
648
664
 
649
665
  file_translation_languages.each do |lang|
650
666
  source = export_pattern_to_path(dest, export_pattern, lang, languages_mapping)
651
- translated_files[lang['crowdin_code']] << { source: File.join(@base_path, source), dest: dest }
667
+ translated_files << { crowdin_code: lang['crowdin_code'], source: File.join(@base_path, source), dest: dest }
652
668
  end
653
-
654
669
  end
655
670
  end # Find
656
-
657
671
  end # if
658
672
  end # @config['files']
659
673
 
@@ -667,40 +681,45 @@ command :upload do |c|
667
681
 
668
682
  common_dir = @preserve_hierarchy ? '' : find_common_directory_path(dest_files)
669
683
 
670
- translated_files.each_pair do |language, files|
671
- files.each do |file|
672
- file[:dest] = file[:dest].sub(common_dir, '')
673
- source_file = file[:source].sub(/\A#{Regexp.escape(@base_path)}/, '')
674
-
675
- if remote_project_tree[:files].include?(file[:dest])
676
- if File.exist?(file[:source])
677
- # If file path starts with / Crowdin returns error
678
- # 17: Specified directory was not found
679
- # make sure that file[:dest] not start with '/'
680
- file[:dest].slice!(0) if file[:dest].start_with?('/')
681
-
682
- print "Uploading translation file `#{source_file}'"
683
-
684
- resp = @crowdin.upload_translation([] << file, language, params)
685
-
686
- case resp['files'].first[1]
687
- when 'skipped'
688
- puts "\rUploading translation file `#{source_file}' - Skipped"
689
- when 'uploaded'
690
- puts "\rUploading translation file `#{source_file}' - OK"
691
- when 'not_allowed'
692
- puts "\rUploading translation file `#{source_file}' - is not possible"
684
+ thread_count = 12
685
+ resps = []
686
+ mutex = Mutex.new
687
+
688
+ thread_count.times.map {
689
+ Thread.new(translated_files, resps) do |translated_files, resps|
690
+ while file = mutex.synchronize { translated_files.pop }
691
+ file[:dest] = file[:dest].sub(common_dir, '')
692
+ source_file = file[:source].sub(/\A#{Regexp.escape(@base_path)}/, '')
693
+ language = file.delete(:crowdin_code)
694
+
695
+ if remote_project_tree[:files].include?(file[:dest])
696
+ if File.exist?(file[:source])
697
+ # If file path starts with / Crowdin returns error
698
+ # 17: Specified directory was not found
699
+ # make sure that file[:dest] not start with '/'
700
+ file[:dest].slice!(0) if file[:dest].start_with?('/')
701
+
702
+ resp = @crowdin.upload_translation([] << file, language, params)
703
+
704
+ case resp['files'].first[1]
705
+ when 'skipped'
706
+ puts "Uploading translation file `#{source_file}' - Skipped"
707
+ when 'uploaded'
708
+ puts "Uploading translation file `#{source_file}' - OK"
709
+ when 'not_allowed'
710
+ puts "Uploading translation file `#{source_file}' - is not possible"
711
+ end
712
+ else
713
+ puts "Warning: Local file `#{file[:source]}' does not exist"
693
714
  end
694
715
  else
695
- puts "Warning: Local file `#{file[:source]}' does not exist"
716
+ # if source file does not exist, don't upload translations
717
+ puts "Warning: Skip `#{source_file}'. Translation can not be uploaded for a non-existent source file `#{file[:dest]}'. Please upload sources first."
696
718
  end
697
- else
698
- # if source file does not exist, don't upload translations
699
- puts "Warning: Skip `#{source_file}'. Translation can not be uploaded for a non-existent source file `#{file[:dest]}'. Please upload sources first."
719
+ mutex.synchronize { resps << resp }
700
720
  end
701
721
  end
702
- end
703
-
722
+ }.each(&:join)
704
723
  end # action
705
724
  end # upload translations
706
725
 
@@ -848,7 +867,6 @@ command :download do |c|
848
867
  tempfile.close
849
868
  tempfile.unlink # delete the tempfile
850
869
  end
851
-
852
870
  end # action
853
871
  end # download
854
872
 
@@ -1,5 +1,5 @@
1
1
  module Crowdin
2
2
  module CLI
3
- VERSION = '0.6.1'
3
+ VERSION = '0.7.0'
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.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Crowdin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-31 00:00:00.000000000 Z
11
+ date: 2018-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.6.13
161
+ rubygems_version: 2.7.3
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: Crowdin CLI.