#!/usr/bin/python3

import subprocess
import sys
import time

argv = sys.argv
last_string = f'\n\033[91mДля более подробной информации наберите команду "справка apt"\033[0m'

print('\033[91mapt больше не поддерживается. Используйте dnf:\033[0m')
if len(argv) > 1:
    if 'install' in argv or 'search' in argv or 'remove' in argv or 'reinstall' in argv:
        argv[0] = 'dnf'
        command = ' '.join(argv)
        print(f'\033[32m{command}\033[0m{last_string}')
        time.sleep(1)
        subprocess.run(argv)
    elif 'update' in argv:
        print(f'\033[32mdnf --refresh makecache\033[0m{last_string}')
        time.sleep(1)
        subprocess.run(['dnf', '--refresh', 'makecache'])
    elif 'dist-upgrade' in argv and '-y' not in argv:
        print(f'\033[32mdnf --refresh upgrade\033[0m{last_string}')
        time.sleep(1)
        subprocess.run(['dnf', '--refresh', 'upgrade'])
    elif 'dist-upgrade' in argv and '-y' in argv:
        print(f'\033[32mdnf --refresh -y upgrade\033[0m{last_string}')
        time.sleep(1)
        subprocess.run(['dnf', '--refresh', '-y', 'upgrade'])
    else:
        print(f'\033[91mВ apt нет такой команды. Вы могли бы вызвать её так:\033[0m')
        argv[0] = 'dnf'
        command = ' '.join(argv)
        print(f'\033[32m{command}\033[0m{last_string}')
        time.sleep(1)
        subprocess.run(argv)
elif 'apt-repo' in argv[0]:
    print(f'\033[32mdnf repolist\033[0m{last_string}')
    time.sleep(1)
    subprocess.run(['dnf', 'repolist'])
else:
    print(f'\033[91mВ apt нет такой команды. Вы могли бы вызвать её так:\033[0m')
    argv[0] = 'dnf'
    command = ' '.join(argv)
    print(f'\033[32m{command}\033[0m{last_string}')
    time.sleep(1)
    subprocess.run(argv)
