Sindbad~EG File Manager
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2018 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# https://cloudlinux.com/docs/LICENCE.TXT
#
from __future__ import absolute_import
import logging
import os
import re
from clconfigure import task, run
STATE_REMOVED = 'uninstalled'
STATE_INSTALLED = 'installed'
_PACKAGE_NOT_INSTALLED = 'is not installed'
@task("Changing package '{package_name}' state to '{desired_state}'")
def set_package_state(desired_state, package_name):
"""
Brings package to given state (installed | uninstalled). May be executed more that once,
does't crash on future calls
"""
current_state = _get_package_state(package_name)
logging.debug("Checking package '%s' state... package is in state '%s'", package_name, current_state)
if desired_state == current_state:
logging.debug("No actions needed for package '%s'", package_name)
return
logging.info('State does not match target, changing...')
if desired_state == STATE_REMOVED:
action = 'remove'
elif desired_state == STATE_INSTALLED:
action = 'install'
else:
raise NotImplementedError()
run(['yum', action, '-y', package_name])
current_state = _get_package_state(package_name)
logging.info("Checking package '%s' state again... package is now in state '%s'", package_name, current_state)
if desired_state != current_state:
raise RuntimeError("Failed to do required actions")
def _get_package_state(package):
"""
Gets current package state.
Either installed or uninstalled.
"""
resp = run(['rpm', '-q', package])
if _PACKAGE_NOT_INSTALLED in resp.stdout:
return STATE_REMOVED
elif resp.exitcode == 0:
return STATE_INSTALLED
raise RuntimeError('Unknown package %s status' % package)
def get_list_installed_alt_phps():
"""
Gets installed alt-phps
return: list ['php44', 'php54', 'php80']
"""
return [php for php in os.listdir('/opt/alt') if re.match(r'^php\d+$', php)]
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists