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 | |
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')
-rw-r--r-- | release/scripts/modules/bl_i18n_utils/bl_extract_messages.py | 31 | ||||
-rw-r--r-- | release/scripts/modules/bl_i18n_utils/settings.py | 10 |
2 files changed, 25 insertions, 16 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) diff --git a/release/scripts/modules/bl_i18n_utils/settings.py b/release/scripts/modules/bl_i18n_utils/settings.py index 31eac77b358..48761a35c99 100644 --- a/release/scripts/modules/bl_i18n_utils/settings.py +++ b/release/scripts/modules/bl_i18n_utils/settings.py @@ -384,11 +384,10 @@ MO_PATH_TEMPLATE_RELATIVE = os.path.join(MO_PATH_ROOT_RELATIVE, "{}", "LC_MESSAG # 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 @@ class I18nSettings: 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 |