import subprocess from sys import stderr from utils import console, get_error_console def getConfigParam(lines, config_id): value = None for line in lines: line = line.strip() if not line or line.startswith('#') or line.startswith(';'): continue if '=' in line: key, val = line.split('=', 1) key = key.strip() if key == config_id: value = val break return value def checkLocalConfig(config_id): try: with open('/etc/lts-cc.conf', 'r', encoding="utf-8") as file: return getConfigParam(file.readlines(), config_id) except FileNotFoundError: print("Can not find lts-cc.conf") def extractDatabases(output): lines = output.splitlines() databases = [] capture = False for line in lines: line = line.strip() if line.startswith("Name"): capture = True continue if capture: if line.startswith("----"): continue if line.strip() == "": continue name = line.split('|')[0].strip() if name != "": databases.append(name) return databases def parseDiskUsage(output): lines = output.split("\n") disk_usage = [] for line in lines[1:]: parts = line.split() if len(parts) < 6: continue percent_used = int(parts[4].replace("%", "")) mountpoint = parts[5] disk_usage.append({ 'percent_used': percent_used, 'mountpoint': mountpoint }) return disk_usage def add_branch( svn_url): branch_name = svn_url.rstrip('/').split('/')[-1] stderr_source = subprocess.run(['mkdir', f'/shd/CTC/TOOLS/TDS/source-{branch_name}'], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) if stderr_source.returncode: get_error_console().log(f"Cant create source folder: {stderr_source}") return False stderr_build = subprocess.run(['mkdir', f'/shd/CTC/TOOLS/TDS/build-{branch_name}'],stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) if stderr_build.returncode: get_error_console().log(f"Cant create build folder: {stderr_build}") return False stderr_co = subprocess.run(['svn', 'co', f'{svn_url}', f'/shd/CTC/TOOLS/TDS/source-{branch_name}'], stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) if stderr_co.returncode: get_error_console().log(f"Cant checkout branch: {stderr_co}") return False return branch_name def build_branch(branch_name, project_name, guez_mode, build_ws, build_sv, build_hla): command = ['cmake', '-G', 'Ninja', f'/shd/CTC/TOOLS/TDS/source-{branch_name}'] if guez_mode: command.append( "-DGUEZ_MODE=ON") else: command.append( "-DGUEZ_MODE=OFF") command.append("-DBUILD_TOOLSSV=ON") command.append("-DBUILD_WLS=ON") if build_ws: command.append("-DBUILD_WS=ON") else: command.append("-DBUILD_WS=OFF") command.append("-DBUILD_AAR=OFF") if build_hla: command.append("-DBUILD_SVC_HLA=ON") else: command.append("-DBUILD_SVC_HLA=OFF") if build_sv: command.append("-DBUILD_SV=ON") else: command.append("-DBUILD_SV=OFF") command.append( f'-D_pname={project_name}') command.append( "-DCMAKE_BUILD_TYPE=RelWithDebInfo") command.append("-B") command.append(f"/shd/CTC/TOOLS/TDS/build-{branch_name}") stderr_configure = subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) if stderr_configure.returncode: get_error_console().log(f"Cant configure branch: {stderr_configure.stderr}") return False stderr_build = subprocess.run(['ninja'], cwd=f'/shd/CTC/TOOLS/TDS/build-{branch_name}', stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) if stderr_build.returncode: get_error_console().log(f"Cant build branch: {stderr_build}") return False return True def build_test_db(branch_name): stderr = subprocess.run(['ninja', 'test-db'], cwd=f'/shd/CTC/TOOLS/TDS/build-{branch_name}', stdout=subprocess.DEVNULL, stderr=subprocess.PIPE) if stderr.returncode: get_error_console().log(f"Cant build test-db: {stderr}") def check_rpm_package_installed(package_prefix): try: result = subprocess.run(['rpm', '-qa', package_prefix], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) if result.returncode: get_error_console().log(f"Package {package_prefix} not installed: {stderr}") return False installed_packages = result.stdout.splitlines() matching_packages = [package for package in installed_packages if package.startswith(package_prefix)] if matching_packages: return True else: return False except Exception as e: return False