/usr/share/l.v.e-manager/utils
#!/opt/cloudlinux/venv/bin/python3 # 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 copy import argparse import os import json BASE_DIR = os.path.join(os.path.dirname(__file__), "../") USER_LOCALES_SOURCE = '/usr/share/l.v.e-locales/' MAP = { 'cPanel': BASE_DIR + 'cpanel/spa/assets/i18n', 'Plesk': BASE_DIR + 'plesk/htdocs/modules/plesk-lvemanager/i18n/', 'DirectAdmin': BASE_DIR + 'directadmin/lvemanager_spa/images/assets/i18n/', } I18N_SOURCE = BASE_DIR + 'commons/spa-resources/i18n/' def main(): """ Analyze arguments and merge locale files :return: """ parser = argparse.ArgumentParser( description='Convert yaml locales to json') parser.add_argument( '--panel', '-p', type=str, help="The target control panel" ) args = parser.parse_args() if not os.path.isdir(USER_LOCALES_SOURCE): return panel_path = MAP.get(args.panel, I18N_SOURCE) for locale in available_locales(USER_LOCALES_SOURCE): user_locale = read_locale_json(USER_LOCALES_SOURCE, locale) current_locale = read_locale_json(I18N_SOURCE, locale) if current_locale: current_locale = nested_merge(copy.deepcopy(current_locale), user_locale) write_locale_json(panel_path, locale, current_locale) def available_locales(path): """ Get list of locales in directory :param path: directory with locales :return: list of locales """ for locale in os.listdir(path): filename = '{}/{}'.format(path, locale) if os.path.isfile(filename) and filename.endswith('.json'): yield locale.split('.')[0] def read_locale_json(path, locale): """ read locale from directory :param path: directory with locales :param locale: locale (en, etc) :return: locale data """ filename = '{}/{}.json'.format(path, locale) if os.path.isfile(filename): with open(filename, 'r') as f: return json.load(f) def write_locale_json(path, locale, data): """ Save json into file :param path: directory with locales :param locale: locale (en, etc) :param data: locale dict :return: """ with open('{}/{}.json'.format(path, locale), 'w') as f: return json.dump(data, f, indent=4) def nested_merge(a, b, path=None): """ Merger a into b :param a: dict :param b: dict :return: merger dict """ path = path or [] for key in b: if key in a: if isinstance(a[key], dict) and isinstance(b[key], dict): nested_merge(a[key], b[key], path + [str(key)]) else: a[key] = b[key] else: a[key] = b[key] return a if __name__ == '__main__': main()
.
Edit
..
Edit
__pycache__
Edit
activate
Edit
autorestore.py
Edit
cache_phpdata.py
Edit
cache_rubygems.py
Edit
clinfo.php
Edit
cloudlinux-awp-installer.py
Edit
cloudlinux-cli-user.py
Edit
cloudlinux-cli.py
Edit
cloudlinux-selector.py
Edit
cloudlinux-xray.py
Edit
cloudlinux_cli.py
Edit
cloudlinux_cli_user.py
Edit
cpanel_api.py
Edit
create_translate_template.py
Edit
delete-isp-plugin.sh
Edit
delete-plesk-plugin.sh
Edit
downgrades
Edit
dynamicui.py
Edit
dynamicui_base.py
Edit
dynamicui_cpanel.py
Edit
dynamicui_da.py
Edit
dynamicui_plesk.py
Edit
fix-nodejs-environments.py
Edit
generate_locale_files_for_plesk.py
Edit
install-cpanel-plugin.sh
Edit
install-plesk-plugin.sh
Edit
installsupergrp.sh
Edit
libcagefs.py
Edit
libcloudlinux.py
Edit
libsupport.py
Edit
node_wrapper
Edit
npm_wrapper
Edit
plesk-cgi.sh
Edit
python_wrapper
Edit
set_env_vars.py
Edit
sync_locales.py
Edit
ui_package_installer.py
Edit