From c08a73f0158fbfc63842b8ce48e7e5ceab369e79 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Thu, 13 Mar 2014 14:30:53 -0400 Subject: [PATCH] pep8 --- i18n/converter.py | 9 +++++---- i18n/execute.py | 5 ++++- i18n/extract.py | 28 ++++++++++++++++++---------- i18n/validate.py | 1 + 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/i18n/converter.py b/i18n/converter.py index 9a982347ee..9a3a97db0a 100644 --- a/i18n/converter.py +++ b/i18n/converter.py @@ -1,6 +1,7 @@ import re import itertools + class Converter(object): """Converter is an abstract class that transforms strings. It hides embedded tags (HTML or Python sequences) from transformation @@ -20,7 +21,8 @@ class Converter(object): # matches tags like these: # HTML: , ,
, # Python: %(date)s, %(name)s - tag_pattern = re.compile(r''' + tag_pattern = re.compile( + r''' (<[^>]+>) | # ({[^}]+}) | # {tag} (%\([\w]+\)\w) | # %(tag)s @@ -28,7 +30,7 @@ class Converter(object): (&\#\d+;) | # Ӓ (&\#x[0-9a-f]+;) # ꯍ ''', - re.IGNORECASE|re.VERBOSE + re.IGNORECASE | re.VERBOSE ) def convert(self, string): @@ -55,7 +57,7 @@ class Converter(object): tags = [''.join(tag) for tag in tags] (new, nfound) = self.tag_pattern.subn(count, string) if len(tags) != nfound: - raise Exception('tags dont match:'+string) + raise Exception('tags dont match:' + string) return (new, tags) def retag_string(self, string, tags): @@ -65,7 +67,6 @@ class Converter(object): string = re.sub(p, tag, string, 1) return string - # ------------------------------ # Customize this in subclasses of Converter diff --git a/i18n/execute.py b/i18n/execute.py index 0f672a2d73..c3883569d5 100644 --- a/i18n/execute.py +++ b/i18n/execute.py @@ -1,9 +1,12 @@ -import os, subprocess, logging +import os +import subprocess +import logging from i18n.config import BASE_DIR LOG = logging.getLogger(__name__) + def execute(command, working_directory=BASE_DIR, stderr=subprocess.STDOUT): """ Executes shell command in a given working_directory. diff --git a/i18n/extract.py b/i18n/extract.py index 28f798cff4..b7e81d2f8d 100755 --- a/i18n/extract.py +++ b/i18n/extract.py @@ -35,6 +35,7 @@ EDX_MARKER = "edX translation file" LOG = logging.getLogger(__name__) DEVNULL = open(os.devnull, 'wb') + def base(path1, *paths): """Return a relative path from BASE_DIR to path1 / paths[0] / ... """ return BASE_DIR.relpathto(path1.joinpath(*paths)) @@ -143,20 +144,24 @@ def fix_header(po): fixes = ( ('SOME DESCRIPTIVE TITLE', EDX_MARKER), ('Translations template for PROJECT.', EDX_MARKER), - ('YEAR', '%s' % datetime.utcnow().year), + ('YEAR', str(datetime.utcnow().year)), ('ORGANIZATION', 'edX'), ("THE PACKAGE'S COPYRIGHT HOLDER", "EdX"), - ('This file is distributed under the same license as the PROJECT project.', - 'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.'), - ('This file is distributed under the same license as the PACKAGE package.', - 'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.'), - ('FIRST AUTHOR ', - 'EdX Team ') - ) + ( + 'This file is distributed under the same license as the PROJECT project.', + 'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.' + ), + ( + 'This file is distributed under the same license as the PACKAGE package.', + 'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.' + ), + ('FIRST AUTHOR ', 'EdX Team '), + ) for src, dest in fixes: header = header.replace(src, dest) po.header = header + def fix_metadata(po): """ Replace default metadata with edX metadata @@ -179,12 +184,13 @@ def fix_metadata(po): 'PO-Revision-Date': datetime.utcnow(), 'Report-Msgid-Bugs-To': 'openedx-translation@googlegroups.com', 'Project-Id-Version': '0.1a', - 'Language' : 'en', - 'Last-Translator' : '', + 'Language': 'en', + 'Last-Translator': '', 'Language-Team': 'openedx-translation ', } po.metadata.update(fixes) + def strip_key_strings(po): """ Removes all entries in PO which are key strings. @@ -194,6 +200,7 @@ def strip_key_strings(po): del po[:] po += newlist + def is_key_string(string): """ returns True if string is a key string. @@ -201,6 +208,7 @@ def is_key_string(string): """ return len(string) > 1 and string[0] == '_' + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--verbose', '-v', action='count', default=0) diff --git a/i18n/validate.py b/i18n/validate.py index 49eaa5fd6f..6f207ddf56 100644 --- a/i18n/validate.py +++ b/i18n/validate.py @@ -16,6 +16,7 @@ from i18n.converter import Converter log = logging.getLogger(__name__) + def validate_po_files(root, report_empty=False): """ Validate all of the po files found in the root directory.