[gnome-keysign: 9/18] setup: group the catalogs in a separate function



commit 2ec2d22e104dc6ba275198b51db04d9e4530877e
Author: RyuzakiKK <aasonykk gmail com>
Date:   Thu Oct 26 14:46:55 2017 +0200

    setup: group the catalogs in a separate function

 setup.py | 51 +++++++++++++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 22 deletions(-)
---
diff --git a/setup.py b/setup.py
index 0dd52a1..a34edb3 100644
--- a/setup.py
+++ b/setup.py
@@ -28,32 +28,11 @@ with open(os.path.join('keysign', '_version.py')) as f:
     exec(f.read())
 
 
-
 def translate_desktop_file(infile, outfile, localedir):
-    # We import it here rather than globally because
-    # we don't have a guarantee for babel to be available
-    # globally. The setup_requires can only be evaluated after
-    # this file has been loaded. And it can't load if the import
-    # cannot be resolved.
-    from babel.messages.pofile import read_po
     infp = codecs.open(infile, 'rb', encoding='utf-8')
     outfp = codecs.open(outfile, 'wb', encoding='utf-8')
-    # glob in Python 3.5 takes ** syntax
-    # pofiles = glob.glob(os.path.join(localedir, '**.po', recursive=True))
-    pofiles = [os.path.join(dirpath, f)
-        for dirpath, dirnames, files in os.walk(localedir)
-        for f in files if f.endswith('.po')]
 
-    logging.debug('Loading %r', pofiles)
-    catalogs = {}
-
-    for pofile in pofiles:
-        catalog = read_po(open(pofile, 'r'))
-        catalogs[catalog.locale] = catalog
-        logging.info("Found %d strings for %s", len(catalog), catalog.locale)
-        # logging.debug("Strings for %r", catalog, catalog.values())
-    if not catalogs:
-        logging.warning("Could not find pofiles in %r: %r", localedir, pofiles)
+    catalogs = get_catalogs(localedir)
 
     for line in (x.strip() for x in infp):
         logging.debug('Found in original (%s): %r', type(line), line)
@@ -89,6 +68,34 @@ def translate_desktop_file(infile, outfile, localedir):
         outfp.writelines((outline+'\n' for outline in ([line] + additional_lines)))
 
 
+
+
+def get_catalogs(localedir):
+    # We import it here rather than globally because
+    # we don't have a guarantee for babel to be available
+    # globally. The setup_requires can only be evaluated after
+    # this file has been loaded. And it can't load if the import
+    # cannot be resolved.
+    from babel.messages.pofile import read_po
+
+    # glob in Python 3.5 takes ** syntax
+    # pofiles = glob.glob(os.path.join(localedir, '**.po', recursive=True))
+    pofiles = [os.path.join(dirpath, f)
+               for dirpath, dirnames, files in os.walk(localedir)
+               for f in files if f.endswith('.po')]
+    logging.debug('Loading %r', pofiles)
+    catalogs = {}
+
+    for pofile in pofiles:
+        catalog = read_po(open(pofile, 'r'))
+        catalogs[catalog.locale] = catalog
+        logging.info("Found %d strings for %s", len(catalog), catalog.locale)
+        # logging.debug("Strings for %r", catalog, catalog.values())
+    if not catalogs:
+        logging.warning("Could not find pofiles in %r", pofiles)
+    return catalogs
+
+
 class BuildWithCompile(build):
     sub_commands = [('compile_catalog', None)] + build.sub_commands
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]