33import logging
44import os
55import os .path
6+ import sys
67import subprocess
78import tarfile
89
@@ -414,8 +415,15 @@ def pulp_export(exporter_pk, params):
414415 stdin = subprocess .PIPE ,
415416 ) as split_process :
416417 try :
417- with tarfile .open (tarfile_fp , "w|gz" , fileobj = split_process .stdin ) as tar :
418- _do_export (pulp_exporter , tar , the_export )
418+ # on Python < 3.12 we have a monkeypatch which enables compression levels
419+ if sys .version_info .major == 3 and sys .version_info .minor < 12 :
420+ with tarfile .open (tarfile_fp , "w|gz" , fileobj = split_process .stdin ) as tar :
421+ _do_export (pulp_exporter , tar , the_export )
422+ else :
423+ with tarfile .open (
424+ tarfile_fp , "w|gz" , fileobj = split_process .stdin , compresslevel = 1
425+ ) as tar :
426+ _do_export (pulp_exporter , tar , the_export )
419427 except Exception :
420428 # no matter what went wrong, we can't trust the files we (may have) created.
421429 # Delete the ones we can find and pass the problem up.
@@ -433,7 +441,7 @@ def pulp_export(exporter_pk, params):
433441 else :
434442 # write into the file
435443 try :
436- with tarfile .open (tarfile_fp , "w:gz" ) as tar :
444+ with tarfile .open (tarfile_fp , "w:gz" , compresslevel = 1 ) as tar :
437445 _do_export (pulp_exporter , tar , the_export )
438446 except Exception :
439447 # no matter what went wrong, we can't trust the file we created.
0 commit comments