Hacked By AnonymousFox

Current Path : /usr/share/l.v.e-manager/
Upload File :
Current File : //usr/share/l.v.e-manager/detect_edition_changes.py

#!/opt/cloudlinux/venv/bin/python3 -bb
# coding:utf-8

# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT

from __future__ import absolute_import
from feature_manager import cpanel_fix_feature_manager, cpanel_remove_from_feature_list
import cldetectlib as detect
from clcommon.lib.cledition import is_cl_shared_edition, get_cl_edition_readable

EDITION_CACHE_FILE = "/var/lve/cl_edition.cache"
DISABLED_FEATURES_FOR_SHARED = {
    "name_list": ["lvewpos"],
    "install_json_list": ["cpanel/wpos/plugin/install.json"]
}

def main():
    """
    Main
    :return: None
    """
    if detect.is_cpanel() and edition_changed():
        process_feature_list()
        return
    print('No action required')

def get_cl_edition_from_cache():
    """
    Red edition from cache file
    :return: String or None
    """
    try:
        with open(EDITION_CACHE_FILE, 'r') as f:
            return f.read()
    except Exception:
        return

def cache_cl_edition(edition):
    """
    Save edition to cache file
    :param edition:
    :return: None
    """
    try:
        with open(EDITION_CACHE_FILE, 'w') as f:
            return f.write(edition)
    except Exception as e:
        print("Cannot cache the edition: {}".format(str(e)))

def edition_changed():
    """
    Detect if edition changed
    :return: Boolean
    """
    current_edition = get_cl_edition_readable()
    cached_edition = get_cl_edition_from_cache()
    if current_edition != cached_edition:
        cache_cl_edition(current_edition)
        return True
    return False

def process_feature_list():
    """
    Fix feature list and disable unsupported features for Shared Edition
    :return: None
    """
    cpanel_fix_feature_manager(DISABLED_FEATURES_FOR_SHARED["install_json_list"])
    if is_cl_shared_edition():
        cpanel_remove_from_feature_list(DISABLED_FEATURES_FOR_SHARED["name_list"])

if __name__ == '__main__':
    main()

Hacked By AnonymousFox1.0, Coded By AnonymousFox