# 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 progSpec
import os
import subprocess
import buildAndroid
import buildMac
import errno
import shutil
import checkSys
import environmentMngr as emgr
    import urllib.request
from progSpec import cdlog, cdErr
from pathlib import Path
    from git import Repo


def downloadExtractZip(downloadUrl, packageName, packageDirectory):
    zipExtension = ""
    if downloadUrl.endswith(".zip"):
        zipExtension = ".zip"
    elif downloadUrl.endswith(".tar.gz"):
        zipExtension = ".tar.gz"
    elif downloadUrl.endswith(".tar.bz2"):
        zipExtension = ".tar.bz2"
    elif downloadUrl.endswith(".tar.xz"):
        zipExtension = ".tar.xz"
    elif downloadUrl.endswith(".tar"):
        zipExtension = ".tar"
    else:
        pass

    zipFileDirectory = packageDirectory + '/' + packageName
    innerPackageName = packageName     # TODO: get actual innerPackageName
    innerPackageDir  = zipFileDirectory + '/' + innerPackageName
    packagePath = zipFileDirectory + '/' + packageName + zipExtension
    checkDirectory = os.path.isdir(zipFileDirectory)
    zipFileName = os.path.basename(downloadUrl)
    if not checkDirectory:
        makeDirs(zipFileDirectory + "/INSTALL")
        emgr.downloadFile(packagePath, downloadUrl)
        try:
            cdlog(1, "Extracting zip file: " + zipFileName)
            shutil.unpack_archive(packagePath, zipFileDirectory)
        except:

# 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: buildDog.py
import progSpec
import os
import subprocess
import buildAndroid
import buildMac
import errno
import shutil
import checkSys
import environmentMngr as emgr
    import urllib.request
from progSpec import cdlog, cdErr
from pathlib import Path
    from git import Repo



def downloadExtractZip(downloadUrl, packageName, packageDirectory):
    zipExtension = ""
    if downloadUrl.endswith(".zip"):
        zipExtension = ".zip"
    elif downloadUrl.endswith(".tar.gz"):
        zipExtension = ".tar.gz"
    elif downloadUrl.endswith(".tar.bz2"):
        zipExtension = ".tar.bz2"
    elif downloadUrl.endswith(".tar.xz"):
        zipExtension = ".tar.xz"
    elif downloadUrl.endswith(".tar"):
        zipExtension = ".tar"
    else:
        pass

    zipFileDirectory = packageDirectory + '/' + packageName
    innerPackageName = packageName     # TODO: get actual innerPackageName
    innerPackageDir  = zipFileDirectory + '/' + innerPackageName
    packagePath = zipFileDirectory + '/' + packageName + zipExtension
    checkDirectory = os.path.isdir(zipFileDirectory)
    zipFileName = os.path.basename(downloadUrl)
    if not checkDirectory:
        makeDirs(zipFileDirectory + "/INSTALL")
        emgr.downloadFile(packagePath, downloadUrl)
        try:
            cdlog(1, "Extracting zip file: " + zipFileName)
            shutil.unpack_archive(packagePath, zipFileDirectory)
        except:

            cdErr("Could not extract zip archive file: " + zipFileName)