[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54909] trunk/blender/release/scripts/ modules/bl_i18n_utils: Various small enhancements/fixes.

Bastien Montagne montagne29 at wanadoo.fr
Wed Feb 27 17:24:20 CET 2013


Revision: 54909
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54909
Author:   mont29
Date:     2013-02-27 16:24:20 +0000 (Wed, 27 Feb 2013)
Log Message:
-----------
Various small enhancements/fixes.

Most notable difference from now on will be that all py is handled from current blender's resource dirs, no more from source dir. Better for consistency, and avoid e.g. cycles' addon to be checked twice...

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
    trunk/blender/release/scripts/modules/bl_i18n_utils/settings.py

Modified: trunk/blender/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
===================================================================
--- trunk/blender/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py	2013-02-27 14:25:39 UTC (rev 54908)
+++ trunk/blender/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py	2013-02-27 16:24:20 UTC (rev 54909)
@@ -408,6 +408,14 @@
 
     bpy_struct = bpy.types.ID.__base__
 
+    root_paths = tuple(bpy.utils.resource_path(t) for t in ('USER', 'LOCAL', 'SYSTEM'))
+    def make_rel(path):
+        for rp in root_paths:
+            if path.startswith(rp):
+                return os.path.relpath(path, rp)
+        # Use binary's dir as fallback...
+        return os.path.relpath(path, os.path.dirname(bpy.app.binary_path))
+
     # Helper function
     def extract_strings_ex(node, is_split=False):
         """
@@ -559,7 +567,7 @@
         with open(fp, 'r', encoding="utf8") as filedata:
             root_node = ast.parse(filedata.read(), fp, 'exec')
 
-        fp_rel = os.path.relpath(fp, settings.SOURCE_DIR)
+        fp_rel = make_rel(fp)
 
         for node in ast.walk(root_node):
             if type(node) == ast.Call:
@@ -623,19 +631,22 @@
                             reports["py_messages"].append((msgctxt, estr, msgsrc))
 
 
-def dump_py_messages(msgs, reports, addons, settings):
+def dump_py_messages(msgs, reports, addons, settings, addons_only=False):
     def _get_files(path):
+        if not os.path.exists(path):
+            return []
         if os.path.isdir(path):
-            # XXX use walk instead of listdir?
-            return [os.path.join(path, fn) for fn in sorted(os.listdir(path))
-                                              if not fn.startswith("_") and fn.endswith(".py")]
+            return [os.path.join(dpath, fn) for dpath, _, fnames in os.walk(path) for fn in fnames
+                                            if not fn.startswith("_") and fn.endswith(".py")]
         return [path]
 
     files = []
-    for path in settings.CUSTOM_PY_UI_FILES:
-        files += _get_files(path)
+    if not addons_only:
+        for path in settings.CUSTOM_PY_UI_FILES:
+            for root in (bpy.utils.resource_path(t) for t in ('USER', 'LOCAL', 'SYSTEM')):
+                files += _get_files(os.path.join(root, path))
 
-    # Add all addons we support in main translation file!
+    # Add all given addons.
     for mod in addons:
         fn = mod.__file__
         if os.path.basename(fn) == "__init__.py":
@@ -643,7 +654,7 @@
         else:
             files.append(fn)
 
-    dump_py_messages_from_files(msgs, reports, files, settings)
+    dump_py_messages_from_files(msgs, reports, sorted(files), settings)
 
 
 ##### C source code #####
@@ -855,7 +866,7 @@
 
     # get strings from UI layout definitions text="..." args
     reports["check_ctxt"] = check_ctxt
-    dump_messages_pytext(msgs, reports, addons, settings)
+    dump_messages_pytext(msgs, reports, addons, settings, addons_only=True)
 
     print_info(reports, pot)
 

Modified: trunk/blender/release/scripts/modules/bl_i18n_utils/settings.py
===================================================================
--- trunk/blender/release/scripts/modules/bl_i18n_utils/settings.py	2013-02-27 14:25:39 UTC (rev 54908)
+++ trunk/blender/release/scripts/modules/bl_i18n_utils/settings.py	2013-02-27 16:24:20 UTC (rev 54909)
@@ -384,11 +384,10 @@
 # Mo file name.
 MO_FILE_NAME = DOMAIN + ".mo"
 
-# Where to search for py files that may contain ui strings (relative to SOURCE_DIR).
-REL_CUSTOM_PY_UI_FILES = [
-    os.path.join("release", "scripts", "startup", "bl_ui"),
-    os.path.join("intern", "cycles", "blender", "addon", "ui.py"),
-    os.path.join("release", "scripts", "modules", "rna_prop_ui.py"),
+# Where to search for py files that may contain ui strings (relative to one of the 'resource_path' of Blender).
+CUSTOM_PY_UI_FILES = [
+    os.path.join("scripts", "startup", "bl_ui"),
+    os.path.join("scripts", "modules", "rna_prop_ui.py"),
 ]
 
 # An optional text file listing files to force include/exclude from py_xgettext process.
@@ -503,7 +502,6 @@
     FILE_NAME_POT = property(*(_gen_get_set_path("I18N_DIR", "REL_FILE_NAME_POT")))
     MO_PATH_ROOT = property(*(_gen_get_set_path("I18N_DIR", "REL_MO_PATH_ROOT")))
     MO_PATH_TEMPLATE = property(*(_gen_get_set_path("I18N_DIR", "REL_MO_PATH_TEMPLATE")))
-    CUSTOM_PY_UI_FILES = property(*(_gen_get_set_paths("SOURCE_DIR", "REL_CUSTOM_PY_UI_FILES")))
 
     def _get_py_sys_paths(self):
         return self.INTERN_PY_SYS_PATHS




More information about the Bf-blender-cvs mailing list