MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / tar_extract

Function tar_extract

setup.py:329–365  ·  view source on GitHub ↗

Extracts tar file into single local directory. We fail if items in tar file have different . path: The tar file. mode: As tarfile.open(). prefix: If not None, we fail if tar file's is not . exists:

(path, mode='r:gz', prefix=None, exists='raise')

Source from the content-addressed store, hash-verified

327
328
329def tar_extract(path, mode='r:gz', prefix=None, exists='raise'):
330 '''
331 Extracts tar file into single local directory.
332
333 We fail if items in tar file have different <top-directory>.
334
335 path:
336 The tar file.
337 mode:
338 As tarfile.open().
339 prefix:
340 If not None, we fail if tar file&#x27;s <top-directory> is not <prefix>.
341 exists:
342 What to do if <top-directory> already exists:
343 'raise': raise exception.
344 'remove': remove existing file/directory before extracting.
345 'return': return without extracting.
346
347 Returns the directory name (which will be <prefix> if not None, with '/'
348 appended if not already present).
349 ''&#x27;
350 prefix_actual = tar_check( path, mode, prefix)
351 if os.path.exists( prefix_actual):
352 if exists == 'raise':
353 raise Exception( f'Path already exists: {prefix_actual!r}')
354 elif exists == 'remove':
355 remove( prefix_actual)
356 elif exists == 'return':
357 log( f'Not extracting {path} because already exists: {prefix_actual}')
358 return prefix_actual
359 else:
360 assert 0, f'Unrecognised exists={exists!r}'
361 assert not os.path.exists( prefix_actual), f'Path already exists: {prefix_actual}'
362 log( f'Extracting {path}')
363 with tarfile.open( path, mode) as t:
364 t.extractall()
365 return prefix_actual
366
367
368def git_info( directory):

Callers 1

get_mupdf_internalFunction · 0.85

Calls 2

tar_checkFunction · 0.85
logFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…