Esempio n. 1
0
def create_from_real_object(fo, use_rpmdb=False):
    """
    Creates and returns an appropriate type of FileObjects' instance from a
    Bunch object of which path exists actually.

    :param fo:  A Bunch object
    """
    if not os.path.islink(fo.path):
        assert os.path.exists(fo.path)

    basic_attr_names = ("mode", "uid", "gid")
    st = lstat(fo.path, use_rpmdb)

    if st is None:
        return FO.UnknownObject(**fo)

    attrs = dict(zip(basic_attr_names, st))
    attrs["mode"] = U.st_mode_to_mode(attrs["mode"])

    filetype = guess_filetype(st[0])

    if filetype == G.TYPE_FILE:
        fo.checksum = U.checksum(fo.path)
    else:
        fo.checksum = U.checksum()

        if filetype == G.TYPE_UNKNOWN:
            logging.warn("Failed to detect filetype: " + fo.path)

        elif filetype == G.TYPE_SYMLINK:
            if "linkto" not in fo:
                fo.linkto = os.path.realpath(fo.path)

    # override with real (stat-ed) values if not specified.
    for n in basic_attr_names:
        if n not in fo:
            fo[n] = attrs[n]

    cls = FO.FILEOBJECTS.get(filetype, None)
    assert cls is not None

    return cls(**fo)
Esempio n. 2
0
 def test_pred__supported(self):
     fo = FileObject("/dummy/path", 33204, 0, 0, checksum(), dict())
     self.assertFalse(self.filter.pred(fo))