Exemplo n.º 1
0
def get_ls_color_codes():
    if "LS_COLORS" not in os.environ:
        script = os.path.join(os.path.dirname(__file__), "LS_COLORS.sh")
        with open(script) as file_:
            codes = file_.readline().strip()[len("LS_COLORS='"):-len("';")]
            os.environ["LS_COLORS"] = codes
    return lscolors.get_color_codes(os.environ)
Exemplo n.º 2
0
def test_against_ls(root_path, environment):
    process = subprocess.Popen(
        ["ls", "--color=always", "-R", root_path],
        stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environment)
    stdout, stderr = process.communicate()
    color_codes = lscolors.get_color_codes(environment)
    for line in stdout.splitlines():
        line = line.strip()
        if line == "":
            continue
        if line.endswith(":"):
            current_directory = line[:-1]
            continue
        ls_color_code, filename = parse_ls_line(line)
        path = os.path.join(current_directory, filename)
        if os.path.exists(path):  # Some paths are already gone. e.g. in /proc
            color_code = lscolors.color_code_for_path(path, color_codes)
            if color_code != ls_color_code:
                print "%s %r %r" % (path, color_code, ls_color_code)