Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1194751lqs; Fri, 14 Jun 2024 20:54:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWR04ZzbqFiHpoB0VyGEJlrOBaqFhi01Y2qdasBmGbfPZcsevumkzr6WYEX54TS3UMRJtyb5Sn3a0OgqtfmWoVWzatn7mgwBVOCKskFNA== X-Google-Smtp-Source: AGHT+IFrvFfEsWbj0RdYK7hIpRvWqsIjuhfs2YyETSAHjqQ4tSHBAn4tAP4YScVK8JMhkvPUGY13 X-Received: by 2002:a9d:4f0e:0:b0:6fb:7388:1295 with SMTP id 46e09a7af769-6fb93651105mr5033434a34.5.1718423673772; Fri, 14 Jun 2024 20:54:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718423673; cv=pass; d=google.com; s=arc-20160816; b=OkRpi4MjnSp4qv5SMpDM9kNA6BLUzT2Mu3Ad00S9cHiC54J0ZN23BouBcT8hj8K8NN M1VSro59wYsjMhdIA99HWJ+qG+5kqOS5eYyY2nhErE5AdJ/FYdi6YHpKWZK1u6jvkORF trSKMIdHXhpGiDjAn0NjFO+9lJm8UFCzJw/oBY82mlQQboD4++87PPnLpCUXtT7A0KAU AOOYddzK5c7GajECnxQaydY1zbAcOgyFKWeuSpOi4soWoF2TDo7KuVNlav97c2yzT0Sc oguUEB6xm1Pn80KR34q3Ybs3VOs0g2jNXtUZ+0IRa2DlsdOXeoSDmO8hIQM8yfJDNtur RipA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=ypiuSX5QDI2cc4GXXq3FWkyuPPzKyLKLS/EzrisF+kU=; fh=nS/fmrZxyy9hu8r35XcxAQjwu0N9TY3cvKs58iSuz5o=; b=vV8EvRv3Xxv5cyZBql83nn8wGBggJ0j+vukknn3IjlWPf1Lzbxf+BSyBkQ4Uos/XVs XfG1zHy0ClcVn4G1nmIeqZeiJYVY5p6FheLFJKlftpoS5jnhRxCPRhDVkgfKQlIv8we9 zSiNUNV7+Ekirq4tU/ejjnZlVLGY9ON4Bsm/z3mkofodRSkpYWoa5/CJ0oNhE/RvPjBU t3yVTDkEKYbQ51bvhvfqNcuqVEUSu98dud7IpFBYg031PSSsroYK4RjsD3rtYhXdsVXA hmbXihTvhw/w/L58Tck1Wl/4XOrgwDyIVyaNSFA4rsfvQ+TE28Nk+smGK0ZgyUyWqCGR KxZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=hust.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-215694-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215694-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6fedd4f3f4csi2410512a12.164.2024.06.14.20.54.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jun 2024 20:54:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-215694-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hust.edu.cn); spf=pass (google.com: domain of linux-kernel+bounces-215694-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-215694-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C992FB2324C for ; Sat, 15 Jun 2024 03:54:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD8F9EAEB; Sat, 15 Jun 2024 03:54:23 +0000 (UTC) Received: from zg8tmtyylji0my4xnjeumjiw.icoremail.net (zg8tmtyylji0my4xnjeumjiw.icoremail.net [162.243.161.220]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A84ECDDA9 for ; Sat, 15 Jun 2024 03:54:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=162.243.161.220 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718423663; cv=none; b=a4YpLSvnEcjOH/ZQqZDx98c68M5QCLxG80b7rG6bY1tQ5JJljnGomA+Tav/ty+chL+m/Cmy2eoYypKVJUfJ32kIAlpCvw5KMRTmCxJ9zayNVQwWf6C2k3EYwPfX7IgqjjoFXUPph53cVSgBJQoUg28E9EVSXDaNBAAeZBImEInA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718423663; c=relaxed/simple; bh=fVCy6/dkF7HT91z7sabukVEP02eEuNJGU6rMT2irjBo=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=EH47jzYxP/jXQ+XusM3cBG+w0HFX22m7bFflaUgBZdKowaMgfzrgzYOyf+8lPR/121NahmdD8dNg1wa6OoG7xgn+0Td7v5Q2gUhCgwGJ/w3UyhGFl4s3uwHzjVDv29C+7Fh6Hh+TAyQ2pSBEm6fHwuhSPlKGvimucf0xYWW6awg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hust.edu.cn; spf=pass smtp.mailfrom=hust.edu.cn; arc=none smtp.client-ip=162.243.161.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hust.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hust.edu.cn Received: from hust.edu.cn (unknown [172.16.0.50]) by app1 (Coremail) with SMTP id HgEQrABXWilFEG1mb33oBw--.32212S2; Sat, 15 Jun 2024 11:53:41 +0800 (CST) Received: from localhost.localdomain (unknown [10.12.164.29]) by gateway (Coremail) with SMTP id _____wBnYN8_EG1mKgQrAA--.4979S2; Sat, 15 Jun 2024 11:53:40 +0800 (CST) From: Dongliang Mu To: Dongliang Mu , Jonathan Corbet , Cheng Ziqiu , Yanteng Si , Alex Shi Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] scripts: fix most issues reported by pylint Date: Sat, 15 Jun 2024 11:53:16 +0800 Message-Id: <20240615035323.909650-1-dzm91@hust.edu.cn> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:HgEQrABXWilFEG1mb33oBw--.32212S2 Authentication-Results: app1; spf=neutral smtp.mail=dzm91@hust.edu.cn; X-Coremail-Antispam: 1UD129KBjvJXoW3AF1DAr47tF4kKFWruF4fAFb_yoWxGF15p3 45CFWIyrs8JrWUtr1xGw4UZFy3Ar9rJrWjqryqq3s7ArnrK3409FW2y34SvrW7WFyrXa43 GFWYyr1jqF1j9aDanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQFb7Iv0xC_Kw4lb4IE77IF4wAFc2x0x2IEx4CE42xK8VAvwI8I cIk0rVWrJVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjx v20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwA2z4x0Y4vE x4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAaw2AFwI0_Jr v_JF1lnxkEFVAIw20F6cxK64vIFxWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF 0cIa020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0EF7xvrVAajcxG14v26r 4UJVWxJr1lYx0E74AGY7Cv6cx26r4fZr1UJr1lYx0Ec7CjxVAajcxG14v26r4j6F4UMcvj eVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7AKxVWUAVWUtwCF04 k20xvY0x0EwIxGrwCF04k20xvE74AGY7Cv6cx26r4fZr1UJr1l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E 14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07bcsj8UUUUU= X-CM-SenderInfo: asqsiiirqrkko6kx23oohg3hdfq/ Pylint reports many coding style issues of scripts/checktransupdate.py This patch fixes most issues with the following contents: - add or revise comments for all functions - use format string suggested by python Signed-off-by: Dongliang Mu --- scripts/checktransupdate.py | 55 ++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/scripts/checktransupdate.py b/scripts/checktransupdate.py index 5a0fc99e3f93..70a5dab1a17b 100755 --- a/scripts/checktransupdate.py +++ b/scripts/checktransupdate.py @@ -4,19 +4,9 @@ """ This script helps track the translation status of the documentation in different locales, e.g., zh_CN. More specially, it uses `git log` -commit to find the latest english commit from the translation commit -(order by author date) and the latest english commits from HEAD. If +command to find the latest English commit from the translation commit +(order by author date) and the latest English commits from HEAD. If differences occur, report the file and commits that need to be updated. - -The usage is as follows: -- ./scripts/checktransupdate.py -l zh_CN -This will print all the files that need to be updated in the zh_CN locale. -- ./scripts/checktransupdate.py Documentation/translations/zh_CN/dev-tools/testing-overview.rst -This will only print the status of the specified file. - -The output is something like: -Documentation/translations/zh_CN/dev-tools/testing-overview.rst (1 commits) -commit 42fb9cfd5b18 ("Documentation: dev-tools: Add link to RV docs") """ import os @@ -29,12 +19,14 @@ flag_debug = False def dprint(*args, **kwargs): + """Print debug information if the debug flag is set""" if flag_debug: print("[DEBUG] ", end="") print(*args, **kwargs) def get_origin_path(file_path): + """Get the origin path from the translation path""" paths = file_path.split("/") tidx = paths.index("translations") opaths = paths[:tidx] @@ -43,9 +35,8 @@ def get_origin_path(file_path): def get_latest_commit_from(file_path, commit): - command = "git log --pretty=format:%H%n%aD%n%cD%n%n%B {} -1 -- {}".format( - commit, file_path - ) + """Get the latest commit from the specified commit for the specified file""" + command = f"git log --pretty=format:%H%n%aD%n%cD%n%n%B {commit} -1 -- {file_path}" dprint(command) pipe = os.popen(command) result = pipe.read() @@ -53,7 +44,7 @@ def get_latest_commit_from(file_path, commit): if len(result) <= 1: return None - dprint("Result: {}".format(result[0])) + dprint(f"Result: {result[0]}") return { "hash": result[0], @@ -64,16 +55,18 @@ def get_latest_commit_from(file_path, commit): def get_origin_from_trans(origin_path, t_from_head): + """Get the latest origin commit from the translation commit""" o_from_t = get_latest_commit_from(origin_path, t_from_head["hash"]) while o_from_t is not None and o_from_t["author_date"] > t_from_head["author_date"]: o_from_t = get_latest_commit_from(origin_path, o_from_t["hash"] + "^") if o_from_t is not None: - dprint("tracked origin commit id: {}".format(o_from_t["hash"])) + dprint(f"tracked origin commit id: {o_from_t['hash']}") return o_from_t def get_commits_count_between(opath, commit1, commit2): - command = "git log --pretty=format:%H {}...{} -- {}".format(commit1, commit2, opath) + """Get the commits count between two commits for the specified file""" + command = f"git log --pretty=format:%H {commit1}...{commit2} -- {opath}" dprint(command) pipe = os.popen(command) result = pipe.read().split("\n") @@ -83,50 +76,52 @@ def get_commits_count_between(opath, commit1, commit2): def pretty_output(commit): - command = "git log --pretty='format:%h (\"%s\")' -1 {}".format(commit) + """Pretty print the commit message""" + command = f"git log --pretty='format:%h (\"%s\")' -1 {commit}" dprint(command) pipe = os.popen(command) return pipe.read() def check_per_file(file_path): + """Check the translation status for the specified file""" opath = get_origin_path(file_path) if not os.path.isfile(opath): - dprint("Error: Cannot find the origin path for {}".format(file_path)) + dprint(f"Error: Cannot find the origin path for {file_path}") return o_from_head = get_latest_commit_from(opath, "HEAD") t_from_head = get_latest_commit_from(file_path, "HEAD") if o_from_head is None or t_from_head is None: - print("Error: Cannot find the latest commit for {}".format(file_path)) + print(f"Error: Cannot find the latest commit for {file_path}") return o_from_t = get_origin_from_trans(opath, t_from_head) if o_from_t is None: - print("Error: Cannot find the latest origin commit for {}".format(file_path)) + print(f"Error: Cannot find the latest origin commit for {file_path}") return if o_from_head["hash"] == o_from_t["hash"]: if flag_p_uf: - print("No update needed for {}".format(file_path)) - return + print(f"No update needed for {file_path}") else: - print("{}".format(file_path), end="\t") + print(f"{file_path}", end="\t") commits = get_commits_count_between( opath, o_from_t["hash"], o_from_head["hash"] ) - print("({} commits)".format(len(commits))) + print(f"({len(commits)} commits)") if flag_p_c: for commit in commits: msg = pretty_output(commit) if "Merge tag" not in msg: - print("commit", msg) + print(f"commit {msg}") def main(): + """Main function of the script""" script_path = os.path.dirname(os.path.abspath(__file__)) linux_path = os.path.join(script_path, "..") @@ -173,9 +168,7 @@ def main(): if args.locale is not None: files = ( os.popen( - "find {}/Documentation/translations/{} -type f".format( - linux_path, args.locale - ) + f"find {linux_path}/Documentation/translations/{args.locale} -type f" ) .read() .split("\n") @@ -183,7 +176,7 @@ def main(): else: files = ( os.popen( - "find {}/Documentation/translations -type f".format(linux_path) + f"find {linux_path}/Documentation/translations -type f" ) .read() .split("\n") -- 2.39.2