From 8092a1881a495dbbea63e82d9d65284932e5eaea 2025-03-02 00:58:38 From: Branko Majic Date: 2025-03-02 00:58:38 Subject: [PATCH] [thebuggenie_hg_remote.py] Fixed linter errors: - Mostly spacing-related. - Use the range function instead of xrange (Python 2.7 -> Python 3.x). - Script probably will not run correctly under Python 3.x, but at least the linter will not get in the way when working on other Python code in the project. --- diff --git a/hooks/thebuggenie_hg_remote.py b/hooks/thebuggenie_hg_remote.py index 6b85f6ba396c01b5b58bb1b85d146dbe81dd621f..d7c3ca5c3a6ecf2ad07de373860110699a2a23d9 100755 --- a/hooks/thebuggenie_hg_remote.py +++ b/hooks/thebuggenie_hg_remote.py @@ -25,7 +25,7 @@ # passkey = project_passkey # project = project_id # nosslverify = [true|false] -# +# # [hooks] # changegroup.buggenie = python:buggenie.hook # @@ -59,6 +59,7 @@ import subprocess import mercurial.node + def call_program(program, arguments, url): """ Calls the specified program, passing it the arguments. The URL is passed @@ -83,7 +84,7 @@ def call_program(program, arguments, url): arguments.insert(0, program) # Set-up the subprocess for execution. - process = subprocess.Popen(arguments, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE) + process = subprocess.Popen(arguments, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # curl expects slightly different format when reading URL from stdin. if program == "curl": @@ -95,6 +96,7 @@ def call_program(program, arguments, url): # Return the exit code of process, and message that should be shown to user. return process.returncode, stdout, stderr + def extract_report(repo, context): """ Extract the commit report from provided context. @@ -141,12 +143,13 @@ def extract_report(repo, context): # Finally return the report. return report + def submit_report(commit, repo, ui, program, program_params, base_url, project_id, passkey): """ Submits report to TBG for a single commit. Arguments: - + commit - Mercurial commit identifier. repo - Mercurial repository object. @@ -178,7 +181,7 @@ def submit_report(commit, repo, ui, program, program_params, base_url, project_i # Set-up the base link for project. url = "%s/vcs_integration/report/%s/?" % (base_url, project_id) # Pass the GET arguments. - args = [ "%s=%s" % (quote(key), quote(value)) for key, value in report.iteritems()] + args = ["%s=%s" % (quote(key), quote(value)) for key, value in report.iteritems()] url += "&".join(args) # Call the program. @@ -206,7 +209,8 @@ def submit_report(commit, repo, ui, program, program_params, base_url, project_i stdout += "\n" ui.warn(stdout) -def hook(ui, repo, hooktype, node = None, url = None, **kwargs): + +def hook(ui, repo, hooktype, node=None, url=None, **kwargs): """ Commit and changegroup hook for Mercurial. @@ -228,28 +232,28 @@ def hook(ui, repo, hooktype, node = None, url = None, **kwargs): config = dict((param, value) for param, value in ui.configitems('buggenie')) # Make sure the required settings were specified. - if not "program" in config: + if "program" not in config: ui.warn("TBG HG Hook: No program was specified. Check your settings.\n") return - if not "url" in config: + if "url" not in config: ui.warn("TBG HG Hook: No base URL was specified. Check your settings.\n") return - if not "project" in config: + if "project" not in config: ui.warn("TBG HG Hook: No project ID was specified. Check your settings.\n") return - if not "passkey" in config: + if "passkey" not in config: ui.warn("TBG HG Hook: No passkey was specified. Check your settings.\n") return # Set-up parameters to be passed onto program. if config["program"] == "wget": # Use dots for progress, output to stdout, read link from stdin. - program_params = [ "--progress=dot", "-O", "-", "-i", "-" ] + program_params = ["--progress=dot", "-O", "-", "-i", "-"] if config.get("nosslverify") == "true": program_params.append("--no-check-certificate") elif config["program"] == "curl": # Quiet, but show errors, fail on server error, and read link from stdin. - program_params = [ "-s", "-S", "-f", "-K", "-" ] + program_params = ["-s", "-S", "-f", "-K", "-"] if config.get("nosslverify") == "true": program_params.append("--insecure") else: @@ -264,10 +268,11 @@ def hook(ui, repo, hooktype, node = None, url = None, **kwargs): start = repo.changelog.rev(node_hash) end = len(repo.changelog) - for commit in xrange(start, end): - submit_report(commit, repo, ui, config["program"], program_params, config["url"], config["project"], config["passkey"]) + for commit in range(start, end): + submit_report(commit, repo, ui, + config["program"], program_params, config["url"], config["project"], config["passkey"]) # If the hook is called as a commit, hook, process just the single commit. elif hooktype == "commit": - submit_report(commit, repo, ui, config["program"], program_params, config["url"], config["project"], config["passkey"]) - + submit_report(commit, repo, ui, + config["program"], program_params, config["url"], config["project"], config["passkey"])