示例#1
0
def load_env(cmd):
    """Runs a cmd and loads the environment variables it sets"""
    log.info("Loading environment variables from " + cmd)
    variables = subprocess.check_output(cmd + ' && set')
    for var in variables.splitlines():
        var = var.decode('cp1252') # FIXME: This works on (German?) Windows only
        k, _, val = [x.strip() for x in var.strip().partition('=')]
        if k.startswith('?') or k == '':
            continue
        os.environ[k] = val
示例#2
0
def rmdir(directory):
    """Removes a directory with multiple tries. On Windows this is needed, because read access by a
    random program causes a remove operation to fail."""
    log.info("Removing directory " + directory)
    tries = 0
    while True:
        try:
            shutil.rmtree(directory)
            return
        except PermissionError as err:
            tries += 1
            if tries > 100:
                raise err
            else:
                time.sleep(0.01)