mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
9ec56cbe27
commit
60a99e2cae
@ -215,32 +215,34 @@ class GetTranslations(Translations): # {{{
|
|||||||
description = 'Get updated translations from Launchpad'
|
description = 'Get updated translations from Launchpad'
|
||||||
BRANCH = 'lp:~kovid/calibre/translations'
|
BRANCH = 'lp:~kovid/calibre/translations'
|
||||||
|
|
||||||
@classmethod
|
@property
|
||||||
def modified_translations(cls):
|
def modified_translations(self):
|
||||||
raw = subprocess.Popen(['bzr', 'status'],
|
raw = subprocess.Popen(['bzr', 'status', '-S', self.PATH],
|
||||||
stdout=subprocess.PIPE).stdout.read().strip()
|
stdout=subprocess.PIPE).stdout.read().strip()
|
||||||
|
ans = []
|
||||||
for line in raw.splitlines():
|
for line in raw.splitlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line.startswith(cls.PATH) and line.endswith('.po'):
|
if line.startswith('M') and line.endswith('.po'):
|
||||||
yield line
|
ans.append(line.split()[-1])
|
||||||
|
return ans
|
||||||
|
|
||||||
def run(self, opts):
|
def run(self, opts):
|
||||||
if len(list(self.modified_translations())) == 0:
|
if not self.modified_translations:
|
||||||
subprocess.check_call(['bzr', 'merge', self.BRANCH])
|
subprocess.check_call(['bzr', 'merge', self.BRANCH])
|
||||||
if len(list(self.modified_translations())) == 0:
|
|
||||||
print 'No updated translations available'
|
|
||||||
else:
|
|
||||||
subprocess.check_call(['bzr', 'commit', '-m',
|
|
||||||
'IGN:Updated translations', self.PATH])
|
|
||||||
self.check_for_errors()
|
self.check_for_errors()
|
||||||
|
|
||||||
@classmethod
|
if self.modified_translations:
|
||||||
def check_for_errors(cls):
|
subprocess.check_call(['bzr', 'commit', '-m',
|
||||||
|
'IGN:Updated translations', self.PATH])
|
||||||
|
else:
|
||||||
|
print('No updated translations available')
|
||||||
|
|
||||||
|
def check_for_errors(self):
|
||||||
errors = os.path.join(tempfile.gettempdir(), 'calibre-translation-errors')
|
errors = os.path.join(tempfile.gettempdir(), 'calibre-translation-errors')
|
||||||
if os.path.exists(errors):
|
if os.path.exists(errors):
|
||||||
shutil.rmtree(errors)
|
shutil.rmtree(errors)
|
||||||
os.mkdir(errors)
|
os.mkdir(errors)
|
||||||
pofilter = ('pofilter', '-i', cls.PATH, '-o', errors,
|
pofilter = ('pofilter', '-i', self.PATH, '-o', errors,
|
||||||
'-t', 'accelerators', '-t', 'escapes', '-t', 'variables',
|
'-t', 'accelerators', '-t', 'escapes', '-t', 'variables',
|
||||||
#'-t', 'xmltags',
|
#'-t', 'xmltags',
|
||||||
#'-t', 'brackets',
|
#'-t', 'brackets',
|
||||||
@ -253,23 +255,20 @@ class GetTranslations(Translations): # {{{
|
|||||||
'-t', 'printf')
|
'-t', 'printf')
|
||||||
subprocess.check_call(pofilter)
|
subprocess.check_call(pofilter)
|
||||||
errfiles = glob.glob(errors+os.sep+'*.po')
|
errfiles = glob.glob(errors+os.sep+'*.po')
|
||||||
subprocess.check_call(['gvim', '-f', '-p', '--']+errfiles)
|
if errfiles:
|
||||||
for f in errfiles:
|
subprocess.check_call(['gvim', '-f', '-p', '--']+errfiles)
|
||||||
with open(f, 'r+b') as f:
|
for f in errfiles:
|
||||||
raw = f.read()
|
with open(f, 'r+b') as f:
|
||||||
raw = re.sub(r'# \(pofilter\).*', '', raw)
|
raw = f.read()
|
||||||
f.seek(0)
|
raw = re.sub(r'# \(pofilter\).*', '', raw)
|
||||||
f.truncate()
|
f.seek(0)
|
||||||
f.write(raw)
|
f.truncate()
|
||||||
|
f.write(raw)
|
||||||
|
|
||||||
subprocess.check_call(['pomerge', '-t', cls.PATH, '-i', errors, '-o',
|
subprocess.check_call(['pomerge', '-t', self.PATH, '-i', errors, '-o',
|
||||||
cls.PATH])
|
self.PATH])
|
||||||
if len(list(cls.modified_translations())) > 0:
|
return True
|
||||||
subprocess.call(['bzr', 'diff', cls.PATH])
|
return False
|
||||||
yes = raw_input('Merge corrections? [y/n]: ').strip()
|
|
||||||
if yes in ['', 'y']:
|
|
||||||
subprocess.check_call(['bzr', 'commit', '-m',
|
|
||||||
'IGN:Translation corrections', cls.PATH])
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user