#!/usr/bin/env python3
import sys
from subprocess import call

try:
    import pkg_resources
except ImportError as err:
    import sys

    print(err)
    sys.exit(1)


def colorcode(code: int) -> str:
    return "\033[" + str(code) + "m"


GREEN = colorcode(32)
BOLD = colorcode(1)
RESET = colorcode(0)


print(f"{BOLD}==> Collecting packages...{RESET}")
packages = [dist.project_name for dist in pkg_resources.working_set]
print(f"{GREEN}✓ Collected {len(packages)} packages.{RESET}")

for pkg in packages:
    print(f"\n{BOLD}==> Upgrading {pkg}...{RESET}")
    call(f"pip install --upgrade {pkg}", shell=True)
