Mini Shell

Direktori : /usr/share/l.v.e-manager/utils/
Upload File :
Current File : //usr/share/l.v.e-manager/utils/dynamicui_da.py

# coding:utf-8

# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import os
import sys

from dynamicui_base import DynamicUIBase

sys.path.append(os.path.dirname(__file__))

from lvemanager.config_parser import SectionlessConfigParser
from clcommon.ui_config import UIConfig


class DynamicUIDA(DynamicUIBase):

    da_plugin_conf_file = '/usr/local/directadmin/plugins/{}/plugin.conf'.format

    def sync(self, plugin):
        if plugin == 'all':
            self.sync_nodejs()
            self.sync_python()
            self.sync_resource_usage()
            self.sync_xray()
            self.sync_awp()
        elif plugin == 'nodejs':
            self.sync_nodejs()
        elif plugin == 'python':
            self.sync_python()
        elif plugin == 'resource_usage':
            self.sync_resource_usage()
        elif plugin == 'xray':
            self.sync_xray()
        elif plugin == 'awp':
            self.sync_awp()

    def sync_nodejs(self):
        from clselect.clselectnodejs.node_manager import NodeManager
        self.set_plugin_active('nodejs_selector', NodeManager().selector_enabled)

    def sync_python(self):
        from clselect.clselectpython.python_manager import PythonManager
        self.set_plugin_active('python_selector', PythonManager().selector_enabled)

    def sync_resource_usage(self):
        try:
            self.set_plugin_active('resource_usage',
                                   UIConfig().get_param('hideLVEUserStat', 'uiSettings') is False)
        except IOError:
            return None

    def sync_xray(self):
        try:
            self.set_plugin_active('xray', UIConfig().get_param('hideXrayApp', 'uiSettings') is False)
        except IOError:
            return None

    def sync_awp(self):
        try:
            self.set_plugin_active('awp', UIConfig().get_param('hideAccelerateWPApp', 'uiSettings') is False)
        except IOError:
            return None

    def set_plugin_active(self, plugin_name, state):
        config = SectionlessConfigParser()
        config_file = self.da_plugin_conf_file(plugin_name)
        config.read(config_file)
        config.set('__config__', 'active', 'yes' if state else 'no')
        with open(config_file, 'w') as f:
            config.write(f)

Zerion Mini Shell 1.0