예제 #1
0
    def init_from_tarinfo(self, tarinfo):
        """Set data from tarinfo object (part of tarfile module)"""
        # Set the typepp
        type = tarinfo.type
        if type == tarfile.REGTYPE or type == tarfile.AREGTYPE:
            self.type = "reg"
        elif type == tarfile.LNKTYPE:
            raise PathException("Hard links not supported yet")
        elif type == tarfile.SYMTYPE:
            self.type = "sym"
            self.symtext = tarinfo.linkname
        elif type == tarfile.CHRTYPE:
            self.type = "chr"
            self.devnums = (tarinfo.devmajor, tarinfo.devminor)
        elif type == tarfile.BLKTYPE:
            self.type = "blk"
            self.devnums = (tarinfo.devmajor, tarinfo.devminor)
        elif type == tarfile.DIRTYPE:
            self.type = "dir"
        elif type == tarfile.FIFOTYPE:
            self.type = "fifo"
        else:
            raise PathException("Unknown tarinfo type %s" % (type,))

        self.mode = tarinfo.mode
        self.stat = StatResult()

        """ Set user and group id 
        use numeric id if name lookup fails
        OR
        --numeric-owner is set 
        """
        try:
            if globals.numeric_owner:
                raise KeyError
            self.stat.st_uid = tarfile.uname2uid(tarinfo.uname)
        except KeyError:
            self.stat.st_uid = tarinfo.uid
        try:
            if globals.numeric_owner:
                raise KeyError
            self.stat.st_gid = tarfile.gname2gid(tarinfo.gname)
        except KeyError:
            self.stat.st_gid = tarinfo.gid

        self.stat.st_mtime = int(tarinfo.mtime)
        if self.stat.st_mtime < 0:
            log.Warn(_("Warning: %s has negative mtime, treating as 0.")
                     % (tarinfo.name,))
            self.stat.st_mtime = 0
        self.stat.st_size = tarinfo.size
예제 #2
0
    def init_from_tarinfo(self, tarinfo):
        """Set data from tarinfo object (part of tarfile module)"""
        # Set the typepp
        type = tarinfo.type
        if type == tarfile.REGTYPE or type == tarfile.AREGTYPE:
            self.type = "reg"
        elif type == tarfile.LNKTYPE:
            raise PathException("Hard links not supported yet")
        elif type == tarfile.SYMTYPE:
            self.type = "sym"
            self.symtext = tarinfo.linkname
        elif type == tarfile.CHRTYPE:
            self.type = "chr"
            self.devnums = (tarinfo.devmajor, tarinfo.devminor)
        elif type == tarfile.BLKTYPE:
            self.type = "blk"
            self.devnums = (tarinfo.devmajor, tarinfo.devminor)
        elif type == tarfile.DIRTYPE:
            self.type = "dir"
        elif type == tarfile.FIFOTYPE:
            self.type = "fifo"
        else:
            raise PathException("Unknown tarinfo type %s" % (type, ))

        self.mode = tarinfo.mode
        self.stat = StatResult()
        """ Set user and group id 
        use numeric id if name lookup fails
        OR
        --numeric-owner is set 
        """
        try:
            if globals.numeric_owner:
                raise KeyError
            self.stat.st_uid = tarfile.uname2uid(tarinfo.uname)
        except KeyError:
            self.stat.st_uid = tarinfo.uid
        try:
            if globals.numeric_owner:
                raise KeyError
            self.stat.st_gid = tarfile.gname2gid(tarinfo.gname)
        except KeyError:
            self.stat.st_gid = tarinfo.gid

        self.stat.st_mtime = int(tarinfo.mtime)
        if self.stat.st_mtime < 0:
            log.Warn(
                _("Warning: %s has negative mtime, treating as 0.") %
                (tarinfo.name, ))
            self.stat.st_mtime = 0
        self.stat.st_size = tarinfo.size
예제 #3
0
 def test_uname2uid(self):
     """Test getting uids from unames"""
     for uname in ('root', 'ben', 'bin', 'sanothua', 'root', 'root'):
         self.compare(lambda: tarfile.uname2uid(uname),
                      lambda: pwd.getpwnam(uname)[2])