2017-10-24 19:16:36 +05:00
|
|
|
import pexpect
|
|
|
|
|
import CyberCPLogFileWriter as logging
|
|
|
|
|
import subprocess
|
|
|
|
|
import shlex
|
|
|
|
|
import thread
|
|
|
|
|
|
|
|
|
|
class phpUtilities:
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def installPHPExtension(extension,extensions):
|
|
|
|
|
try:
|
|
|
|
|
|
2017-11-05 03:02:51 +05:00
|
|
|
command = 'sudo yum install '+extension +' -y'
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
cmd = shlex.split(command)
|
|
|
|
|
|
2017-11-09 00:35:52 +05:00
|
|
|
with open('/usr/local/CyberCP/managePHP/phpExtensionRequestLog', 'w') as f:
|
2017-10-24 19:16:36 +05:00
|
|
|
res = subprocess.call(cmd, stdout=f)
|
|
|
|
|
|
|
|
|
|
if res == 1:
|
2017-11-09 00:35:52 +05:00
|
|
|
writeToFile = open('/usr/local/CyberCP/managePHP/phpExtensionRequestLog', 'a')
|
2017-10-24 19:16:36 +05:00
|
|
|
writeToFile.writelines("Can not be installed.\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile("[Could not Install]")
|
|
|
|
|
return 0
|
|
|
|
|
else:
|
2017-11-09 00:35:52 +05:00
|
|
|
writeToFile = open('/usr/local/CyberCP/managePHP/phpExtensionRequestLog', 'a')
|
2017-10-24 19:16:36 +05:00
|
|
|
writeToFile.writelines("PHP Extension Installed.\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installPHPExtension]")
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def unInstallPHPExtension(extension,extensions):
|
|
|
|
|
try:
|
|
|
|
|
|
2017-11-05 03:02:51 +05:00
|
|
|
command = 'sudo rpm --nodeps -e ' + extension + ' -v'
|
2017-10-24 19:16:36 +05:00
|
|
|
|
|
|
|
|
cmd = shlex.split(command)
|
|
|
|
|
|
2017-11-09 00:35:52 +05:00
|
|
|
with open('/usr/local/CyberCP/managePHP/phpExtensionRequestLog', 'w') as f:
|
2017-10-24 19:16:36 +05:00
|
|
|
res = subprocess.call(cmd, stdout=f)
|
|
|
|
|
|
|
|
|
|
if res == 1:
|
2017-11-09 00:35:52 +05:00
|
|
|
writeToFile = open('/usr/local/CyberCP/managePHP/phpExtensionRequestLog', 'a')
|
2017-10-24 19:16:36 +05:00
|
|
|
writeToFile.writelines("Can not un-install Extension.\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile("[Could not Install]")
|
|
|
|
|
return 0
|
|
|
|
|
else:
|
2017-11-09 00:35:52 +05:00
|
|
|
writeToFile = open('/usr/local/CyberCP/managePHP/phpExtensionRequestLog', 'a')
|
2017-10-24 19:16:36 +05:00
|
|
|
writeToFile.writelines("PHP Extension Removed.\n")
|
|
|
|
|
writeToFile.close()
|
|
|
|
|
|
|
|
|
|
return 1
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[unInstallPHPExtension]")
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def initiateInstall(extension):
|
|
|
|
|
try:
|
|
|
|
|
thread.start_new_thread(phpUtilities.installPHPExtension, (extension, extension))
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateInstall]")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def initiateRemoval(extension):
|
|
|
|
|
try:
|
|
|
|
|
thread.start_new_thread(phpUtilities.unInstallPHPExtension, (extension, extension))
|
|
|
|
|
except BaseException, msg:
|
|
|
|
|
logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]")
|