From 70fda0b1ef6a73f7a79314b28b832d7f3fad6a6e Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sun, 12 Jun 2022 14:52:17 +0500 Subject: [PATCH] dynamically get php extensions centos/alma --- managePHP/views.py | 62 +++++++++++++++++++++++++++++++++------------- plogical/test.py | 5 ++++ 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/managePHP/views.py b/managePHP/views.py index d942134ee..cc9e75885 100755 --- a/managePHP/views.py +++ b/managePHP/views.py @@ -1296,6 +1296,11 @@ def getExtensionsInformation(request): if os.path.exists('/etc/lsb-release'): command = f'apt list | grep {phpVers}' + else: + command = 'yum list installed' + resultInstalled = ProcessUtilities.outputExecutioner(command) + + command = f'yum list | grep {phpVers} | xargs -n3 | column -t' result = ProcessUtilities.outputExecutioner(command).split('\n') @@ -1306,27 +1311,50 @@ def getExtensionsInformation(request): counter = 1 for items in result: + if os.path.exists('/etc/lsb-release'): + if items.find(phpVers) > -1: + if items.find('installed') == -1: + status = "Not-Installed" + else: + status = "Installed" - if items.find(phpVers) > -1: + dic = {'id': counter, + 'phpVers': phpVers, + 'extensionName': items.split('/')[0], + 'description': items, + 'status': status + } - if items.find('installed') == -1: - status = "Not-Installed" - else: - status = "Installed" + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) + counter += 1 + else: + ResultExt = items.split(' ') + extesnion = ResultExt[0] - dic = {'id': counter, - 'phpVers': phpVers, - 'extensionName': items.split('/')[0], - 'description': items, - 'status': status - } + if extesnion.find(phpVers) > -1: + if resultInstalled.find(extesnion) == -1: + status = "Not-Installed" + else: + status = "Installed" - if checker == 0: - json_data = json_data + json.dumps(dic) - checker = 1 - else: - json_data = json_data + ',' + json.dumps(dic) - counter += 1 + dic = {'id': counter, + 'phpVers': phpVers, + 'extensionName': extesnion, + 'description': items, + 'status': status + } + + + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) + counter += 1 json_data = json_data + ']' final_json = json.dumps({'fetchStatus': 1, 'error_message': "None", "data": json_data}) diff --git a/plogical/test.py b/plogical/test.py index e69de29bb..43397b4b2 100644 --- a/plogical/test.py +++ b/plogical/test.py @@ -0,0 +1,5 @@ +import subprocess, shlex +command = 'yum list | grep lsphp | xargs -n3 | column -t' +result = subprocess.check_output(command, shell=True).splitlines() +for item in result: + print(item.split(b' '))