From 841a42c5ef113e4842401fa3fc094d58ec015a39 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Wed, 6 May 2020 00:25:46 +0500 Subject: [PATCH] package manager support for cent7 --- plogical/applicationInstaller.py | 23 +++-- serverStatus/views.py | 151 ++++++++++++++++++++++++------- 2 files changed, 133 insertions(+), 41 deletions(-) diff --git a/plogical/applicationInstaller.py b/plogical/applicationInstaller.py index 5063926d3..d46a49396 100755 --- a/plogical/applicationInstaller.py +++ b/plogical/applicationInstaller.py @@ -67,16 +67,23 @@ class ApplicationInstaller(multi.Thread): f = open(ServerStatusUtil.lswsInstallStatusPath, 'a') - if package == 'all': - command = 'apt-get update -y' - f.write(ProcessUtilities.outputExecutioner(command)) + if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: - f.flush() + if package == 'all': + command = 'apt-get update -y' + f.write(ProcessUtilities.outputExecutioner(command)) - command = 'apt-get upgrade -y' - f.write(ProcessUtilities.outputExecutioner(command)) - else: - command = 'apt-get install --only-upgrade %s -y' % (package) + f.flush() + + command = 'apt-get upgrade -y' + f.write(ProcessUtilities.outputExecutioner(command)) + else: + command = 'apt-get install --only-upgrade %s -y' % (package) + f.write(ProcessUtilities.outputExecutioner(command)) + + f.close() + elif ProcessUtilities.decideDistro() == ProcessUtilities.centos: + command = 'yum update %s -y' % (package) f.write(ProcessUtilities.outputExecutioner(command)) f.close() diff --git a/serverStatus/views.py b/serverStatus/views.py index fa3598713..9e7737919 100755 --- a/serverStatus/views.py +++ b/serverStatus/views.py @@ -753,6 +753,59 @@ def fetchPackages(request): upgradePackages.append(pack) packages = upgradePackages + elif ProcessUtilities.decideDistro() == ProcessUtilities.centos: + + if type == 'installed': + + #### Cater for packages that need updates. + + startForUpdate = 1 + + command = 'yum check-update' + updates = ProcessUtilities.outputExecutioner(command).split('\n') + + for items in updates: + if items == '': + updates = updates[startForUpdate:] + break + else: + startForUpdate = startForUpdate + 1 + + ## make list of packages that need update + + updateNeeded = [] + for items in updates: + updateNeeded.append(items.split(' ')[0]) + + ### + + command = 'yum list installed' + packages = ProcessUtilities.outputExecutioner(command).split('\n') + + startFrom = 1 + + for items in packages: + if items.find('Installed Packages') > -1: + packages = packages[startFrom:] + break + else: + startFrom = startFrom + 1 + elif type == 'upgrade': + #### Cater for packages that need updates. + + startForUpdate = 1 + + command = 'yum check-update' + packages = ProcessUtilities.outputExecutioner(command).split('\n') + + for items in packages: + if items == '': + packages = packages[startForUpdate:-1] + break + else: + startForUpdate = startForUpdate + 1 + + ## make list of packages that need update #if os.path.exists(ProcessUtilities.debugPath): @@ -773,51 +826,80 @@ def fetchPackages(request): import re for items in finalPackages: - try: - if type == 'CyberPanel': + if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: + try: + if type == 'CyberPanel': - packageName = items['Package'].split('/')[0] + packageName = items['Package'].split('/')[0] + + if packageName in locked: + lock = 1 + else: + lock = 0 + + dic = {'package': packageName, + 'version': items['Version'], 'lock': lock} + + counter = counter + 1 + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) - if packageName in locked: - lock = 1 else: - lock = 0 + nowSplitted = items.split('now') - dic = {'package': packageName, - 'version': items['Version'], 'lock': lock} + upgrade = 'Not Needed' - counter = counter + 1 - if checker == 0: - json_data = json_data + json.dumps(dic) - checker = 1 - else: - json_data = json_data + ',' + json.dumps(dic) + if nowSplitted[1].split(' ')[3].find('upgradable') > -1: + current = nowSplitted[1].split(' ') + upgrade = '%s %s %s' % (current[3], current[4], current[5]) - else: - nowSplitted = items.split('now') + if nowSplitted[0].split('/')[0] in locked: + lock = 1 + else: + lock = 0 - upgrade = 'Not Needed' + dic = {'package': nowSplitted[0].split('/')[0], 'version': '%s %s' % (nowSplitted[1].split(' ')[1], nowSplitted[1].split(' ')[2]), 'upgrade': upgrade, 'lock': lock} - if nowSplitted[1].split(' ')[3].find('upgradable') > -1: - current = nowSplitted[1].split(' ') - upgrade = '%s %s %s' % (current[3], current[4], current[5]) + counter = counter + 1 + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile('[ERROR] %s. [fetchPackages:773]' % (str(msg))) + elif ProcessUtilities.decideDistro() == ProcessUtilities.centos: + try: + if type == 'installed' or type == 'upgrade': - if nowSplitted[0].split('/')[0] in locked: - lock = 1 - else: - lock = 0 + details = items.split(' ') + details = [a for a in details if a != ''] - dic = {'package': nowSplitted[0].split('/')[0], 'version': '%s %s' % (nowSplitted[1].split(' ')[1], nowSplitted[1].split(' ')[2]), 'upgrade': upgrade, 'lock': lock} + if type == 'installed': + if details[0] in updateNeeded: + upgrade = 'Upgrade available' + else: + upgrade = 'Not needed.' + else: + upgrade = 'Upgrade available' - counter = counter + 1 - if checker == 0: - json_data = json_data + json.dumps(dic) - checker = 1 - else: - json_data = json_data + ',' + json.dumps(dic) + dic = {'package': details[0], + 'version': details[1], + 'upgrade': upgrade, 'lock': 1} - except BaseException as msg: - logging.CyberCPLogFileWriter.writeToFile('[ERROR] %s. [fetchPackages:773]' % (str(msg))) + counter = counter + 1 + if checker == 0: + json_data = json_data + json.dumps(dic) + checker = 1 + else: + json_data = json_data + ',' + json.dumps(dic) + + + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile('[ERROR] %s. [fetchPackages:839]' % (str(msg))) json_data = json_data + ']' @@ -847,6 +929,9 @@ def fetchPackageDetails(request): if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: command = 'apt-cache show %s' % (package) packageDetails = ProcessUtilities.outputExecutioner(command) + elif ProcessUtilities.decideDistro() == ProcessUtilities.centos: + command = 'yum info %s' % (package) + packageDetails = ProcessUtilities.outputExecutioner(command) data_ret = {'status': 1, 'packageDetails': packageDetails} json_data = json.dumps(data_ret)