diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2013-02-27 20:24:20 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2013-02-27 20:24:20 +0400 |
commit | 4238d6d7581107310a31e8e588c96ed03342d034 (patch) | |
tree | 2201bbd9c28eaa9d70ab8e82b02efdc9466e312a /release/scripts/modules/bl_i18n_utils/bl_extract_messages.py | |
parent | a8c48058f9f93a45c84ab292ba8c1b1b66c0a39c (diff) |
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...
Diffstat (limited to 'release/scripts/modules/bl_i18n_utils/bl_extract_messages.py')
-rw-r--r-- | release/scripts/modules/bl_i18n_utils/bl_extract_messages.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py b/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py index 18c7b736ea5..7876a443035 100644 --- a/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py +++ b/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py @@ -408,6 +408,14 @@ def dump_py_messages_from_files(msgs, reports, files, settings): 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 @@ def dump_py_messages_from_files(msgs, reports, files, settings): 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 @@ def dump_py_messages_from_files(msgs, reports, files, settings): 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 @@ def dump_py_messages(msgs, reports, addons, settings): 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 @@ def dump_addon_messages(module_name, messages_formats, do_checks, settings): # 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) |