|
9 | 9 | :license: BSD, see LICENSE for more details. |
10 | 10 | """ |
11 | 11 | from __future__ import print_function |
12 | | -try: |
13 | | - from ConfigParser import RawConfigParser |
14 | | -except ImportError: |
15 | | - from configparser import RawConfigParser |
16 | | -from datetime import datetime |
17 | | -from distutils import log as distutils_log |
18 | | -from distutils.cmd import Command as _Command |
19 | | -from distutils.errors import DistutilsOptionError, DistutilsSetupError |
20 | | -from locale import getpreferredencoding |
| 12 | + |
21 | 13 | import logging |
22 | | -from optparse import OptionParser |
| 14 | +import optparse |
23 | 15 | import os |
24 | 16 | import re |
25 | 17 | import shutil |
26 | 18 | import sys |
27 | 19 | import tempfile |
| 20 | +from datetime import datetime |
| 21 | +from locale import getpreferredencoding |
28 | 22 |
|
29 | 23 | from babel import __version__ as VERSION |
30 | 24 | from babel import Locale, localedata |
| 25 | +from babel._compat import StringIO, string_types |
31 | 26 | from babel.core import UnknownLocaleError |
32 | 27 | from babel.messages.catalog import Catalog |
33 | | -from babel.messages.extract import extract_from_dir, DEFAULT_KEYWORDS, \ |
34 | | - DEFAULT_MAPPING |
| 28 | +from babel.messages.extract import DEFAULT_KEYWORDS, DEFAULT_MAPPING, extract_from_dir |
35 | 29 | from babel.messages.mofile import write_mo |
36 | 30 | from babel.messages.pofile import read_po, write_po |
37 | | -from babel.util import odict, LOCALTZ |
38 | | -from babel._compat import string_types, StringIO, PY2 |
| 31 | +from babel.util import LOCALTZ, odict |
| 32 | +from distutils import log as distutils_log |
| 33 | +from distutils.cmd import Command as _Command |
| 34 | +from distutils.errors import DistutilsOptionError, DistutilsSetupError |
| 35 | + |
| 36 | +try: |
| 37 | + from ConfigParser import RawConfigParser |
| 38 | +except ImportError: |
| 39 | + from configparser import RawConfigParser |
39 | 40 |
|
40 | 41 |
|
41 | 42 | class Command(_Command): |
@@ -162,21 +163,24 @@ def run(self): |
162 | 163 | translated = 0 |
163 | 164 | for message in list(catalog)[1:]: |
164 | 165 | if message.string: |
165 | | - translated +=1 |
| 166 | + translated += 1 |
166 | 167 | percentage = 0 |
167 | 168 | if len(catalog): |
168 | 169 | percentage = translated * 100 // len(catalog) |
169 | | - self.log.info('%d of %d messages (%d%%) translated in %r', |
170 | | - translated, len(catalog), percentage, po_file) |
| 170 | + self.log.info( |
| 171 | + '%d of %d messages (%d%%) translated in %r', |
| 172 | + translated, len(catalog), percentage, po_file |
| 173 | + ) |
171 | 174 |
|
172 | 175 | if catalog.fuzzy and not self.use_fuzzy: |
173 | 176 | self.log.info('catalog %r is marked as fuzzy, skipping', po_file) |
174 | 177 | continue |
175 | 178 |
|
176 | 179 | for message, errors in catalog.check(): |
177 | 180 | for error in errors: |
178 | | - self.log.error('error: %s:%d: %s', po_file, message.lineno, |
179 | | - error) |
| 181 | + self.log.error( |
| 182 | + 'error: %s:%d: %s', po_file, message.lineno, error |
| 183 | + ) |
180 | 184 |
|
181 | 185 | self.log.info('compiling catalog %r to %r', po_file, mo_file) |
182 | 186 |
|
@@ -300,7 +304,8 @@ def finalize_options(self): |
300 | 304 | if isinstance(self.input_dirs, string_types): |
301 | 305 | self.input_dirs = re.split(',\s*', self.input_dirs) |
302 | 306 | else: |
303 | | - self.input_dirs = dict.fromkeys([k.split('.',1)[0] |
| 307 | + self.input_dirs = dict.fromkeys([ |
| 308 | + k.split('.', 1)[0] |
304 | 309 | for k in (self.distribution.packages or ()) |
305 | 310 | ]).keys() |
306 | 311 |
|
@@ -339,12 +344,13 @@ def callback(filename, method, options): |
339 | 344 | k, v in options.items()]) |
340 | 345 | self.log.info('extracting messages from %s%s', filepath, optstr) |
341 | 346 |
|
342 | | - extracted = extract_from_dir(dirname, method_map, options_map, |
343 | | - keywords=self._keywords, |
344 | | - comment_tags=self.add_comments, |
345 | | - callback=callback, |
346 | | - strip_comment_tags= |
347 | | - self.strip_comments) |
| 347 | + extracted = extract_from_dir( |
| 348 | + dirname, method_map, options_map, |
| 349 | + keywords=self._keywords, |
| 350 | + comment_tags=self.add_comments, |
| 351 | + callback=callback, |
| 352 | + strip_comment_tags=self.strip_comments |
| 353 | + ) |
348 | 354 | for filename, lineno, message, comments, context in extracted: |
349 | 355 | filepath = os.path.normpath(os.path.join(dirname, filename)) |
350 | 356 | catalog.add(message, None, [(filepath, lineno)], |
@@ -477,8 +483,9 @@ def finalize_options(self): |
477 | 483 | self.width = int(self.width) |
478 | 484 |
|
479 | 485 | def run(self): |
480 | | - self.log.info('creating catalog %r based on %r', self.output_file, |
481 | | - self.input_file) |
| 486 | + self.log.info( |
| 487 | + 'creating catalog %r based on %r', self.output_file, self.input_file |
| 488 | + ) |
482 | 489 |
|
483 | 490 | infile = open(self.input_file, 'rb') |
484 | 491 | try: |
@@ -674,8 +681,8 @@ def run(self, argv=None): |
674 | 681 | if argv is None: |
675 | 682 | argv = sys.argv |
676 | 683 |
|
677 | | - self.parser = OptionParser(usage=self.usage % ('command', '[args]'), |
678 | | - version=self.version) |
| 684 | + self.parser = optparse.OptionParser(usage=self.usage % ('command', '[args]'), |
| 685 | + version=self.version) |
679 | 686 | self.parser.disable_interspersed_args() |
680 | 687 | self.parser.print_help = self._help |
681 | 688 | self.parser.add_option('--list-locales', dest='list_locales', |
@@ -750,7 +757,7 @@ def _dispatch(self, cmdname, argv): |
750 | 757 | assert isinstance(cmdinst, Command) |
751 | 758 | cmdinst.initialize_options() |
752 | 759 |
|
753 | | - parser = OptionParser( |
| 760 | + parser = optparse.OptionParser( |
754 | 761 | usage=self.usage % (cmdname, ''), |
755 | 762 | description=self.commands[cmdname] |
756 | 763 | ) |
@@ -843,7 +850,7 @@ def parse_mapping(fileobj, filename=None): |
843 | 850 | options_map = {} |
844 | 851 |
|
845 | 852 | parser = RawConfigParser() |
846 | | - parser._sections = odict(parser._sections) # We need ordered sections |
| 853 | + parser._sections = odict(parser._sections) # We need ordered sections |
847 | 854 | parser.readfp(fileobj, filename) |
848 | 855 | for section in parser.sections(): |
849 | 856 | if section == 'extractors': |
|
0 commit comments