Skip to content
Snippets Groups Projects
Commit 929440ee authored by Aaron Carlisle's avatar Aaron Carlisle
Browse files

RNA Manual Mappings: Make script more versatile

- Refactor to functions
- Write file to the release folder by default
- Add arg parser to specify url, local path, and output.

In the future we may want to add arguments for output url info (base, 
langs and version)
parent dd131bc4
No related branches found
No related tags found
No related merge requests found
...@@ -15,89 +15,147 @@ ...@@ -15,89 +15,147 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# #
# ##### END GPL LICENSE BLOCK ##### # ##### END GPL LICENSE BLOCK #####
#
# ##### RNA MANUAL REFERENCES ##### '''
# RNA Manual Reference Mapping Updater
# This file generates a file that maps RNA strings to online URL's
# for the context menu documentation access This script generates a file that maps RNA strings to online URL's
# for the context menu documentation access.
# To make international, we made a script,
# pointing the manuals to the proper language, This script either downloads a sphinx requirement file from the manual
# specified in the 'User Preferences Window' by the users. or optionally can take a path to the file using `--input`.
# Some Languages have their manual page, using a prefix or
# being preceded by their respective reference, for example: To make international, we made a script,
# pointing the manuals to the proper language,
# manual/ --> manual/ru/ specified in the 'User Preferences Window' by the users.
# Some Languages have their manual page, using a prefix or
# The table in the script, contains all of the languages we have in the being preceded by their respective reference, for example:
# Blender manual website, for those other languages that still
# does not have a team of translators, manual/ --> manual/ru/
# and/or don't have a manual for their languages we commented the lines below,
# you should add them to the language table when they have a proper manual, The table in the script, contains all of the languages we have in the
# or added to the Blender UI translation table. Blender manual website, for those other languages that still
# does not have a team of translators,
# URL is the: url_manual_prefix + url_manual_mapping[#id] and/or don't have a manual for their languages we commented the lines below,
you should add them to the language table when they have a proper manual,
or added to the Blender UI translation table.
URL is the: url_manual_prefix + url_manual_mapping[#id]
'''
import os import os
import sphobjinv as soi import sphobjinv as soi
# Download and decode objects.inv def write_mappings(inv, output):
inv = soi.Inventory(url="https://docs.blender.org/manual/en/dev/objects.inv") print("Writing...")
# Write the file
# Write the fire file = open(output, "w", encoding="utf-8")
filepath = os.path.join("rna_manual_reference.py") fw = file.write
file = open(filepath, "w", encoding="utf-8")
fw = file.write fw("# Do not edit this file.")
fw(" This file is auto generated from rna_manual_reference_updater.py\n\n")
fw("# Do not edit this file.") fw("import bpy\n\n")
fw(" This file is auto generated from rna_manual_reference_updater.py\n\n") fw("if bpy.app.version_cycle in {'rc', 'release'}:\n")
fw("import bpy\n\n") fw(" manual_version = '%d.%d' % bpy.app.version[:2]\n")
fw("if bpy.app.version_cycle in {'rc', 'release'}:\n") fw("else:\n")
fw(" manual_version = '%d.%d' % bpy.app.version[:2]\n") fw(" manual_version = 'dev'\n\n")
fw("else:\n") fw("url_manual_prefix = \"https://docs.blender.org/manual/en/\" + manual_version + \"/\"\n\n")
fw(" manual_version = 'dev'\n\n") fw("language = bpy.context.preferences.view.language\n")
fw("url_manual_prefix = \"https://docs.blender.org/manual/en/\" + manual_version + \"/\"\n\n") fw("if language == 'DEFAULT':\n")
fw("language = bpy.context.preferences.view.language\n") fw(" import os\n")
fw("if language == 'DEFAULT':\n") fw(" language = os.getenv('LANG', '').split('.')[0]\n\n")
fw(" import os\n") fw("LANG = {\n")
fw(" language = os.getenv('LANG', '').split('.')[0]\n\n") # fw("\"ar_EG": \"ar",\n")
fw("LANG = {\n") # fw("\"bg_BG": \"bg",\n")
# fw("\"ar_EG": \"ar",\n") # fw("\"ca_AD": \"ca",\n")
# fw("\"bg_BG": \"bg",\n") # fw("\"cs_CZ": \"cz",\n")
# fw("\"ca_AD": \"ca",\n") fw("\"de_DE\": \"de\",\n") # German
# fw("\"cs_CZ": \"cz",\n") # fw("\"el_GR": \"el",\n")
fw("\"de_DE\": \"de\",\n") # German fw("\"ru_RU\": \"ru\",\n") # Russian
# fw("\"el_GR": \"el",\n") # fw("\"sr_RS": \"sr",\n")
fw("\"ru_RU\": \"ru\",\n") # Russian # fw("\"sv_SE": \"sv",\n")
# fw("\"sr_RS": \"sr",\n") # fw("\"tr_TR": \"th",\n")
# fw("\"sv_SE": \"sv",\n") fw("\"uk_UA\": \"uk\",\n") # Ukrainian
# fw("\"tr_TR": \"th",\n") fw("\"es\": \"es\",\n") # Spanish
fw("\"uk_UA\": \"uk\",\n") # Ukrainian # fw("\"fi_FI": \"fi",\n")
fw("\"es\": \"es\",\n") # Spanish fw("\"fr_FR\": \"fr\",\n") # French
# fw("\"fi_FI": \"fi",\n") # fw("\"id_ID": \"id",\n")
fw("\"fr_FR\": \"fr\",\n") # French fw("\"it_IT\": \"it\",\n") # Italian
# fw("\"id_ID": \"id",\n") fw("\"ja_JP\": \"ja\",\n") # Japanese
fw("\"it_IT\": \"it\",\n") # Italian fw("\"ko_KR\": \"ko\",\n") # Korean
fw("\"ja_JP\": \"ja\",\n") # Japanese # fw("\"nl_NL": \"nl",\n")
fw("\"ko_KR\": \"ko\",\n") # Korean # fw("\"pl_PL": \"pl",\n")
# fw("\"nl_NL": \"nl",\n") fw("\"pt_PT\": \"pt\",\n") # Portuguese
# fw("\"pl_PL": \"pl",\n") fw("\"pt_BR\": \"pt\",\n") # Portuguese - for until we have a pt_BR version
fw("\"pt_PT\": \"pt\",\n") # Portuguese fw("\"vi_VN\": \"vi\",\n") # Vietnamese
fw("\"pt_BR\": \"pt\",\n") # Portuguese - for until we have a pt_BR version fw("\"zh_CN\": \"zh-hans\",\n") # Simplified Chinese
fw("\"vi_VN\": \"vi\",\n") # Vietnamese fw("\"zh_TW\": \"zh-hant\",\n") # Traditional Chinese
fw("\"zh_CN\": \"zh-hans\",\n") # Simplified Chinese fw("}.get(language)\n\n")
fw("\"zh_TW\": \"zh-hant\",\n") # Traditional Chinese fw("if LANG is not None:\n")
fw("}.get(language)\n\n") fw(" url_manual_prefix = url_manual_prefix.replace(\"manual/en\", \"manual/\" + LANG)\n\n")
fw("if LANG is not None:\n") fw("url_manual_mapping = (\n")
fw(" url_manual_prefix = url_manual_prefix.replace(\"manual/en\", \"manual/\" + LANG)\n\n")
fw("url_manual_mapping = (\n") # Logic to manipulate strings from objects.inv
lines = [o.data_line() for o in inv.objects if o.name.startswith("bpy.types") or o.name.startswith("bpy.ops")]
# Logic to manipulate strings from objects.inv # Finding first space will return length of rna path
lines = [o.data_line() for o in inv.objects if o.name.startswith("bpy.types") or o.name.startswith("bpy.ops")] lines.sort(key=lambda l: l.find(" "), reverse=True)
# Finding first space will return length of rna path for line in lines:
lines.sort(key=lambda l: l.find(" "), reverse=True) split = line.split(" ")
for line in lines: fw("\t(\"" + split[0] + "*\", \"" + split[3] + "\"),\n")
split = line.split(" ")
fw("\t(\"" + split[0] + "*\", \"" + split[3] + "\"),\n") fw(")\n")
fw(")\n")
def is_valid_file(parser, arg):
if not os.path.isfile(arg) :
parser.error("The file %s does not exist!" % arg)
else:
return arg
def main():
import argparse
parser = argparse.ArgumentParser(
usage=__doc__
)
parser.add_argument(
"--input",
dest="filename",
required=False,
help="sphinx inventory file (objects.inv)",
metavar="FILE",
type=lambda x: is_valid_file(parser, x))
parser.add_argument(
"--output",
dest="output",
default="../../../release/scripts/modules/rna_manual_reference.py",
required=False,
help="path to output including filename and extentsion",
metavar="FILE")
parser.add_argument(
"--url",
dest="url",
default="https://docs.blender.org/manual/en/dev/objects.inv",
required=False,
help="url to sphinx inventory file (objects.inv)",
metavar="FILE")
args = parser.parse_args()
if args.filename:
# Download and decode objects.inv
print("Loading from file...")
inv = soi.Inventory(args.filename)
else:
# Load and decode objects.inv
print("Downloading...")
inv = soi.Inventory(url=args.url)
write_mappings(inv, args.output)
print("Done!")
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment