From e741f821ac4208789df2a5d2d7051c760908f738 Mon Sep 17 00:00:00 2001 From: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> Date: Mon, 6 May 2024 20:46:26 +0000 Subject: [PATCH 1/9] scripts/set-alias-page.py, scripts/set-more-info-link.py: sync documentation and get_tldr_root --- scripts/set-alias-page.py | 33 +++++++++++++++++++++------------ scripts/set-more-info-link.py | 27 ++++++++++++++------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/scripts/set-alias-page.py b/scripts/set-alias-page.py index 697792242e6ed..e9023f3693058 100755 --- a/scripts/set-alias-page.py +++ b/scripts/set-alias-page.py @@ -8,7 +8,9 @@ isn't suggested to use the sync option. If used, only stage changes and commit verified changes for your language. -Note: If there is a symlink error when using the stage flag remove the `pages.en` +Note: Before running this script from another directory as tldr, ensure that TLDR_ROOT is set to the location +of a clone of https://github.com/tldr-pages/tldr, and 'git' is available. +If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. Usage: @@ -24,15 +26,23 @@ -n, --dry-run Show what changes would be made without actually modifying the page. +Positional Argument: + COMMAND The command to be set as the alias command. Examples: 1. Add 'vi' as an alias page of 'vim': python3 scripts/set-alias-page.py -p common/vi vim + python3 scripts/set-alias-page.py --page common/vi vim 2. Read English alias pages and synchronize them into all translations: python3 scripts/set-alias-page.py -S + python3 scripts/set-alias-page.py --sync - 3. Read English alias pages and show what changes would be made: + 3. Read English alias pages, synchronize them into all translations and stage modified pages for commit: + python3 scripts/set-more-info-link.py -Ss + python3 scripts/set-more-info-link.py --sync --stage + + 4. Read English alias pages and show what changes would be made: python3 scripts/set-alias-page.py -Sn python3 scripts/set-alias-page.py --sync --dry-run """ @@ -41,6 +51,7 @@ import os import re import subprocess +from pathlib import Path IGNORE_FILES = (".DS_Store", "tldr.md", "aria2.md") @@ -51,16 +62,14 @@ def get_tldr_root(): """ # If this script is running from tldr/scripts, the parent's parent is the root - f = os.path.normpath(__file__) - if f.endswith("tldr/scripts/set-alias-page.py"): - return os.path.dirname(os.path.dirname(f)) - - if "TLDR_ROOT" in os.environ: - return os.environ["TLDR_ROOT"] - else: - raise SystemExit( - "\x1b[31mPlease set TLDR_ROOT to the location of a clone of https://github.com/tldr-pages/tldr.\x1b[0m" - ) + f = Path(__file__).resolve() + if "tldr" in str(f): + return next(path for path in f.parents if path.name == "tldr") + elif "TLDR_ROOT" in os.environ: + return Path(os.environ["TLDR_ROOT"]) + raise SystemExit( + "\x1b[31mPlease set TLDR_ROOT to the location of a clone of https://github.com/tldr-pages/tldr." + ) def get_templates(root): diff --git a/scripts/set-more-info-link.py b/scripts/set-more-info-link.py index 44b8aca95d082..49dcabbc24c98 100755 --- a/scripts/set-more-info-link.py +++ b/scripts/set-more-info-link.py @@ -5,7 +5,7 @@ This script sets the "More information" link for all translations of a page. It can be used to add or update the links in translations. -Note: Before running this script, ensure that TLDR_ROOT is set to the location +Note: Before running this script from another directory as tldr, ensure that TLDR_ROOT is set to the location of a clone of https://github.com/tldr-pages/tldr, and 'git' is available. If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. @@ -13,14 +13,14 @@ Usage: python3 scripts/set-more-info-link.py [-p PAGE] [-s] [-S] [-n] [LINK] Supported Arguments: - -p, --page Specify the page name in the format "platform/command.md". - This option allows setting the link for a specific page. - -s, --stage Stage modified pages for commit. This option requires 'git' - to be on the $PATH and TLDR_ROOT to be a Git repository. - -S, --sync Synchronize each translation's more information link (if - exists) with that of the English page. This is useful to - ensure consistency across translations. - -n, --dry-run Show what changes would be made without actually modifying the page. + -p, --page PAGE + Specify the page name in the format "platform/command.md". This option allows setting the link for a specific page. + -s, --stage + Stage modified pages for commit. This option requires 'git' to be on the $PATH and TLDR_ROOT to be a Git repository. + -S, --sync + Synchronize each translation's more information link (if exists) with that of the English page. This is useful to ensure consistency across translations. + -n, --dry-run + Show what changes would be made without actually modifying the page. Positional Argument: LINK The link to be set as the "More information" link. @@ -91,12 +91,13 @@ def get_tldr_root() -> Path: + # If this script is running from tldr/scripts, the parent's parent is the root f = Path(__file__).resolve() - return next(path for path in f.parents if path.name == "tldr") - - if "TLDR_ROOT" in os.environ: + if "tldr" in str(f): + return next(path for path in f.parents if path.name == "tldr") + elif "TLDR_ROOT" in os.environ: return Path(os.environ["TLDR_ROOT"]) - raise SystemError( + raise SystemExit( "\x1b[31mPlease set TLDR_ROOT to the location of a clone of https://github.com/tldr-pages/tldr." ) From d54d8055085a0b8ef6b32516a0b156f54477c1b5 Mon Sep 17 00:00:00 2001 From: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> Date: Tue, 7 May 2024 13:32:36 +0200 Subject: [PATCH 2/9] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: VĂ­tor Henrique <87824454+vitorhcl@users.noreply.github.com> --- scripts/set-alias-page.py | 4 ++-- scripts/set-more-info-link.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/set-alias-page.py b/scripts/set-alias-page.py index e9023f3693058..f859e3b0244ae 100755 --- a/scripts/set-alias-page.py +++ b/scripts/set-alias-page.py @@ -8,8 +8,8 @@ isn't suggested to use the sync option. If used, only stage changes and commit verified changes for your language. -Note: Before running this script from another directory as tldr, ensure that TLDR_ROOT is set to the location -of a clone of https://github.com/tldr-pages/tldr, and 'git' is available. +Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr. If you aren't, the script will use TLDR_ROOT as the tldr +root. Also, ensure 'git' is available. If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. diff --git a/scripts/set-more-info-link.py b/scripts/set-more-info-link.py index 49dcabbc24c98..74df0241532ef 100755 --- a/scripts/set-more-info-link.py +++ b/scripts/set-more-info-link.py @@ -5,8 +5,8 @@ This script sets the "More information" link for all translations of a page. It can be used to add or update the links in translations. -Note: Before running this script from another directory as tldr, ensure that TLDR_ROOT is set to the location -of a clone of https://github.com/tldr-pages/tldr, and 'git' is available. +Note: If the current directory or one of its parents is named "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr. If you aren't, the script will use TLDR_ROOT as the tldr +root. Also, ensure 'git' is available. If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. From faf6c67b1ad212d2ee66d1825d699f0f1b5cea20 Mon Sep 17 00:00:00 2001 From: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> Date: Tue, 7 May 2024 13:33:40 +0200 Subject: [PATCH 3/9] Apply suggestions from code review --- scripts/set-alias-page.py | 4 ++-- scripts/set-more-info-link.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/set-alias-page.py b/scripts/set-alias-page.py index f859e3b0244ae..0c4fc01c87357 100755 --- a/scripts/set-alias-page.py +++ b/scripts/set-alias-page.py @@ -8,8 +8,8 @@ isn't suggested to use the sync option. If used, only stage changes and commit verified changes for your language. -Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr. If you aren't, the script will use TLDR_ROOT as the tldr -root. Also, ensure 'git' is available. +Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr. +If you aren't, the script will use TLDR_ROOT as the tldr root. Also, ensure 'git' is available. If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. diff --git a/scripts/set-more-info-link.py b/scripts/set-more-info-link.py index 74df0241532ef..d32069959ac99 100755 --- a/scripts/set-more-info-link.py +++ b/scripts/set-more-info-link.py @@ -5,8 +5,8 @@ This script sets the "More information" link for all translations of a page. It can be used to add or update the links in translations. -Note: If the current directory or one of its parents is named "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr. If you aren't, the script will use TLDR_ROOT as the tldr -root. Also, ensure 'git' is available. +Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr. +If you aren't, the script will use TLDR_ROOT as the tldr root. Also, ensure 'git' is available. If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. From 85fcd4b6d50c31a63606138036b21b33b39d6515 Mon Sep 17 00:00:00 2001 From: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> Date: Tue, 7 May 2024 13:34:39 +0200 Subject: [PATCH 4/9] Apply suggestions from code review --- scripts/set-alias-page.py | 2 +- scripts/set-more-info-link.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/set-alias-page.py b/scripts/set-alias-page.py index 0c4fc01c87357..2484d188271d2 100755 --- a/scripts/set-alias-page.py +++ b/scripts/set-alias-page.py @@ -8,7 +8,7 @@ isn't suggested to use the sync option. If used, only stage changes and commit verified changes for your language. -Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr. +Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr If you aren't, the script will use TLDR_ROOT as the tldr root. Also, ensure 'git' is available. If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. diff --git a/scripts/set-more-info-link.py b/scripts/set-more-info-link.py index d32069959ac99..3f2fb645e64f2 100755 --- a/scripts/set-more-info-link.py +++ b/scripts/set-more-info-link.py @@ -5,7 +5,7 @@ This script sets the "More information" link for all translations of a page. It can be used to add or update the links in translations. -Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr. +Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr If you aren't, the script will use TLDR_ROOT as the tldr root. Also, ensure 'git' is available. If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. From b0f476073f7131da64a22040d4cc087e84304912 Mon Sep 17 00:00:00 2001 From: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> Date: Tue, 7 May 2024 13:35:59 +0200 Subject: [PATCH 5/9] Apply suggestions from code review --- scripts/set-alias-page.py | 3 +-- scripts/set-more-info-link.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/set-alias-page.py b/scripts/set-alias-page.py index 2484d188271d2..d41dd62a3ab13 100755 --- a/scripts/set-alias-page.py +++ b/scripts/set-alias-page.py @@ -10,8 +10,7 @@ Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr If you aren't, the script will use TLDR_ROOT as the tldr root. Also, ensure 'git' is available. -If there is a symlink error when using the stage flag remove the `pages.en` -directory temporarily and try executing it again. +If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. Usage: python3 scripts/set-alias-page.py [-p PAGE] [-s] [-S] [-n] [COMMAND] diff --git a/scripts/set-more-info-link.py b/scripts/set-more-info-link.py index 3f2fb645e64f2..09b311fb723cf 100755 --- a/scripts/set-more-info-link.py +++ b/scripts/set-more-info-link.py @@ -7,8 +7,7 @@ Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr If you aren't, the script will use TLDR_ROOT as the tldr root. Also, ensure 'git' is available. -If there is a symlink error when using the stage flag remove the `pages.en` -directory temporarily and try executing it again. +If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. Usage: python3 scripts/set-more-info-link.py [-p PAGE] [-s] [-S] [-n] [LINK] From d1d05e71401119ce094d3fc0bc3175c2f2fab544 Mon Sep 17 00:00:00 2001 From: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> Date: Tue, 7 May 2024 12:26:41 +0000 Subject: [PATCH 6/9] Apply suggestions from code review --- scripts/set-alias-page.py | 2 +- scripts/set-more-info-link.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/set-alias-page.py b/scripts/set-alias-page.py index d41dd62a3ab13..1e8655fdc9782 100755 --- a/scripts/set-alias-page.py +++ b/scripts/set-alias-page.py @@ -176,7 +176,7 @@ def set_alias_page(file, command, dry_run=False): action = "updated" if dry_run: - status = f"page will be {action}" + status = f"page would be {action}" else: status = f"page {action}" diff --git a/scripts/set-more-info-link.py b/scripts/set-more-info-link.py index 09b311fb723cf..dad3b84f1415b 100755 --- a/scripts/set-more-info-link.py +++ b/scripts/set-more-info-link.py @@ -151,7 +151,7 @@ def set_link(path: Path, link: str, dry_run=False) -> str: action = "added" if dry_run: - status = f"link will be {action}" + status = f"link would be {action}" else: status = f"link {action}" From c2ea1b2efdb85d7c01e8cc6d008e3b2b230813c7 Mon Sep 17 00:00:00 2001 From: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> Date: Tue, 7 May 2024 14:15:13 +0000 Subject: [PATCH 7/9] Apply suggestions from code review --- scripts/set-alias-page.py | 6 ++++-- scripts/set-more-info-link.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/set-alias-page.py b/scripts/set-alias-page.py index 1e8655fdc9782..9953224c358e7 100755 --- a/scripts/set-alias-page.py +++ b/scripts/set-alias-page.py @@ -62,8 +62,10 @@ def get_tldr_root(): # If this script is running from tldr/scripts, the parent's parent is the root f = Path(__file__).resolve() - if "tldr" in str(f): - return next(path for path in f.parents if path.name == "tldr") + if ( + tldr_root := next((path for path in f.parents if path.name == "tldr"), None) + ) is not None: + return tldr_root elif "TLDR_ROOT" in os.environ: return Path(os.environ["TLDR_ROOT"]) raise SystemExit( diff --git a/scripts/set-more-info-link.py b/scripts/set-more-info-link.py index dad3b84f1415b..d61c505de07b4 100755 --- a/scripts/set-more-info-link.py +++ b/scripts/set-more-info-link.py @@ -92,8 +92,10 @@ def get_tldr_root() -> Path: # If this script is running from tldr/scripts, the parent's parent is the root f = Path(__file__).resolve() - if "tldr" in str(f): - return next(path for path in f.parents if path.name == "tldr") + if ( + tldr_root := next((path for path in f.parents if path.name == "tldr"), None) + ) is not None: + return tldr_root elif "TLDR_ROOT" in os.environ: return Path(os.environ["TLDR_ROOT"]) raise SystemExit( From 443400c84d84dd9e24d91c3158419695712246ea Mon Sep 17 00:00:00 2001 From: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> Date: Sun, 12 May 2024 10:37:39 +0000 Subject: [PATCH 8/9] scripts/set-alias-page.py, scripts/set-more-info-link.py: update docs --- scripts/set-alias-page.py | 33 ++++++++++++++++----------------- scripts/set-more-info-link.py | 35 ++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/scripts/set-alias-page.py b/scripts/set-alias-page.py index aa326b22181a0..3bed474fc9cdf 100755 --- a/scripts/set-alias-page.py +++ b/scripts/set-alias-page.py @@ -10,20 +10,19 @@ Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr If you aren't, the script will use TLDR_ROOT as the tldr root. Also, ensure 'git' is available. -If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. Usage: - python3 scripts/set-alias-page.py [-p PAGE] [-l LANGUAGE] [-s] [-S] [-n] [COMMAND] + python3 scripts/set-alias-page.py [-p PAGE] [-S] [-l LANGUAGE] [-s] [-n] [COMMAND] Options: -p, --page PAGE Specify the alias page in the format "platform/alias_command.md". + -S, --sync + Synchronize each translation's alias page (if exists) with that of the English page. -l, --language LANGUAGE Specify the language, a POSIX Locale Name in the form of "ll" or "ll_CC" (e.g. "fr" or "pt_BR"). -s, --stage Stage modified pages (requires 'git' on $PATH and TLDR_ROOT to be a Git repository). - -S, --sync - Synchronize each translation's alias page (if exists) with that of the English page. -n, --dry-run Show what changes would be made without actually modifying the page. @@ -39,17 +38,17 @@ python3 scripts/set-alias-page.py -S python3 scripts/set-alias-page.py --sync - 3. Read English alias pages, synchronize them into all translations and stage modified pages for commit: + 3. Read English alias pages and synchronize them for Brazilian Portuguese pages only: + python3 scripts/set-alias-page.py -S -l pt_BR + python3 scripts/set-alias-page.py --sync --language pt_BR + + 4. Read English alias pages, synchronize them into all translations and stage modified pages for commit: python3 scripts/set-more-info-link.py -Ss python3 scripts/set-more-info-link.py --sync --stage - 4. Read English alias pages and show what changes would be made: + 5. Read English alias pages and show what changes would be made: python3 scripts/set-alias-page.py -Sn python3 scripts/set-alias-page.py --sync --dry-run - - 4. Read English alias pages and synchronize them for Brazilian Portuguese pages only: - python3 scripts/set-alias-page.py -S -l pt_BR - python3 scripts/set-alias-page.py --sync --language pt_BR """ import argparse @@ -247,6 +246,13 @@ def main(): default="", help='page name in the format "platform/alias_command.md"', ) + parser.add_argument( + "-S", + "--sync", + action="store_true", + default=False, + help="synchronize each translation's alias page (if exists) with that of English page", + ) parser.add_argument( "-l", "--language", @@ -262,13 +268,6 @@ def main(): default=False, help="stage modified pages (requires `git` to be on $PATH and TLDR_ROOT to be a Git repository)", ) - parser.add_argument( - "-S", - "--sync", - action="store_true", - default=False, - help="synchronize each translation's alias page (if exists) with that of English page", - ) parser.add_argument( "-n", "--dry-run", diff --git a/scripts/set-more-info-link.py b/scripts/set-more-info-link.py index d61c505de07b4..3326e74d95edd 100755 --- a/scripts/set-more-info-link.py +++ b/scripts/set-more-info-link.py @@ -2,22 +2,21 @@ # SPDX-License-Identifier: MIT """ -This script sets the "More information" link for all translations of a page. -It can be used to add or update the links in translations. +A Python script to add or update the "More information" link for all translations of a page. Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr If you aren't, the script will use TLDR_ROOT as the tldr root. Also, ensure 'git' is available. -If there is a symlink error when using the stage flag remove the `pages.en` directory temporarily and try executing it again. -Usage: python3 scripts/set-more-info-link.py [-p PAGE] [-s] [-S] [-n] [LINK] +Usage: + python3 scripts/set-more-info-link.py [-p PAGE] [-S] [-s] [-n] [LINK] -Supported Arguments: +Options: -p, --page PAGE - Specify the page name in the format "platform/command.md". This option allows setting the link for a specific page. - -s, --stage - Stage modified pages for commit. This option requires 'git' to be on the $PATH and TLDR_ROOT to be a Git repository. + Specify the alias page in the format "platform/alias_command.md". -S, --sync - Synchronize each translation's more information link (if exists) with that of the English page. This is useful to ensure consistency across translations. + Synchronize each translation's more information link (if exists) with that of the English page. + -s, --stage + Stage modified pages (requires 'git' on $PATH and TLDR_ROOT to be a Git repository). -n, --dry-run Show what changes would be made without actually modifying the page. @@ -27,11 +26,13 @@ Examples: 1. Set the link for a specific page: python3 scripts/set-more-info-link.py -p common/tar.md https://example.com + python3 scripts/set-more-info-link.py --page common/tar.md https://example.com - 2. Synchronize more information links across translations: + 2. Read English pages and synchronize more information links across translations: python3 scripts/set-more-info-link.py -S + python3 scripts/set-more-info-link.py --sync - 3. Synchronize more information links across translations and stage modified pages for commit: + 3. Read English pages, synchronize more information links across translations and stage modified pages for commit: python3 scripts/set-more-info-link.py -Ss python3 scripts/set-more-info-link.py --sync --stage @@ -216,18 +217,18 @@ def main(): help='page name in the format "platform/command.md"', ) parser.add_argument( - "-s", - "--stage", + "-S", + "--sync", action="store_true", default=False, - help="stage modified pages (requires `git` to be on $PATH and TLDR_ROOT to be a Git repository)", + help="synchronize each translation's more information link (if exists) with that of English page", ) parser.add_argument( - "-S", - "--sync", + "-s", + "--stage", action="store_true", default=False, - help="synchronize each translation's more information link (if exists) with that of English page", + help="stage modified pages (requires `git` to be on $PATH and TLDR_ROOT to be a Git repository)", ) parser.add_argument( "-n", From adf2f57a381f49145915e378cbaac3842c17fe42 Mon Sep 17 00:00:00 2001 From: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com> Date: Mon, 13 May 2024 13:30:07 +0000 Subject: [PATCH 9/9] scripts/set-*.py: final sync for docs and get_tldr_root --- scripts/set-alias-page.py | 4 +--- scripts/set-more-info-link.py | 8 ++++++-- scripts/set-page-title.py | 32 +++++++++++++++++++------------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/scripts/set-alias-page.py b/scripts/set-alias-page.py index 3bed474fc9cdf..9aae34fc598c4 100755 --- a/scripts/set-alias-page.py +++ b/scripts/set-alias-page.py @@ -4,9 +4,7 @@ """ A Python script to generate or update alias pages. -Disclaimer: This script generates a lot of false positives so it -isn't suggested to use the sync option. If used, only stage changes -and commit verified changes for your language by using -l LANGUAGE. +Disclaimer: This script generates a lot of false positives so it isn't suggested to use the sync option. If used, only stage changes and commit verified changes for your language by using -l LANGUAGE. Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr If you aren't, the script will use TLDR_ROOT as the tldr root. Also, ensure 'git' is available. diff --git a/scripts/set-more-info-link.py b/scripts/set-more-info-link.py index 3326e74d95edd..fb1fa3d672a72 100755 --- a/scripts/set-more-info-link.py +++ b/scripts/set-more-info-link.py @@ -12,7 +12,7 @@ Options: -p, --page PAGE - Specify the alias page in the format "platform/alias_command.md". + Specify the alias page in the format "platform/alias_command.md". This option allows setting the link for a specific page. -S, --sync Synchronize each translation's more information link (if exists) with that of the English page. -s, --stage @@ -90,7 +90,11 @@ IGNORE_FILES = (".DS_Store",) -def get_tldr_root() -> Path: +def get_tldr_root(): + """ + Get the path of local tldr repository for environment variable TLDR_ROOT. + """ + # If this script is running from tldr/scripts, the parent's parent is the root f = Path(__file__).resolve() if ( diff --git a/scripts/set-page-title.py b/scripts/set-page-title.py index 8f6915494224c..d34f65d5813e9 100755 --- a/scripts/set-page-title.py +++ b/scripts/set-page-title.py @@ -2,23 +2,23 @@ # SPDX-License-Identifier: MIT """ -This script sets the title for all translations of a page. -It can be used to update the titles in translations. +A Python script to add or update the page title for all translations of a page. Note: If the current directory or one of its parents is called "tldr", the script will assume it is the tldr root, i.e., the directory that contains a clone of https://github.com/tldr-pages/tldr If you aren't, the script will use TLDR_ROOT as the tldr root. Also, ensure 'git' is available. -Usage: python3 scripts/set-page-title.py [-p PAGE] [-s] [-S] [-n] [TITLE] +Usage: + python3 scripts/set-page-title.py [-p PAGE] [-S] [-s] [-n] [TITLE] -Supported Arguments: - -p, --page Specify the page name in the format "platform/command.md". - This option allows setting the title for a specific page. - -s, --stage Stage modified pages for commit. This option requires 'git' - to be on the $PATH and TLDR_ROOT to be a Git repository. - -S, --sync Synchronize each translation's title (if - exists) with that of the English page. This is useful to - ensure consistency across translations. - -n, --dry-run Show what changes would be made without actually modifying the page. +Options: + -p, --page PAGE + Specify the page in the format "platform/command.md". This option allows setting the title for a specific page. + -S, --sync + Synchronize each translation's title (if exists) with that of the English page. + -s, --stage + Stage modified pages (requires 'git' on $PATH and TLDR_ROOT to be a Git repository). + -n, --dry-run + Show what changes would be made without actually modifying the page. Positional Argument: TITLE The title to be set as the title. @@ -26,9 +26,11 @@ Examples: 1. Set the title for a specific page: python3 scripts/set-page-title.py -p common/tar.md tar.1 + python3 scripts/set-page-title.py --page common/tar.md tar.1 2. Synchronize titles across translations: python3 scripts/set-page-title.py -S + python3 scripts/set-page-title.py --sync 3. Synchronize titles across translations and stage modified pages for commit: python3 scripts/set-page-title.py -Ss @@ -47,7 +49,11 @@ IGNORE_FILES = (".DS_Store",) -def get_tldr_root() -> Path: +def get_tldr_root(): + """ + Get the path of local tldr repository for environment variable TLDR_ROOT. + """ + # If this script is running from tldr/scripts, the parent's parent is the root f = Path(__file__).resolve() if (