package manager support for cent7

This commit is contained in:
Usman Nasir
2020-05-06 00:25:46 +05:00
parent 1cfb65bdd9
commit 841a42c5ef
2 changed files with 133 additions and 41 deletions

View File

@@ -67,6 +67,8 @@ class ApplicationInstaller(multi.Thread):
f = open(ServerStatusUtil.lswsInstallStatusPath, 'a') f = open(ServerStatusUtil.lswsInstallStatusPath, 'a')
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
if package == 'all': if package == 'all':
command = 'apt-get update -y' command = 'apt-get update -y'
f.write(ProcessUtilities.outputExecutioner(command)) f.write(ProcessUtilities.outputExecutioner(command))
@@ -80,6 +82,11 @@ class ApplicationInstaller(multi.Thread):
f.write(ProcessUtilities.outputExecutioner(command)) f.write(ProcessUtilities.outputExecutioner(command))
f.close() f.close()
elif ProcessUtilities.decideDistro() == ProcessUtilities.centos:
command = 'yum update %s -y' % (package)
f.write(ProcessUtilities.outputExecutioner(command))
f.close()
logging.statusWriter(ServerStatusUtil.lswsInstallStatusPath, logging.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
'Package(s) upgraded successfully. [200]', 'Package(s) upgraded successfully. [200]',

View File

@@ -753,6 +753,59 @@ def fetchPackages(request):
upgradePackages.append(pack) upgradePackages.append(pack)
packages = upgradePackages 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): #if os.path.exists(ProcessUtilities.debugPath):
@@ -773,6 +826,7 @@ def fetchPackages(request):
import re import re
for items in finalPackages: for items in finalPackages:
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
try: try:
if type == 'CyberPanel': if type == 'CyberPanel':
@@ -815,9 +869,37 @@ def fetchPackages(request):
checker = 1 checker = 1
else: else:
json_data = json_data + ',' + json.dumps(dic) json_data = json_data + ',' + json.dumps(dic)
except BaseException as msg: except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile('[ERROR] %s. [fetchPackages:773]' % (str(msg))) logging.CyberCPLogFileWriter.writeToFile('[ERROR] %s. [fetchPackages:773]' % (str(msg)))
elif ProcessUtilities.decideDistro() == ProcessUtilities.centos:
try:
if type == 'installed' or type == 'upgrade':
details = items.split(' ')
details = [a for a in details if a != '']
if type == 'installed':
if details[0] in updateNeeded:
upgrade = 'Upgrade available'
else:
upgrade = 'Not needed.'
else:
upgrade = 'Upgrade available'
dic = {'package': details[0],
'version': details[1],
'upgrade': upgrade, 'lock': 1}
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 + ']' json_data = json_data + ']'
@@ -847,6 +929,9 @@ def fetchPackageDetails(request):
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu: if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
command = 'apt-cache show %s' % (package) command = 'apt-cache show %s' % (package)
packageDetails = ProcessUtilities.outputExecutioner(command) packageDetails = ProcessUtilities.outputExecutioner(command)
elif ProcessUtilities.decideDistro() == ProcessUtilities.centos:
command = 'yum info %s' % (package)
packageDetails = ProcessUtilities.outputExecutioner(command)
data_ret = {'status': 1, 'packageDetails': packageDetails} data_ret = {'status': 1, 'packageDetails': packageDetails}
json_data = json.dumps(data_ret) json_data = json.dumps(data_ret)