예제 #1
0
    def list_files_under(self, dir, recursively=False, vroot=None):
        # _really_ simple-minded ..
        result = []
        for f in self.file_list:
            d = dir

            # Remove any common prefix
            while d and f:
                ld, restd = utils.split_path_left(d)
                fd, restf = utils.split_path_left(f)
                if ld != fd:
                    break
                d, f = restd, restf

            if d:  # We don't actually start with 'dir'
                continue

            if not f:  # We *were* 'dir'
                continue

            if recursively:
                result.append(f)
            else:
                if f.find("/") == -1:
                    # Yep
                    result.append(f)

        return result
예제 #2
0
def utils_unit_test():
    """
    Unit testing on various utility code.
    """

    s = utils.c_escape("Hello World!")
    assert s == "Hello World!"

    s = utils.c_escape("Test \" \\ One")

    assert s == "Test \\\" \\\\ One"

    s = utils.pad_to("0123456789", 11)
    assert s == "0123456789 "

    s = utils.pad_to("0123456789", 8)
    assert s == "0123456789"

    s = utils.pad_to("0", 10, "z")
    assert s == "0zzzzzzzzz"

    s = utils.split_path_left("a/b/c")

    assert s == ("a", "b/c")

    s = utils.split_path_left("/a/b/c")
    assert s == ("", "a/b/c")

    s = utils.replace_root_name("/a", "/b", "/a/c")
    assert s == "/b/c"

    s = utils.replace_root_name("/a", "/b", "/d/e")
    assert s == "/d/e"
예제 #3
0
def utils_unit_test():
    """
    Unit testing on various utility code.
    """

    s = utils.c_escape("Hello World!")
    assert s == "Hello World!"

    s = utils.c_escape("Test \" \\ One")

    assert s == "Test \\\" \\\\ One"

    s = utils.pad_to("0123456789", 11)
    assert s == "0123456789 "

    s = utils.pad_to("0123456789", 8)
    assert s == "0123456789"

    s = utils.pad_to("0", 10, "z")
    assert s == "0zzzzzzzzz"

    s = utils.split_path_left("a/b/c")

    assert s == ("a", "b/c")

    s = utils.split_path_left("/a/b/c")
    assert s == ("", "a/b/c")

    s = utils.replace_root_name("/a", "/b", "/a/c")
    assert s == "/b/c"

    s = utils.replace_root_name("/a", "/b", "/d/e")
    assert s == "/d/e"
예제 #4
0
    def list_files_under(self, dir, recursively=False, vroot=None):
        # _really_ simple-minded ..
        result = []
        for f in self.file_list:
            d = dir

            # Remove any common prefix
            while d and f:
                ld, restd = utils.split_path_left(d)
                fd, restf = utils.split_path_left(f)
                if ld != fd:
                    break
                d, f = restd, restf

            if d:  # We don't actually start with 'dir'
                continue

            if not f:  # We *were* 'dir'
                continue

            if recursively:
                result.append(f)
            else:
                if f.find("/") == -1:
                    # Yep
                    result.append(f)

        return result