mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Avoid using a temporary file to extract the old translations
This commit is contained in:
parent
af40ab5b01
commit
c1d57d4b0d
@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
import polib
|
import polib
|
||||||
import git
|
import git
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
|
||||||
import argparse
|
import argparse
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
@ -25,9 +23,9 @@ def list_entries(file):
|
|||||||
|
|
||||||
return entries
|
return entries
|
||||||
|
|
||||||
def process_file(actual_file_path, previous_version_file_path, restore_missing):
|
def process_file(actual_file_path, previous_version_file_data, restore_missing):
|
||||||
actual_file = polib.pofile(actual_file_path, wrapwidth=10000)
|
actual_file = polib.pofile(actual_file_path, wrapwidth=10000)
|
||||||
previous_file = polib.pofile(previous_version_file_path, wrapwidth=10000)
|
previous_file = polib.pofile(previous_version_file_data, wrapwidth=10000)
|
||||||
|
|
||||||
previous_entries = list_entries(previous_file)
|
previous_entries = list_entries(previous_file)
|
||||||
actual_entries = list_entries(actual_file)
|
actual_entries = list_entries(actual_file)
|
||||||
@ -91,11 +89,9 @@ for language_dir in language_dirs:
|
|||||||
for translation_file in os.listdir(language_dir):
|
for translation_file in os.listdir(language_dir):
|
||||||
if translation_file.endswith('.po'):
|
if translation_file.endswith('.po'):
|
||||||
translation_file_path = '/'.join([language_dir, translation_file])
|
translation_file_path = '/'.join([language_dir, translation_file])
|
||||||
blob = repo.commit(args.previous_version).tree / translation_file_path
|
|
||||||
print(f'Processing file {translation_file_path}')
|
print(f'Processing file {translation_file_path}')
|
||||||
with tempfile.NamedTemporaryFile(suffix='.po') as tmp_file:
|
blob = repo.commit(args.previous_version).tree / translation_file_path
|
||||||
tmp_file.write(blob.data_stream.read())
|
process_file(translation_file_path, blob.data_stream.read().decode('utf-8'), args.restore_missing)
|
||||||
process_file(translation_file_path, tmp_file.name, args.restore_missing)
|
|
||||||
|
|
||||||
with open('report.csv', 'w') as report_file:
|
with open('report.csv', 'w') as report_file:
|
||||||
for missing_key, files in missing_keys.items():
|
for missing_key, files in missing_keys.items():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user