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

Pep noreply at blender.org
Sat Nov 14 09:20:57 CET 2020


Revision: 7371
          https://developer.blender.org/rBM7371
Author:   pepribal
Date:     2020-11-14 09:20:56 +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_man_shortcuts.py
    trunk/blender_docs/tools_maintenance/change_shortcuts/diff_tr_shortcuts.py

Added Paths:
-----------
    trunk/blender_docs/tools_maintenance/change_shortcuts/clear_temp_data.py
    trunk/blender_docs/tools_maintenance/change_shortcuts/readme.txt

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-13 23:32:33 UTC (rev 7370)
+++ trunk/blender_docs/tools_maintenance/change_shortcuts/change_man_shortcuts.py	2020-11-14 08:20:56 UTC (rev 7371)
@@ -84,8 +84,8 @@
 
     # In case there were changes, we generate an output file
     if n_changes > 0:
-        print(filename + ':', n_changes, "change(s).")
-
+        print(filename[filename.find('manual')+6:] + ':',
+              n_changes, "change(s).")
         file_out = 'new_' + filename[filename.find('manual'):]
         os.makedirs(os.path.dirname(file_out), exist_ok=True)
         fout = open(file_out, 'wt')
@@ -95,10 +95,13 @@
 
 root_path = find_vcs_root()
 
-if not os.path.isfile('table.csv'):
+# Preliminary checks:
+if root_path is None:
+    print('Repository not found. Script must be in a repo subfolder.')
+elif not os.path.isfile('table.csv'):
     print("'table.csv' file not found. "
           "Script and 'table.csv' must be in the same folder.")
-else:
+else:  # All OK
     # Substitution table initialization:
     f = open('table.csv', 'rt')
     for ln in f:

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-13 23:32:33 UTC (rev 7370)
+++ trunk/blender_docs/tools_maintenance/change_shortcuts/change_tr_shortcuts.py	2020-11-14 08:20:56 UTC (rev 7371)
@@ -99,7 +99,8 @@
 
     # In case there were changes, we generate an output file
     if n_changes > 0:
-        print(filename + ':', n_changes, "change(s).")
+        print(filename[filename.find('LC_MESSAGES')+11:] + ':',
+              n_changes, "change(s).")
         file_out = 'new_' + filename[filename.find('locale'):]
         os.makedirs(os.path.dirname(file_out), exist_ok=True)
         fout = open(file_out, 'wt')
@@ -109,8 +110,10 @@
 
 root_path = find_vcs_root()
 
-# CL Arguments:
-if len(sys.argv) != 2:
+# 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: change_tr_shortcuts.py <LANGUAGE>
 
     Examples: change_tr_shortcuts.py es
@@ -122,10 +125,11 @@
     Output files will be created in 'new_locale' subfolder
     inside the script's folder.\n""")
 elif not os.path.isdir(os.path.join(root_path, 'locale', sys.argv[1])):
-    print('<repo_root>/locale/' + sys.argv[1], 'folder not found')
+    print("'<repo_root>/locale/" + sys.argv[1] + "' folder not found.")
 elif not os.path.isfile(os.path.join('table_' + sys.argv[1] + '.csv')):
-    print('table_' + sys.argv[1] + '.csv file not found')
-else:
+    print("'table_" + sys.argv[1] + ".csv' file not found. "
+          "Script and table must be in the same folder.")
+else:  # All OK
     # Substitution table initialization:
     f = open('table_' + sys.argv[1] + '.csv', 'rt')
     for ln in f:

Added: trunk/blender_docs/tools_maintenance/change_shortcuts/clear_temp_data.py
===================================================================
--- trunk/blender_docs/tools_maintenance/change_shortcuts/clear_temp_data.py	                        (rev 0)
+++ trunk/blender_docs/tools_maintenance/change_shortcuts/clear_temp_data.py	2020-11-14 08:20:56 UTC (rev 7371)
@@ -0,0 +1,16 @@
+#! /usr/bin/env python3
+
+# Deletes all temp files and directories (if they exist):
+#     * 'new_locale' subfolder.
+#     * 'new_manual' subfolder.
+#     * All diff files.
+
+import os
+import shutil
+import glob
+
+
+shutil.rmtree('new_locale', ignore_errors=True)
+shutil.rmtree('new_manual', ignore_errors=True)
+for file in glob.glob('diff*.txt'):
+    os.remove(file)


Property changes on: trunk/blender_docs/tools_maintenance/change_shortcuts/clear_temp_data.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
Modified: trunk/blender_docs/tools_maintenance/change_shortcuts/diff_man_shortcuts.py
===================================================================
--- trunk/blender_docs/tools_maintenance/change_shortcuts/diff_man_shortcuts.py	2020-11-13 23:32:33 UTC (rev 7370)
+++ trunk/blender_docs/tools_maintenance/change_shortcuts/diff_man_shortcuts.py	2020-11-14 08:20:56 UTC (rev 7371)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python3
 
-# Shows the differences between the original RST manual files
-# and the ones generated by change_man_shortcuts.py.
+# Creates a diff file with the differences between the original RST
+# manual files and the ones generated by change_man_shortcuts.py.
 
 import os
 import difflib
@@ -24,9 +24,13 @@
 
 root_dir = find_vcs_root()
 
-if not os.path.isdir('new_manual'):
-    print('new_manual folder not found.')
-else:
+# Preliminary checks:
+if root_dir is None:
+    print('Repository not found. Script must be in a repo subfolder.')
+elif not os.path.isdir('new_manual'):
+    print("'new_manual' folder not found.")
+else:  # All OK
+    fdiff = open('diff_man.txt', 'wt')
     # Main loop:
     for info_dir in os.walk('new_manual'):
         for fname in info_dir[2]:
@@ -39,6 +43,8 @@
             diff = difflib.context_diff(str_in, str_out,
                                         fromfile=path_in, tofile=path_out, n=0)
             for di in diff:
-                print(di, end='')
+                fdiff.write(di)
             f_out.close()
             f_in.close()
+            fdiff.write('\n\n\n')
+    fdiff.close()

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-13 23:32:33 UTC (rev 7370)
+++ trunk/blender_docs/tools_maintenance/change_shortcuts/diff_tr_shortcuts.py	2020-11-14 08:20:56 UTC (rev 7371)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python3
 
-# Shows the differences between the original PO translation files
-# and the ones generated by change_tr_shortcuts.py.
+# Creates a diff file with the differences between the original PO
+# translation files and the ones generated by change_tr_shortcuts.py.
 # Language must be indicated.
 
 import os
@@ -26,15 +26,18 @@
 
 root_dir = find_vcs_root()
 
-# CL Arguments:
-if len(sys.argv) != 2:
-    print("""\nUsage: diffshortcuts.py <LANGUAGE>
+# Preliminary checks:
+if root_dir is None:
+    print('Repository not found. Script must be in a repo subfolder.')
+elif len(sys.argv) != 2:
+    print("""\nUsage: diff_tr_shortcuts.py <LANGUAGE>
 
-    Examples: diffshortcuts.py es
-              diffshortcuts.py fr\n""")
+    Examples: diff_tr_shortcuts.py es
+              diff_tr_shortcuts.py fr\n""")
 elif not os.path.isdir('new_locale/' + sys.argv[1]):
-    print('new_locale/' + sys.argv[1], 'folder not found.')
-else:
+    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 fname in info_dir[2]:
@@ -47,6 +50,8 @@
             diff = difflib.context_diff(str_in, str_out,
                                         fromfile=path_in, tofile=path_out, n=0)
             for di in diff:
-                print(di, end='')
+                fdiff.write(di)
             f_out.close()
             f_in.close()
+            fdiff.write('\n\n\n')
+    fdiff.close()

Added: trunk/blender_docs/tools_maintenance/change_shortcuts/readme.txt
===================================================================
--- trunk/blender_docs/tools_maintenance/change_shortcuts/readme.txt	                        (rev 0)
+++ trunk/blender_docs/tools_maintenance/change_shortcuts/readme.txt	2020-11-14 08:20:56 UTC (rev 7371)
@@ -0,0 +1,67 @@
+change_shortcuts
+================
+
+Scripts to bulk change shortcut names (:kbd:`...`).
+
+
+
+change_man_shortcuts.py
+-----------------------
+
+It changes all the shortcuts in the manual according to a CSV substitution table.
+If one of the entries is, for instance:
+
+LMB;LeftMouse
+
+then all related shortcuts will be replaced, that is:
+
+    :kbd:`LMB`       becomes  :kbd:`LeftMouse`
+    :kbd:`Ctrl-LMB`  becomes  :kbd:`Ctrl-LeftMouse`
+    Etc.
+
+The file 'table.csv' must be in the same folder as the script.
+
+On completion, a 'new_manual' subfolder will be created in the script folder.
+In it, you will find all the RST files that had replacements. You can check them
+before dumping and replacing the desired files onto the repository.
+
+
+
+change_tr_shortcuts.py
+----------------------
+
+It does the same thing as 'change_man_shortcuts.py', but for translations.
+You must specify a language (e.g. 'es'), and provide a substitution table
+(e.g. 'table_es.csv') in the same folder as the script.
+
+Substitutions will be performed only in 'msgstr' strings in the PO files.
+
+It will generate a 'new_locale' subfolder in wich all replaced PO files for
+the desired language will be found.
+
+
+
+diff_man_shortcuts.py
+---------------------
+
+Useful for checking all the differences between the newly generated RST files
+and the current files in the repository. a file 'diff_man.txt' will be generated
+in the script folder, with all the differences.
+
+
+
+diff_tr_shortcuts.py
+---------------------
+
+Same as 'diff_man_shortcuts.py', but for translation files. Language must be indicated
+(e.g. 'fr'), and the corresponding diff text file will be created (e.g. 'diff_fr.txt')
+in the script folder.
+
+
+
+clear_temp_data.py
+------------------
+
+It deletes all temporary data, if they exist: 'new_manual' and 'new_locale' subfolders,
+as well as all diff files.
+


Property changes on: trunk/blender_docs/tools_maintenance/change_shortcuts/readme.txt
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property


More information about the Bf-docboard-svn mailing list