This commit is contained in:
Kovid Goyal 2011-12-15 14:08:54 +05:30
parent 9ec56cbe27
commit 60a99e2cae

View File

@ -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,6 +255,7 @@ 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')
if errfiles:
subprocess.check_call(['gvim', '-f', '-p', '--']+errfiles) subprocess.check_call(['gvim', '-f', '-p', '--']+errfiles)
for f in errfiles: for f in errfiles:
with open(f, 'r+b') as f: with open(f, 'r+b') as f:
@ -262,14 +265,10 @@ class GetTranslations(Translations): # {{{
f.truncate() f.truncate()
f.write(raw) 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])
# }}} # }}}