Home | History | Annotate | Download | only in python2.7

Lines Matching refs:tarinfo

62 __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"]
118 # Fields from a pax header that override a TarInfo attribute.
787 def __init__(self, tarfile, tarinfo):
789 tarinfo.offset_data,
790 tarinfo.size,
791 getattr(tarinfo, "sparse", None))
792 self.name = tarinfo.name
795 self.size = tarinfo.size
912 class TarInfo(object):
915 TarInfo objects are returned by TarFile.getmember(),
921 """Construct a TarInfo object. name is the optional name
961 """Return the TarInfo's attributes as a dictionary.
1190 """Construct a TarInfo object from a 512 byte string buffer.
1236 """Return the next TarInfo object from TarFile object
1254 # 3. Return self or another valid TarInfo object.
1279 # Patch the TarInfo object with saved global
1297 # Patch the TarInfo object from the next header with
1406 # Patch the TarInfo object with the extended header info.
1473 # class TarInfo
1497 tarinfo = TarInfo # The default TarInfo class to use.
1502 tarinfo=None, dereference=None, ignore_zeros=None, encoding=None,
1536 if tarinfo is not None:
1537 self.tarinfo = tarinfo
1564 self.members = [] # list of members as TarInfo objects
1582 tarinfo = self.tarinfo.fromtarfile(self)
1583 self.members.append(tarinfo)
1594 buf = self.tarinfo.create_pax_global_header(self.pax_headers.copy())
1789 """Return a TarInfo object for member `name'. If `name' can not be
1794 tarinfo = self._getmember(name)
1795 if tarinfo is None:
1797 return tarinfo
1800 """Return the members of the archive as a list of TarInfo objects. The
1813 return [tarinfo.name for tarinfo in self.getmembers()]
1816 """Create a TarInfo object for either the file `name' or the file
1818 modify some of the TarInfo's attributes before you add it using
1838 # Now, fill the TarInfo object with
1840 tarinfo = self.tarinfo()
1841 tarinfo.tarfile = self
1883 # Fill the TarInfo object with all
1885 tarinfo.name = arcname
1886 tarinfo.mode = stmd
1887 tarinfo.uid = statres.st_uid
1888 tarinfo.gid = statres.st_gid
1890 tarinfo.size = statres.st_size
1892 tarinfo.size = 0L
1893 tarinfo.mtime = statres.st_mtime
1894 tarinfo.type = type
1895 tarinfo.linkname = linkname
1898 tarinfo.uname = pwd.getpwuid(tarinfo.uid)[0]
1903 tarinfo.gname = grp.getgrgid(tarinfo.gid)[0]
1909 tarinfo.devmajor = os.major(statres.st_rdev)
1910 tarinfo.devminor = os.minor(statres.st_rdev)
1911 return tarinfo
1920 for tarinfo in self:
1922 print filemode(tarinfo.mode),
1923 print "%s/%s" % (tarinfo.uname or tarinfo.uid,
1924 tarinfo.gname or tarinfo.gid),
1925 if tarinfo.ischr() or tarinfo.isblk():
1927 % (tarinfo.devmajor, tarinfo.devminor)),
1929 print "%10d" % tarinfo.size,
1931 tarinfo.mtime)[:6],
1933 print tarinfo.name + ("/" if tarinfo.isdir() else ""),
1936 if tarinfo.issym():
1937 print "->", tarinfo.linkname,
1938 if tarinfo.islnk():
1939 print "link to", tarinfo.linkname,
1949 that expects a TarInfo object argument and returns the changed
1950 TarInfo object, if it returns None the TarInfo object will be
1974 # Create a TarInfo object from the file.
1975 tarinfo = self.gettarinfo(name, arcname)
1977 if tarinfo is None:
1981 # Change or exclude the TarInfo object.
1983 tarinfo = filter(tarinfo)
1984 if tarinfo is None:
1989 if tarinfo.isreg():
1991 self.addfile(tarinfo, f)
1993 elif tarinfo.isdir():
1994 self.addfile(tarinfo)
2001 self.addfile(tarinfo)
2003 def addfile(self, tarinfo, fileobj=None):
2004 """Add the TarInfo object `tarinfo' to the archive. If `fileobj' is
2005 given, tarinfo.size bytes are read from it and added to the archive.
2006 You can create TarInfo objects using gettarinfo().
2012 tarinfo = copy.copy(tarinfo)
2014 buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
2020 copyfileobj(fileobj, self.fileobj, tarinfo.size)
2021 blocks, remainder = divmod(tarinfo.size, BLOCKSIZE)
2027 self.members.append(tarinfo)
2041 for tarinfo in members:
2042 if tarinfo.isdir():
2044 directories.append(tarinfo)
2045 tarinfo = copy.copy(tarinfo)
2046 tarinfo.mode = 0700
2047 self.extract(tarinfo, path)
2054 for tarinfo in directories:
2055 dirpath = os.path.join(path, tarinfo.name)
2057 self.chown(tarinfo, dirpath)
2058 self.utime(tarinfo, dirpath)
2059 self.chmod(tarinfo, dirpath)
2069 as possible. `member' may be a filename or a TarInfo object. You can
2075 tarinfo = self.getmember(member)
2077 tarinfo = member
2080 if tarinfo.islnk():
2081 tarinfo._link_target = os.path.join(path, tarinfo.linkname)
2084 self._extract_member(tarinfo, os.path.join(path, tarinfo.name))
2101 a filename or a TarInfo object. If `member' is a regular file, a
2111 tarinfo = self.getmember(member)
2113 tarinfo = member
2115 if tarinfo.isreg():
2116 return self.fileobject(self, tarinfo)
2118 elif tarinfo.type not in SUPPORTED_TYPES:
2121 return self.fileobject(self, tarinfo)
2123 elif tarinfo.islnk() or tarinfo.issym():
2131 return self.extractfile(self._find_link_target(tarinfo))
2137 def _extract_member(self, tarinfo, targetpath):
2138 """Extract the TarInfo object tarinfo to a physical
2141 # Fetch the TarInfo object for the given name
2154 if tarinfo.islnk() or tarinfo.issym():
2155 self._dbg(1, "%s -> %s" % (tarinfo.name, tarinfo.linkname))
2157 self._dbg(1, tarinfo.name)
2159 if tarinfo.isreg():
2160 self.makefile(tarinfo, targetpath)
2161 elif tarinfo.isdir():
2162 self.makedir(tarinfo, targetpath)
2163 elif tarinfo.isfifo():
2164 self.makefifo(tarinfo, targetpath)
2165 elif tarinfo.ischr() or tarinfo.isblk():
2166 self.makedev(tarinfo, targetpath)
2167 elif tarinfo.islnk() or tarinfo.issym():
2168 self.makelink(tarinfo, targetpath)
2169 elif tarinfo.type not in SUPPORTED_TYPES:
2170 self.makeunknown(tarinfo, targetpath)
2172 self.makefile(tarinfo, targetpath)
2174 self.chown(tarinfo, targetpath)
2175 if not tarinfo.issym():
2176 self.chmod(tarinfo, targetpath)
2177 self.utime(tarinfo, targetpath)
2184 def makedir(self, tarinfo, targetpath):
2195 def makefile(self, tarinfo, targetpath):
2198 source = self.extractfile(tarinfo)
2205 def makeunknown(self, tarinfo, targetpath):
2206 """Make a file from a TarInfo object with an unknown type
2209 self.makefile(tarinfo, targetpath)
2211 "extracted as regular file." % tarinfo.type)
2213 def makefifo(self, tarinfo, targetpath):
2221 def makedev(self, tarinfo, targetpath):
2227 mode = tarinfo.mode
2228 if tarinfo.isblk():
2234 os.makedev(tarinfo.devmajor, tarinfo.devminor))
2236 def makelink(self, tarinfo, targetpath):
2243 if tarinfo.issym():
2246 os.symlink(tarinfo.linkname, targetpath)
2249 if os.path.exists(tarinfo._link_target):
2252 os.link(tarinfo._link_target, targetpath)
2254 self._extract_member(self._find_link_target(tarinfo), targetpath)
2257 self._extract_member(self._find_link_target(tarinfo), targetpath)
2261 def chown(self, tarinfo, targetpath):
2262 """Set owner of targetpath according to tarinfo.
2267 g = grp.getgrnam(tarinfo.gname)[2]
2269 g = tarinfo.gid
2271 u = pwd.getpwnam(tarinfo.uname)[2]
2273 u = tarinfo.uid
2275 if tarinfo.issym() and hasattr(os, "lchown"):
2283 def chmod(self, tarinfo, targetpath):
2284 """Set file permissions of targetpath according to tarinfo.
2288 os.chmod(targetpath, tarinfo.mode)
2292 def utime(self, tarinfo, targetpath):
2293 """Set modification time of targetpath according to tarinfo.
2298 os.utime(targetpath, (tarinfo.mtime, tarinfo.mtime))
2304 """Return the next member of the archive as a TarInfo object, when
2316 tarinfo = None
2319 tarinfo = self.tarinfo.fromtarfile(self)
2342 if tarinfo is not None:
2343 self.members.append(tarinfo)
2347 return tarinfo
2352 def _getmember(self, name, tarinfo=None, normalize=False):
2354 If tarinfo is given, it is used as the starting point.
2359 # Limit the member search list up to tarinfo.
2360 if tarinfo is not None:
2361 tarinfo)]
2380 tarinfo = self.next()
2381 if tarinfo is None:
2394 def _find_link_target(self, tarinfo):
2398 if tarinfo.issym():
2400 linkname = "/".join(filter(None, (os.path.dirname(tarinfo.name), tarinfo.linkname)))
2405 linkname = tarinfo.linkname
2406 limit = tarinfo
2408 member = self._getmember(linkname, tarinfo=limit, normalize=True)
2445 for tarinfo in TarFile(...):
2467 tarinfo = self.tarfile.next()
2469 tarinfo = self.tarfile.members[self.index]
2471 tarinfo = self.tarfile.next()
2472 if not tarinfo:
2478 return tarinfo
2569 tinfo = TarInfo(zinfo.filename)