????

Your IP : 3.15.25.254


Current Path : /usr/share/cloudlinux/
Upload File :
Current File : //usr/share/cloudlinux/plesk_sync_package_id

#!/opt/cloudlinux/venv/bin/python3 -bb
# coding=utf-8
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2022 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT

from sys import exit

import cldetectlib
import clcontrollib
from clveconfig import ve_config


def main() -> None:
    panel = clcontrollib.Plesk()
    packages = panel.list_domain_packages_with_id()     # reseller, package, id
    packages = {(x[0], x[1]): x[2] for x in packages}   # Dict[Tuple[str, str], int]
    xconfig, _ = ve_config.get_xml_config(use_cache=False)
    for el in xconfig.getElementsByTagName('package'):
        if el.getAttribute('plesk_id'):
            continue    # ignore packages with ids set
        name = el.getAttribute('id')
        res = el.getAttribute('reseller') or 'root'     # admin's packages in plesk has no reseller attr
        package_id = packages.get((res, name))
        if package_id:
            el.setAttribute('plesk_id', str(package_id))
    ve_config.save_xml(xconfig)


if __name__ == '__main__':
    if cldetectlib.is_plesk():
        main()
    else:
        print('Should be run only with the plesk panel')
    exit(0)