From 7f7d25d1f940e7606b6e6b44a2d19571aec42eda Mon Sep 17 00:00:00 2001 From: usmannasir Date: Sun, 3 Sep 2023 11:31:12 +0500 Subject: [PATCH] bug fix: return only the php versions exists on the server --- managePHP/phpManager.py | 32 +++++++++++++++++++++++--------- plogical/test.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/managePHP/phpManager.py b/managePHP/phpManager.py index f21d9674c..222f5f96d 100755 --- a/managePHP/phpManager.py +++ b/managePHP/phpManager.py @@ -12,15 +12,29 @@ class PHPManager: @staticmethod def findPHPVersions(): - distro = ProcessUtilities.decideDistro() - if distro == ProcessUtilities.centos: - return ['PHP 5.3', 'PHP 5.4', 'PHP 5.5', 'PHP 5.6', 'PHP 7.0', 'PHP 7.1', 'PHP 7.2', 'PHP 7.3', 'PHP 7.4', 'PHP 8.0', 'PHP 8.1'] - elif distro == ProcessUtilities.cent8: - return ['PHP 7.1','PHP 7.2', 'PHP 7.3', 'PHP 7.4', 'PHP 8.0', 'PHP 8.1'] - elif distro == ProcessUtilities.ubuntu20: - return ['PHP 7.2', 'PHP 7.3', 'PHP 7.4', 'PHP 8.0', 'PHP 8.1'] - else: - return ['PHP 7.0', 'PHP 7.1', 'PHP 7.2', 'PHP 7.3', 'PHP 7.4', 'PHP 8.0', 'PHP 8.1'] + import re + import os + php_versions = [] + lsws_directory = "/usr/local/lsws" + + if os.path.exists(lsws_directory): + for dir_name in os.listdir(lsws_directory): + full_path = os.path.join(lsws_directory, dir_name) + if os.path.isdir(full_path) and dir_name.startswith("lsphp"): + php_version = dir_name.replace("lsphp", "PHP ").replace("", ".") + php_versions.append(php_version) + + result_list = [] + for item in sorted(php_versions): + # Use regular expression to find numbers in the string + numbers = re.findall(r'\d+', item) + + # Join the numbers with dots and add 'PHP' back to the string + result = 'PHP ' + '.'.join(numbers) + + result_list.append(result) + + return sorted(result_list) @staticmethod def getPHPString(phpVersion): diff --git a/plogical/test.py b/plogical/test.py index e69de29bb..d63776954 100644 --- a/plogical/test.py +++ b/plogical/test.py @@ -0,0 +1,30 @@ +import os + +def find_php_versions(): + import re + import os + php_versions = [] + lsws_directory = "/usr/local/lsws" + + if os.path.exists(lsws_directory): + for dir_name in os.listdir(lsws_directory): + full_path = os.path.join(lsws_directory, dir_name) + if os.path.isdir(full_path) and dir_name.startswith("lsphp"): + php_version = dir_name.replace("lsphp", "PHP ").replace("", ".") + php_versions.append(php_version) + + result_list = [] + for item in sorted(php_versions): + # Use regular expression to find numbers in the string + numbers = re.findall(r'\d+', item) + + # Join the numbers with dots and add 'PHP' back to the string + result = 'PHP ' + '.'.join(numbers) + + result_list.append(result) + + return result_list + +if __name__ == "__main__": + php_versions = find_php_versions() + print(php_versions)