Class: Locca::OneskySyncAction
- Inherits:
-
Object
- Object
- Locca::OneskySyncAction
- Defined in:
- lib/locca/actions/onesky_sync_action.rb
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(project, onesky, collection_builder, collection_writer, collections_generator, collection_merger) ⇒ OneskySyncAction
constructor
A new instance of OneskySyncAction.
- #sync(prune_missing_strings = false) ⇒ Object
Constructor Details
#initialize(project, onesky, collection_builder, collection_writer, collections_generator, collection_merger) ⇒ OneskySyncAction
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/locca/actions/onesky_sync_action.rb', line 34 def initialize(project, onesky, collection_builder, collection_writer, collections_generator, collection_merger) @project = project @collections_generator = collections_generator @collection_merger = collection_merger @collection_builder = collection_builder @collection_writer = collection_writer @onesky = onesky @langs = @project.langs() @generated_collections = @collections_generator.generate() @project.collection_names.each do |collection_name| existing_collection = nil @generated_collections.each do |generated_collection| if generated_collection.name == collection_name existing_collection = generated_collection break end end if existing_collection == nil collection_path = @project.path_for_collection(collection_name, @project.base_lang) collection = @collection_builder.collection_at_path(collection_path) @generated_collections.push(collection) end end end |
Instance Method Details
#fetch ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/locca/actions/onesky_sync_action.rb', line 64 def fetch() # 1 @generated_collections.each do |generated_collection| @langs.each do |lang| max_attempts = 3 for attempt in 1..max_attempts do print "[*] #{@project.name}: fetch: #{lang}/#{generated_collection.name}\n" begin data = @onesky.fetch_translations(lang, @project.full_collection_name(generated_collection.name)) rescue Exception => ex if attempt == max_attempts raise ex end puts "[!] #{ex}" sleep 2 else break end end fetched_collection = @collection_builder.collection_from_datastring(data) local_collection_path = @project.path_for_collection(generated_collection.name, lang) local_collection = @collection_builder.collection_at_path(local_collection_path) # 2 print "[*] #{@project.name}: merge: onesky -> #{lang}/#{generated_collection.name}\n" @collection_merger.merge(fetched_collection, local_collection, CollectionMerger::ACTION_ADD | CollectionMerger::ACTION_UPDATE) @collection_writer.write_to_path(local_collection, local_collection_path) end end end |
#sync(prune_missing_strings = false) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/locca/actions/onesky_sync_action.rb', line 97 def sync(prune_missing_strings = false) fetch() # 3 @generated_collections.each do |generated_collection| @langs.each do |lang| print "[*] #{@project.name}: merge: code -> #{lang}/#{generated_collection.name}\n" local_collection_path = @project.path_for_collection(generated_collection.name, lang) local_collection = @collection_builder.collection_at_path(local_collection_path) @collection_merger.merge(generated_collection, local_collection, (CollectionMerger::ACTION_ADD | CollectionMerger::ACTION_DELETE | CollectionMerger::ACTION_UPDATE_COMMENTS)) @collection_writer.write_to_path(local_collection, local_collection_path) end end if @project.prevent_sync_without_comments? lang = @project.base_lang @generated_collections.each do |generated_collection| print "[*] #{@project.name}: check: #{lang}/#{generated_collection.name}\n" local_collection_path = @project.path_for_collection(generated_collection.name, lang) local_collection = @collection_builder.collection_at_path(local_collection_path) keys = local_collection.keys_without_comments if keys.length > 0 raise "Keys without comments:\n" + keys.join("\n") end end end # 4 @generated_collections.each do |generated_collection| collection_path = @project.path_for_collection(generated_collection.name, @project.base_lang()) max_attempts = 3 for attempt in 1..max_attempts do print "[*] #{@project.name}: upload: #{@project.base_lang}/#{generated_collection.name}\n" begin @onesky.upload_file(collection_path, @project.one_sky_file_format, prune_missing_strings) rescue Exception => ex if attempt == max_attempts raise ex end puts "[!] #{ex}" sleep 2 else break end end end end |