# Path: progSpec.py
# def cdlog(lvl, mesg):
#     global MaxLogLevelToShow
#     global lastLogMesgs
#     global highestLvl
#     highestLvl=lvl
#     resizeLogArray(lvl)
#     lastLogMesgs[lvl]=mesg
#     for i in range(highestLvl+1, len(lastLogMesgs)):
#         lastLogMesgs[i]=''
#     if(lvl<=MaxLogLevelToShow):
#         if(lvl==0): print('')
#         printAtLvl(lvl, mesg, '|    ')
# 
# def cdErr(mesg):
#     global lastLogMesgs
#     global highestLvl
#     highestLvl+=1
#     lastLogMesgs[highestLvl]="\n\nError: "+mesg
#     exit(1)


import os
import subprocess
import checkSys
    import urllib3
from progSpec import cdlog, cdErr
    from sys import platform
        elif ipm == 'pacman':
            if packageInstalled("sudo pacman -S", packageName):
                break
        elif ipm == 'dnf':
            if packageInstalled("sudo dnf install", packageName):
                break
        elif ipm == 'emerge':
            if packageInstalled("sudo emerge -pv", packageName):
                break
        elif ipm == 'zypper':
            if packageInstalled("sudo zypper install", packageName):
                break
        elif ipm == 'brew':
            if packageInstalled("brew install --cask", packageName):
                break


def checkAndUpgradeOSPackageVersions(packageName):
    cdlog(1, f"Searching for package: {packageName}")
    installedPackage = os.popen(f'apt-cache policy {packageName} | grep Installed')
    if installedPackage.read():
        installedPackage = os.popen(f'apt-cache policy {packageName} | grep Installed')
        candidatePackage = os.popen(f'apt-cache policy {packageName} | grep Candidate')
        installedVersion = installedPackage.read().split(" ")[-1].replace('\n','')
        candidateVersion = candidatePackage.read().split(" ")[-1].replace('\n','')
        cdlog(1, f"Candidate Package available: {candidateVersion}")
        if installedVersion or installedVersion == '(none)':
            if installedVersion != candidateVersion:
                getPackageManagerCMD(packageName, findPackageManager())
            else:

# Path: progSpec.py
# def cdlog(lvl, mesg):
#     global MaxLogLevelToShow
#     global lastLogMesgs
#     global highestLvl
#     highestLvl=lvl
#     resizeLogArray(lvl)
#     lastLogMesgs[lvl]=mesg
#     for i in range(highestLvl+1, len(lastLogMesgs)):
#         lastLogMesgs[i]=''
#     if(lvl<=MaxLogLevelToShow):
#         if(lvl==0): print('')
#         printAtLvl(lvl, mesg, '|    ')
# 
# def cdErr(mesg):
#     global lastLogMesgs
#     global highestLvl
#     highestLvl+=1
#     lastLogMesgs[highestLvl]="\n\nError: "+mesg
#     exit(1)


# Path: environmentMngr.py
import os
import subprocess
import checkSys
    import urllib3
from progSpec import cdlog, cdErr
    from sys import platform

        elif ipm == 'pacman':
            if packageInstalled("sudo pacman -S", packageName):
                break
        elif ipm == 'dnf':
            if packageInstalled("sudo dnf install", packageName):
                break
        elif ipm == 'emerge':
            if packageInstalled("sudo emerge -pv", packageName):
                break
        elif ipm == 'zypper':
            if packageInstalled("sudo zypper install", packageName):
                break
        elif ipm == 'brew':
            if packageInstalled("brew install --cask", packageName):
                break


def checkAndUpgradeOSPackageVersions(packageName):
    cdlog(1, f"Searching for package: {packageName}")
    installedPackage = os.popen(f'apt-cache policy {packageName} | grep Installed')
    if installedPackage.read():
        installedPackage = os.popen(f'apt-cache policy {packageName} | grep Installed')
        candidatePackage = os.popen(f'apt-cache policy {packageName} | grep Candidate')
        installedVersion = installedPackage.read().split(" ")[-1].replace('\n','')
        candidateVersion = candidatePackage.read().split(" ")[-1].replace('\n','')
        cdlog(1, f"Candidate Package available: {candidateVersion}")
        if installedVersion or installedVersion == '(none)':
            if installedVersion != candidateVersion:
                getPackageManagerCMD(packageName, findPackageManager())
            else:

                cdlog(1, f"Package already Installed: {packageName}")