Mini Shell
#!/opt/cloudlinux/venv/bin/python3 -bb
# 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 sys
from future.utils import iteritems
from clcommon.clpwd import ClPwd
from clselect.clselectctlnodejsuser import _create_environment
from clselect.clselectexcept import ClSelectExcept
from clselect.clselectnodejs import scan_node_versions
from clselect.clselectnodejs.apps_manager import ApplicationsManager
WRAPPERS_VERSION_FILE = '/usr/share/l.v.e-manager/utils/nodejs_selector_wrappers_version'
# Increment when introducing incompatible changes to nodejs virtualenv
LAST_WRAPPERS_VERSION = 1
def is_alt_nodejs_installed():
return scan_node_versions() != {}
def get_wrappers_version():
"""
Return the version of wrappers used in existing apps
:rtype: int or None
"""
try:
with open(WRAPPERS_VERSION_FILE, 'r') as f:
version = f.read()
except (IOError, OSError):
return None
else:
try:
return int(version)
except ValueError:
return None
def set_wrappers_version(wrappers_version=LAST_WRAPPERS_VERSION):
"""
Save the last wrappers version introducing incompatibility
:rtype: None
"""
try:
with open(WRAPPERS_VERSION_FILE, 'w') as f:
f.write("{}".format(wrappers_version))
except (IOError, OSError):
pass
def main():
if not is_alt_nodejs_installed():
sys.exit(0)
current_version = get_wrappers_version()
if current_version is not None and current_version >= LAST_WRAPPERS_VERSION:
sys.exit(0)
clpwd = ClPwd()
clpwd.get_user_dict()
users = clpwd.get_user_dict()
apps_manager = ApplicationsManager()
for user in users:
try:
user_config = apps_manager.get_user_config_data(user)
except ClSelectExcept.WrongData:
pass
for approot, app_info in iteritems(user_config):
try:
_create_environment(user, approot, app_info['nodejs_version'], destroy_first=True)
except ClSelectExcept.NoSuchAlternativeVersion:
continue
set_wrappers_version(LAST_WRAPPERS_VERSION)
if __name__ == "__main__":
main()
sys.exit(0)
Zerion Mini Shell 1.0