MCPcopy Index your code
hub / github.com/RustPython/RustPython / add

Method add

Lib/tarfile.py:2291–2340  ·  view source on GitHub ↗

Add the file 'name' to the archive. 'name' may be any type of file (directory, fifo, symbolic link, etc.). If given, 'arcname' specifies an alternative name for the file in the archive. Directories are added recursively by default. This can be avoided by s

(self, name, arcname=None, recursive=True, *, filter=None)

Source from the content-addressed store, hash-verified

2289 print()
2290
2291 def add(self, name, arcname=None, recursive=True, *, filter=None):
2292 """Add the file 'name' to the archive. 'name' may be any type of file
2293 (directory, fifo, symbolic link, etc.). If given, 'arcname'
2294 specifies an alternative name for the file in the archive.
2295 Directories are added recursively by default. This can be avoided by
2296 setting 'recursive' to False. 'filter' is a function
2297 that expects a TarInfo object argument and returns the changed
2298 TarInfo object, if it returns None the TarInfo object will be
2299 excluded from the archive.
2300 """
2301 self._check("awx")
2302
2303 if arcname is None:
2304 arcname = name
2305
2306 # Skip if somebody tries to archive the archive...
2307 if self.name is not None and os.path.abspath(name) == self.name:
2308 self._dbg(2, "tarfile: Skipped %r" % name)
2309 return
2310
2311 self._dbg(1, name)
2312
2313 # Create a TarInfo object from the file.
2314 tarinfo = self.gettarinfo(name, arcname)
2315
2316 if tarinfo is None:
2317 self._dbg(1, "tarfile: Unsupported type %r" % name)
2318 return
2319
2320 # Change or exclude the TarInfo object.
2321 if filter is not None:
2322 tarinfo = filter(tarinfo)
2323 if tarinfo is None:
2324 self._dbg(2, "tarfile: Excluded %r" % name)
2325 return
2326
2327 # Append the tar header and data to the archive.
2328 if tarinfo.isreg():
2329 with bltn_open(name, "rb") as f:
2330 self.addfile(tarinfo, f)
2331
2332 elif tarinfo.isdir():
2333 self.addfile(tarinfo)
2334 if recursive:
2335 for f in sorted(os.listdir(name)):
2336 self.add(os.path.join(name, f), os.path.join(arcname, f),
2337 recursive, filter=filter)
2338
2339 else:
2340 self.addfile(tarinfo)
2341
2342 def addfile(self, tarinfo, fileobj=None):
2343 """Add the TarInfo object 'tarinfo' to the archive. If 'tarinfo' represents

Callers 1

mainFunction · 0.45

Calls 10

_checkMethod · 0.95
_dbgMethod · 0.95
gettarinfoMethod · 0.95
addfileMethod · 0.95
filterFunction · 0.85
sortedFunction · 0.85
isregMethod · 0.80
listdirMethod · 0.80
isdirMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected