[Bf-docboard-svn] bf-manual: [7372] trunk/blender_docs/tools_maintenance/change_shortcuts: change_shortcuts scripts update

Pep noreply at blender.org
Sat Nov 14 12:10:40 CET 2020


Revision: 7372
          https://developer.blender.org/rBM7372
Author:   pepribal
Date:     2020-11-14 12:10:39 +0100 (Sat, 14 Nov 2020)
Log Message:
-----------
change_shortcuts scripts update

Modified Paths:
--------------
    trunk/blender_docs/tools_maintenance/change_shortcuts/change_man_shortcuts.py
    trunk/blender_docs/tools_maintenance/change_shortcuts/change_tr_shortcuts.py
    trunk/blender_docs/tools_maintenance/change_shortcuts/diff_tr_shortcuts.py
    trunk/blender_docs/tools_maintenance/change_shortcuts/readme.txt
    trunk/blender_docs/tools_maintenance/change_shortcuts/table_es.csv

Added Paths:
-----------
    trunk/blender_docs/tools_maintenance/change_shortcuts/find_man_shortcuts.py
    trunk/blender_docs/tools_maintenance/change_shortcuts/find_tr_shortcuts.py
    trunk/blender_docs/tools_maintenance/change_shortcuts/list_man_shortcuts.py
    trunk/blender_docs/tools_maintenance/change_shortcuts/list_tr_shortcuts.py

Modified: trunk/blender_docs/tools_maintenance/change_shortcuts/change_man_shortcuts.py
===================================================================
--- trunk/blender_docs/tools_maintenance/change_shortcuts/change_man_shortcuts.py	2020-11-14 08:20:56 UTC (rev 7371)
+++ trunk/blender_docs/tools_maintenance/change_shortcuts/change_man_shortcuts.py	2020-11-14 11:10:39 UTC (rev 7372)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python3
 
-# Changes the shortcuts (:kbd:`...`) across all the manual RST
-# files according to the provided CSV table.
+# Changes the shortcuts (:kbd:`...`) and menus (:menuselection:`...`)
+# across all the manual RST files according to the provided CSV table.
 
 import os
 
@@ -37,10 +37,11 @@
     return result
 
 
-def line_process(line):
+def line_process(line, prefix=':kbd:'):
     """
     It processes a line from the RST file.
     :param line: the line from the RST file.
+    :param prefix: type of element (:kbd:, :menuitem:,...)
     :return: the processed (replaced) line.
     """
     result = ''
@@ -48,12 +49,12 @@
     global n_changes
     while True:
         # shortcut start search
-        pos = lin.find(':kbd:`')
+        pos = lin.find(prefix + '`')
         if pos == -1:
             result += lin
             break
-        result += lin[:pos+6]
-        lin = lin[pos+6:]
+        result += lin[:pos+len(prefix)+1]
+        lin = lin[pos+len(prefix)+1:]
 
         # shortcut end search
         pos = lin.find('`')  # we assume it will be found
@@ -78,7 +79,8 @@
     global n_changes
     n_changes = 0
     for line in fin:
-        lin = line_process(line)
+        lin = line_process(line)  # :kbd: shortcuts
+        lin = line_process(lin, ':menuitem:')  # :menuitem: menu items
         fout_list.append(lin)
     fin.close()
 

Modified: trunk/blender_docs/tools_maintenance/change_shortcuts/change_tr_shortcuts.py
===================================================================
--- trunk/blender_docs/tools_maintenance/change_shortcuts/change_tr_shortcuts.py	2020-11-14 08:20:56 UTC (rev 7371)
+++ trunk/blender_docs/tools_maintenance/change_shortcuts/change_tr_shortcuts.py	2020-11-14 11:10:39 UTC (rev 7372)
@@ -1,7 +1,8 @@
 #! /usr/bin/env python3
 
-# Changes the shortcuts (:kbd:`...`) across all the translated PO
-# files of a spcecific language according to the provided CSV table.
+# Changes the shortcuts (:kbd:`...`) and menu items (:menuselection:`...`)
+# across all the translated PO files of a spcecific language, according to
+# the provided CSV table.
 # Language must be indicated.
 
 import os
@@ -39,10 +40,11 @@
     return result
 
 
-def line_process(line):
+def line_process(line, prefix=':kbd:'):
     """
-    It processes a line of the PO file corresponding to a msgstr.
+    It processes a line from the PO file.
     :param line: the line from the PO file.
+    :param prefix: type of element (:kbd:, :menuitem:,...)
     :return: the processed (replaced) line.
     """
     result = ''
@@ -50,12 +52,12 @@
     global n_changes
     while True:
         # shortcut start search
-        pos = lin.find(':kbd:`')
+        pos = lin.find(prefix + '`')
         if pos == -1:
             result += lin
             break
-        result += lin[:pos+6]
-        lin = lin[pos+6:]
+        result += lin[:pos+len(prefix)+1]
+        lin = lin[pos+len(prefix)+1:]
 
         # shortcut end search
         pos = lin.find('`')  # we assume it will be found
@@ -83,7 +85,8 @@
     for line in fin:
         if in_msgstr:
             if line[0] == '"':  # still inside a msgstr
-                lin = line_process(line)
+                lin = line_process(line)  # :kbd: shortcuts
+                lin = line_process(lin, ':menuitem:')  # :menuitem: menu items
                 fout_list.append(lin)
             else:
                 in_msgstr = False  # not anymore in a msgstr
@@ -91,7 +94,8 @@
         else:
             if line[:6] == 'msgstr':  # entering a msgstr
                 in_msgstr = True
-                lin = line_process(line)
+                lin = line_process(line)  # :kbd: shortcuts
+                lin = line_process(lin, ':menuitem:')  # :menuitem: menu items
                 fout_list.append(lin)
             else:  # still outside a msgstr
                 fout_list.append(line)

Modified: trunk/blender_docs/tools_maintenance/change_shortcuts/diff_tr_shortcuts.py
===================================================================
--- trunk/blender_docs/tools_maintenance/change_shortcuts/diff_tr_shortcuts.py	2020-11-14 08:20:56 UTC (rev 7371)
+++ trunk/blender_docs/tools_maintenance/change_shortcuts/diff_tr_shortcuts.py	2020-11-14 11:10:39 UTC (rev 7372)
@@ -34,12 +34,12 @@
 
     Examples: diff_tr_shortcuts.py es
               diff_tr_shortcuts.py fr\n""")
-elif not os.path.isdir('new_locale/' + sys.argv[1]):
+elif not os.path.isdir(os.path.join('new_locale', sys.argv[1])):
     print("'new_locale/" + sys.argv[1] + "' folder not found.")
 else:  # All OK
     fdiff = open('diff_' + sys.argv[1] + '.txt', 'wt')
     # Main loop:
-    for info_dir in os.walk('new_locale/' + sys.argv[1]):
+    for info_dir in os.walk(os.path.join('new_locale', sys.argv[1])):
         for fname in info_dir[2]:
             path_out = os.path.abspath(os.path.join(info_dir[0], fname))
             path_in = os.path.join(root_dir, path_out[path_out.find('locale'):])

Added: trunk/blender_docs/tools_maintenance/change_shortcuts/find_man_shortcuts.py
===================================================================
--- trunk/blender_docs/tools_maintenance/change_shortcuts/find_man_shortcuts.py	                        (rev 0)
+++ trunk/blender_docs/tools_maintenance/change_shortcuts/find_man_shortcuts.py	2020-11-14 11:10:39 UTC (rev 7372)
@@ -0,0 +1,74 @@
+#! /usr/bin/env python3
+
+# Searches for files containing :kbd: or :menuselection: items that
+# match the provided string in the RST files in the repository.
+
+import os
+import sys
+
+file_list = set()
+
+
+def find_vcs_root(dirs=(".svn", ".git"), default=None):
+    """
+    Returns the repo root dir.
+    :param dirs: dirs to look for.
+    :param default: value to return if not found.
+    :return: repo root dir.
+    """
+    prev, test = None, os.path.abspath(os.path.dirname(__file__))
+    while prev != test:
+        if any(os.path.isdir(os.path.join(test, d)) for d in dirs):
+            return test
+        prev, test = test, os.path.abspath(os.path.join(test, os.pardir))
+    return default
+
+
+def line_search(line, prefix):
+    """
+    It searches for the item in the string.
+    :param line: the line from the RST file.
+    :param prefix: type of element (:kbd:, :menuselection:,...).
+    :return: True if found, otherwise False.
+    """
+    if line.find(prefix + '`' + sys.argv[1] + '`') != -1:
+        return True
+    return False
+
+
+def file_process(filename):
+    """
+    It processes the RST file searching for items.
+    :param filename: the name of the PO file.
+    :return: nothing.
+    """
+    global file_list
+    fin = open(filename, 'rt')
+    for line in fin:
+        if line_search(line, ':kbd:') or line_search(line, ':menuselection:'):
+            file_list.add(filename)
+    fin.close()
+
+
+root_path = find_vcs_root()
+
+# Preliminary checks:
+if root_path is None:
+    print('Repository not found. Script must be in a repo subfolder.')
+elif len(sys.argv) != 2:
+    print("""\nUsage: list_tr_shortcuts.py <STRING>
+
+    Examples: list_tr_shortcuts.py Ctrl
+              list_tr_shortcuts.py 'View --> Frame All'\n""")
+else:  # All OK
+    # Main loop:
+    for info_dir in os.walk(os.path.join(root_path, 'manual')):
+        for fname in info_dir[2]:
+            path_full = os.path.join(info_dir[0], fname)
+            if path_full[-4:] == '.rst':
+                file_process(path_full)
+
+    print("Searching for '" + sys.argv[1] + "'...")
+    fl = sorted(file_list)
+    for f in fl:
+        print(f[f.find('manual')+6:])


Property changes on: trunk/blender_docs/tools_maintenance/change_shortcuts/find_man_shortcuts.py
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: trunk/blender_docs/tools_maintenance/change_shortcuts/find_tr_shortcuts.py
===================================================================
--- trunk/blender_docs/tools_maintenance/change_shortcuts/find_tr_shortcuts.py	                        (rev 0)
+++ trunk/blender_docs/tools_maintenance/change_shortcuts/find_tr_shortcuts.py	2020-11-14 11:10:39 UTC (rev 7372)
@@ -0,0 +1,87 @@
+#! /usr/bin/env python3
+
+# Searches for files containing :kbd: or :menuselection: items that
+# match the provided string in the 'msgstr' strings of the desired
+# language PO files in the repository.
+# Language must be indicated.
+
+import os
+import sys
+
+file_list = set()
+
+
+def find_vcs_root(dirs=(".svn", ".git"), default=None):
+    """
+    Returns the repo root dir.
+    :param dirs: dirs to look for.
+    :param default: value to return if not found.
+    :return: repo root dir.
+    """
+    prev, test = None, os.path.abspath(os.path.dirname(__file__))
+    while prev != test:
+        if any(os.path.isdir(os.path.join(test, d)) for d in dirs):
+            return test
+        prev, test = test, os.path.abspath(os.path.join(test, os.pardir))
+    return default
+
+
+def line_search(line, prefix):
+    """
+    It searches for the item in the string.
+    :param line: the line from the PO file.
+    :param prefix: type of element (:kbd:, :menuselection:,...).
+    :return: True if found, otherwise False.
+    """
+    if line.find(prefix + '`' + sys.argv[2] + '`') != -1:
+        return True
+    return False
+
+
+def file_process(filename):
+    """
+    It processes the PO file searching for items.
+    :param filename: the name of the PO file.
+    :return: nothing.
+    """
+    global file_list
+    fin = open(filename, 'rt')
+    in_msgstr = False
+    for line in fin:
+        if in_msgstr:
+            if line[0] == '"':  # still inside a msgstr
+                if line_search(line, ':kbd:') or line_search(line, ':menuselection:'):
+                    file_list.add(filename)
+            else:
+                in_msgstr = False  # not anymore in a msgstr
+        else:
+            if line[:6] == 'msgstr':  # entering a msgstr
+                in_msgstr = True

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-docboard-svn mailing list