def wgetFile(url, destdir, filename, quiet):
    "download file with wget from 'url' into 'destdir', if filename is given to the file specified"
    wget = CraftCore.cache.findApplication('wget')
    command = [wget, '-c', '-t', '10']
    cert = os.path.join(CraftCore.standardDirs.etcDir(), 'cacert.pem')
    if os.path.exists(cert):
        command += ['--ca-certificate', cert]
    command += ['--max-redirect', '50']
    if CraftCore.settings.getboolean('General', 'EMERGE_NO_PASSIVE_FTP', False):
        command += ['--no-passive-ftp']
    if (not filename):
        command += ['-P', destdir]
    else:
        command += ['-O', os.path.join(destdir, filename)]
    command += [url]
    if (CraftCore.debug.verbose() < 1):
        if quiet:
            with io.StringIO() as tmp:
                ciMode = CraftCore.settings.getboolean('ContinuousIntegration', 'Enabled', False)
                if (not utils.system(command, logCommand=ciMode, stdout=tmp, stderr=subprocess.STDOUT)):
                    CraftCore.log.warning(tmp.getvalue())
                    return False
                if ciMode:
                    loc = re.findall('Location: ([^\\s]+)', tmp.getvalue())
                    if loc:
                        CraftCore.log.info(f'Downloaded from: {loc[(- 1)]}')
                return True
        elif CraftCore.cache.checkCommandOutputFor(wget, '--show-progress'):
            command += ['-q', '--show-progress']
            CraftCore.log.info(f'wget {url}')
            return utils.system(command, displayProgress=True, logCommand=False, stderr=subprocess.STDOUT)
    return utils.system(command)
download file with wget from 'url' into 'destdir', if filename is given to the file specified
def wgetFile(url, destdir, filename, quiet):
    
    wget = CraftCore.cache.findApplication('wget')
    command = [wget, '-c', '-t', '10']
    cert = os.path.join(CraftCore.standardDirs.etcDir(), 'cacert.pem')
    if os.path.exists(cert):
        command += ['--ca-certificate', cert]
    command += ['--max-redirect', '50']
    if CraftCore.settings.getboolean('General', 'EMERGE_NO_PASSIVE_FTP', False):
        command += ['--no-passive-ftp']
    if (not filename):
        command += ['-P', destdir]
    else:
        command += ['-O', os.path.join(destdir, filename)]
    command += [url]
    if (CraftCore.debug.verbose() < 1):
        if quiet:
            with io.StringIO() as tmp:
                ciMode = CraftCore.settings.getboolean('ContinuousIntegration', 'Enabled', False)
                if (not utils.system(command, logCommand=ciMode, stdout=tmp, stderr=subprocess.STDOUT)):
                    CraftCore.log.warning(tmp.getvalue())
                    return False
                if ciMode:
                    loc = re.findall('Location: ([^\\s]+)', tmp.getvalue())
                    if loc:
                        CraftCore.log.info(f'Downloaded from: {loc[(- 1)]}')
                return True
        elif CraftCore.cache.checkCommandOutputFor(wget, '--show-progress'):
            command += ['-q', '--show-progress']
            CraftCore.log.info(f'wget {url}')
            return utils.system(command, displayProgress=True, logCommand=False, stderr=subprocess.STDOUT)
    return utils.system(command)