How to use the cget.util.BuildError function in cget

To help you get started, we’ve selected a few cget examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pfultz2 / cget / cget / util.py View on Github external
def which(p, paths=None, throws=True):
    exes = [p+x for x in ['', '.exe', '.bat']]
    for dirname in list(paths or [])+os.environ['PATH'].split(os.pathsep):
        for exe in exes:
            candidate = os.path.join(os.path.expanduser(dirname), exe)
            if os.path.isfile(candidate):
                return candidate
    if throws: raise BuildError("Can't find file %s" % p)
    else: return None
github pfultz2 / cget / cget / util.py View on Github external
def http_error_default(self, url, fp, errcode, errmsg, headers):
        if errcode >= 400:
            raise BuildError("Download failed with error {0} for: {1}".format(errcode, url))
        return request.FancyURLopener.http_error_default(self, url, fp, errcode, errmsg, headers)
github pfultz2 / cget / cget / util.py View on Github external
file = os.path.join(download_dir, name)
    click.echo("Downloading {0}".format(url))
    bar_len = 1000
    with click.progressbar(length=bar_len, width=70) as bar:
        def hook(count, block_size, total_size):
            percent = int(count*block_size*bar_len/total_size)
            if percent > 0 and percent < bar_len:
                # Hack because we can't set the position
                bar.pos = percent
                bar.update(0)
        context = None
        if insecure: context = ssl._create_unverified_context()
        CGetURLOpener(context=context).retrieve(url, filename=file, reporthook=hook, data=None)
        bar.update(bar_len)
    if not os.path.exists(file):
        raise BuildError("Download failed for: {0}".format(url))
    return file
github pfultz2 / cget / cget / prefix.py View on Github external
def check(self, f, *args):
        if self.verbose and not f(*args):
            raise util.BuildError('ASSERTION FAILURE: ', ' '.join([str(arg) for arg in args]))
github pfultz2 / cget / cget / util.py View on Github external
def cmd(args, env=None, capture=None, **kwargs):
    e = merge(os.environ, env)
    c = capture or ''
    stdout = None
    stderr = None
    if c == 'out' or c == 'all': stdout = subprocess.PIPE
    if c == 'err' or c == 'all': stderr = subprocess.PIPE
    child = subprocess.Popen(args, stdout=stdout, stderr=stderr, env=e, **kwargs)
    out = child.communicate()
    if child.returncode != 0:
        raise BuildError(msg='Command failed: ' + str(args), data=e)
    return out