| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
"""import PO-files from launchpad-export.tar.gz (extra command for setup.py)""" |
| 21 |
|
| 22 |
from distutils import log |
| 23 |
from distutils.core import Command |
| 24 |
from distutils.spawn import find_executable |
| 25 |
|
| 26 |
from .en_po import regenerate_en |
| 27 |
|
| 28 |
|
| 29 |
class import_po(Command): |
| 30 |
"""Distutils command for import PO files.""" |
| 31 |
|
| 32 |
description = 'import PO-files from launchpad-export.tar.gz' |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
user_options = [('tarball=', 'F', 'path to launchpad-export.tar.gz file'), |
| 39 |
('output-dir=', 'O', 'output directory (default: po)'), |
| 40 |
] |
| 41 |
boolean_options = [] |
| 42 |
|
| 43 |
def initialize_options(self): |
| 44 |
self.tarball = None |
| 45 |
self.output_dir = None |
| 46 |
|
| 47 |
def finalize_options(self): |
| 48 |
if self.tarball is None: |
| 49 |
self.tarball = 'launchpad-export.tar.gz' |
| 50 |
if self.output_dir is None: |
| 51 |
self.output_dir = 'po' |
| 52 |
|
| 53 |
def run(self): |
| 54 |
"""Unpack tarball with PO-files.""" |
| 55 |
import os |
| 56 |
import tarfile |
| 57 |
|
| 58 |
log.info('Inspecting tarball...') |
| 59 |
t = tarfile.open(self.tarball) |
| 60 |
names = t.getnames() |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
entries = [] |
| 66 |
pot_file = None |
| 67 |
for n in names: |
| 68 |
if n == './': |
| 69 |
continue |
| 70 |
parts = os.path.split(n) |
| 71 |
fn = parts[-1] |
| 72 |
if not fn: |
| 73 |
continue |
| 74 |
if t.getmember(n).isfile(): |
| 75 |
entries.append((n, os.path.join(self.output_dir, fn))) |
| 76 |
if fn.endswith('.pot'): |
| 77 |
assert pot_file is None, "There is 2 POT files in archive!" |
| 78 |
pot_file = fn |
| 79 |
log.info('Extracting...') |
| 80 |
for n, fn in entries: |
| 81 |
log.info(' %s -> %s' % (n, fn)) |
| 82 |
ft = t.extractfile(n) |
| 83 |
with open(fn, 'wb') as fd: |
| 84 |
fd.write(ft.read()) |
| 85 |
if pot_file: |
| 86 |
if find_executable('msginit') is None: |
| 87 |
log.warn("GNU gettext msginit utility not found!") |
| 88 |
log.warn("Skip creating English PO file.") |
| 89 |
else: |
| 90 |
log.info('Re-creating English PO file...') |
| 91 |
prj_name = os.path.splitext(pot_file)[0] |
| 92 |
regenerate_en(prj_name, self.output_dir, pot_file, self.spawn) |
| 93 |
log.info('Done.') |