From 3614119529e31caae97e0b920c80173887a81503 Mon Sep 17 00:00:00 2001 From: yungwine Date: Mon, 20 May 2024 13:42:19 +0700 Subject: [PATCH] fix git config in status and telemetry --- mytoncore/functions.py | 5 ++++- mytonctrl/mytonctrl.py | 19 +++---------------- mytonctrl/utils.py | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/mytoncore/functions.py b/mytoncore/functions.py index 12e36ba3..0cca873a 100755 --- a/mytoncore/functions.py +++ b/mytoncore/functions.py @@ -10,6 +10,7 @@ import subprocess from mytoncore.mytoncore import MyTonCore +from mytonctrl.utils import fix_git_config from mytoninstaller.config import GetConfig from mypylib.mypylib import ( b2mb, @@ -420,7 +421,9 @@ def Telemetry(local, ton): # Get git hashes gitHashes = dict() - gitHashes["mytonctrl"] = get_git_hash("/usr/src/mytonctrl") + mtc_path = "/usr/src/mytonctrl" + local.try_function(fix_git_config, args=[mtc_path]) + gitHashes["mytonctrl"] = get_git_hash(mtc_path) gitHashes["validator"] = GetBinGitHash( "/usr/bin/ton/validator-engine/validator-engine") data["gitHashes"] = gitHashes diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index 43ace71c..138aee8d 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -40,7 +40,7 @@ GetBinGitHash, ) from mytonctrl.migrate import run_migrations -from mytonctrl.utils import GetItemFromList, timestamp2utcdatetime +from mytonctrl.utils import GetItemFromList, timestamp2utcdatetime, fix_git_config import sys, getopt, os @@ -290,21 +290,6 @@ def check_vport(local, ton): #end define -def fix_git_config(git_path: str): - args = ["git", "status"] - try: - process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=git_path, timeout=3) - err = process.stderr.decode("utf-8") - except Exception as e: - err = str(e) - if err: - if 'git config --global --add safe.directory' in err: - args = ["git", "config", "--global", "--add", "safe.directory", git_path] - subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3) - else: - raise Exception(f'Failed to check git status: {err}') -#end define - def check_git(input_args, default_repo, text): src_dir = "/usr/src" git_path = f"{src_dir}/{default_repo}" @@ -708,6 +693,8 @@ def PrintLocalStatus(local, adnlAddr, validatorIndex, validatorEfficiency, valid validatorBinGitPath = "/usr/bin/ton/validator-engine/validator-engine" mtcGitHash = get_git_hash(mtcGitPath, short=True) validatorGitHash = GetBinGitHash(validatorBinGitPath, short=True) + fix_git_config(mtcGitPath) + fix_git_config(validatorGitPath) mtcGitBranch = get_git_branch(mtcGitPath) validatorGitBranch = get_git_branch(validatorGitPath) mtcGitHash_text = bcolors.yellow_text(mtcGitHash) diff --git a/mytonctrl/utils.py b/mytonctrl/utils.py index 12dba3c9..ba6cd105 100644 --- a/mytonctrl/utils.py +++ b/mytonctrl/utils.py @@ -1,3 +1,4 @@ +import subprocess import time @@ -12,3 +13,19 @@ def GetItemFromList(data, index): return data[index] except: pass + + +def fix_git_config(git_path: str): + args = ["git", "status"] + try: + process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=git_path, timeout=3) + err = process.stderr.decode("utf-8") + except Exception as e: + err = str(e) + if err: + if 'git config --global --add safe.directory' in err: + args = ["git", "config", "--global", "--add", "safe.directory", git_path] + subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3) + else: + raise Exception(f'Failed to check git status: {err}') +#end define