py3 compat in POT generation

This commit is contained in:
Kovid Goyal 2020-11-12 11:15:16 +05:30
parent e11b6ef0b3
commit c26a981001
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -151,16 +151,15 @@ class POT(Command): # {{{
if needs_import: if needs_import:
self.tx(['set', '-r', 'calibre.' + slug, '--source', '-l', 'en', '-t', 'PO', dest]) self.tx(['set', '-r', 'calibre.' + slug, '--source', '-l', 'en', '-t', 'PO', dest])
with open(self.j(self.d(tbase), '.tx/config'), 'r+b') as f: with open(self.j(self.d(tbase), '.tx/config'), 'r+b') as f:
lines = f.read().splitlines() lines = f.read().decode('utf-8').splitlines()
for i in range(len(lines)): for i in range(len(lines)):
line = lines[i] line = lines[i].strip()
if line == '[calibre.%s]' % slug: if line == '[calibre.%s]' % slug:
lines.insert(i+1, 'file_filter = manual/<lang>/%s.po' % bname) lines.insert(i+1, 'file_filter = manual/<lang>/%s.po' % bname)
f.seek(0), f.truncate(), f.write('\n'.join(lines)) f.seek(0), f.truncate(), f.write('\n'.join(lines).encode('utf-8'))
break break
else: else:
self.info('Failed to add file_filter to config file') raise SystemExit(f'Failed to add file_filter for {slug=} to config file')
raise SystemExit(1)
self.git('add .tx/config') self.git('add .tx/config')
self.upload_pot(resource=slug) self.upload_pot(resource=slug)
self.git(['add', dest]) self.git(['add', dest])