Beispiel #1
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"
Beispiel #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"
Beispiel #3
0
def hierarchy_from_fs(name, base_name):
    """
    Create a hierarchy of files from a named object in the
    filesystem.

    The files will be named with 'base_name' substituted for 'name'.

    Returns a Hierarchy with everything filled in.
    """

    # A map of filename to file object, so you can find 'em eas
    file_map = { }

    # Add the root ..
    file_map[base_name] = file_from_fs(name,
                                  base_name)

    # Same as file_map, but indexed by the name in the fs rather
    # than in the resulting archive - used to find directories
    # quickly.
    by_tgt_map = { }

    by_tgt_map[name] = file_map[base_name]

    the_paths = os.walk(name)
    for p in the_paths:
        (root, dirs, files) = p

        # This is legit - top-down means that root must have been
        # visited first. If it isn't, our ordering will collapse
        # and the cpio archive when we generate it will at the
        # least be extremely odd.
        #
        root_file = by_tgt_map[root]

        for d in dirs:
            new_obj = os.path.join(root, d)
            # Lop off the initial name and replace with base_name
            tgt_name =  utils.replace_root_name(name, base_name,
                                                new_obj)
            new_file = file_from_fs(new_obj, tgt_name)
            file_map[tgt_name] = new_file
            by_tgt_map[new_obj] = new_file
            root_file.children.append(new_file)

        for f in files:
            new_obj = os.path.join(root, f)
            #print "new_obj = %s"%new_obj
            tgt_name =  utils.replace_root_name(name, base_name,
                                                new_obj)
            new_file = file_from_fs(new_obj, tgt_name)
            file_map[tgt_name] = new_file
            by_tgt_map[new_obj] = new_file
            root_file.children.append(new_file)

    return Hierarchy(file_map, { base_name : file_map[base_name] })
Beispiel #4
0
def hierarchy_from_fs(name, base_name):
    """
    Create a hierarchy of files from a named object in the
    filesystem.

    The files will be named with 'base_name' substituted for 'name'.

    Returns a Hierarchy with everything filled in.
    """

    # A map of filename to file object, so you can find 'em eas
    file_map = {}

    # Add the root ..
    file_map[base_name] = file_from_fs(name, base_name)

    # Same as file_map, but indexed by the name in the fs rather
    # than in the resulting archive - used to find directories
    # quickly.
    by_tgt_map = {}

    by_tgt_map[name] = file_map[base_name]

    the_paths = os.walk(name)
    for p in the_paths:
        (root, dirs, files) = p

        # This is legit - top-down means that root must have been
        # visited first. If it isn't, our ordering will collapse
        # and the cpio archive when we generate it will at the
        # least be extremely odd.
        #
        root_file = by_tgt_map[root]

        for d in dirs:
            new_obj = os.path.join(root, d)
            # Lop off the initial name and replace with base_name
            tgt_name = utils.replace_root_name(name, base_name, new_obj)
            new_file = file_from_fs(new_obj, tgt_name)
            file_map[tgt_name] = new_file
            by_tgt_map[new_obj] = new_file
            root_file.children.append(new_file)

        for f in files:
            new_obj = os.path.join(root, f)
            #print "new_obj = %s"%new_obj
            tgt_name = utils.replace_root_name(name, base_name, new_obj)
            new_file = file_from_fs(new_obj, tgt_name)
            file_map[tgt_name] = new_file
            by_tgt_map[new_obj] = new_file
            root_file.children.append(new_file)

    return Hierarchy(file_map, {base_name: file_map[base_name]})
Beispiel #5
0
    def build_label(self, builder, label):
        our_dir = builder.package_obj_path(label)

        dirlist = []
        tag = label.tag

        if (tag == utils.LabelTag.Built or tag == utils.LabelTag.Installed):
            for (l, s) in self.components:
                tmp = Label(utils.LabelType.Package,
                            l.name,
                            l.role,
                            domain=label.domain)
                root_dir = builder.package_install_path(tmp)
                dirlist.append((root_dir, s))

                print "dirlist:"
                for (x, y) in dirlist:
                    print "%s=%s \n" % (x, y)

        if (tag == utils.LabelTag.PreConfig):
            pass
        elif (tag == utils.LabelTag.Configured):
            pass
        elif (tag == utils.LabelTag.Built):
            # OK. Building. This is ghastly ..
            utils.recursively_remove(our_dir)
            utils.ensure_dir(our_dir)
            # Now we need to copy all the subdirs in ..
            for (root, sub) in dirlist:
                utils.ensure_dir(utils.rel_join(our_dir, sub))
                # Only bother to copy kernel modules.
                names = utils.find_by_predicate(utils.rel_join(root, sub),
                                                predicate_is_kernel_module)
                utils.copy_name_list_with_dirs(names,
                                               utils.rel_join(root, sub),
                                               utils.rel_join(our_dir, sub))

            # .. and run depmod.
            depmod = "depmod"
            if (self.custom_depmod is not None):
                depmod = self.custom_depmod

            # Because depmod is brain-dead, we need to give it explicit versions.
            names = os.listdir(utils.rel_join(our_dir, "lib/modules"))
            our_re = re.compile(r'\d+\.\d+\..*')
            for n in names:
                if (our_re.match(n) is not None):
                    print "Found kernel version %s in %s .. " % (n, our_dir)
                    utils.run0("%s -b %s %s" % (depmod, our_dir, n))

        elif (tag == utils.LabelTag.Installed):
            # Now we find all the modules.* files in our_dir and copy them over
            # to our install directory
            names = utils.find_by_predicate(our_dir, predicate_is_module_db)
            tgt_dir = builder.package_install_path(label)
            utils.copy_name_list_with_dirs(names, our_dir, tgt_dir)
            for n in names:
                new_n = utils.replace_root_name(our_dir, tgt_dir, n)
                print "Installed: %s" % (new_n)

        elif (tag == utils.LabelTag.Clean):
            utils.recursively_remove(our_dir)
        elif (tag == utils.LabelTag.DistClean):
            utils.recursively_remove(our_dir)
Beispiel #6
0
    def build_label(self, builder, label):
        our_dir = builder.package_obj_path(label)

        dirlist = [ ]
        tag = label.tag

        if (tag == utils.LabelTag.Built or tag == utils.LabelTag.Installed):
            for (l,s) in self.components:
                tmp = Label(utils.LabelType.Package, l.name, l.role, domain=label.domain)
                root_dir = builder.package_install_path(tmp)
                dirlist.append( (root_dir, s) )

                print "dirlist:"
                for (x,y) in dirlist:
                    print "%s=%s \n"%(x,y)


        if (tag == utils.LabelTag.PreConfig):
            pass
        elif (tag == utils.LabelTag.Configured):
            pass
        elif (tag == utils.LabelTag.Built):
            # OK. Building. This is ghastly ..
            utils.recursively_remove(our_dir)
            utils.ensure_dir(our_dir)
            # Now we need to copy all the subdirs in ..
            for (root, sub) in dirlist:
                utils.ensure_dir(utils.rel_join(our_dir, sub))
                # Only bother to copy kernel modules.
                names = utils.find_by_predicate(utils.rel_join(root, sub),
                                                predicate_is_kernel_module)
                utils.copy_name_list_with_dirs(names,
                                               utils.rel_join(root,sub),
                                               utils.rel_join(our_dir, sub))


            # .. and run depmod.
            depmod = "depmod"
            if (self.custom_depmod is not None):
                depmod = self.custom_depmod

            # Because depmod is brain-dead, we need to give it explicit versions.
            names = os.listdir(utils.rel_join(our_dir, "lib/modules"))
            our_re = re.compile(r'\d+\.\d+\..*')
            for n in names:
                if (our_re.match(n) is not None):
                    print "Found kernel version %s in %s .. "%(n, our_dir)
                    utils.run0("%s -b %s %s"%(depmod, our_dir, n))

        elif (tag == utils.LabelTag.Installed):
            # Now we find all the modules.* files in our_dir and copy them over
            # to our install directory
            names = utils.find_by_predicate(our_dir, predicate_is_module_db)
            tgt_dir = builder.package_install_path(label)
            utils.copy_name_list_with_dirs(names, our_dir, tgt_dir)
            for n in names:
                new_n = utils.replace_root_name(our_dir, tgt_dir, n)
                print "Installed: %s"%(new_n)

        elif (tag == utils.LabelTag.Clean):
            utils.recursively_remove(our_dir)
        elif (tag == utils.LabelTag.DistClean):
            utils.recursively_remove(our_dir)