<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import subprocess <EOL> import sys <EOL> from freezer . engine import engine <EOL> from freezer . engine . tar import tar_builders <EOL> from freezer . utils import winutils <EOL> class TarBackupEngine ( engine . BackupEngine ) : <EOL> DEFAULT_CHUNK_SIZE = <NUM_LIT> <EOL> def __init__ ( <EOL> self , compression_algo , dereference_symlink , exclude , main_storage , <EOL> is_windows , encrypt_pass_file = None , dry_run = False , <EOL> chunk_size = DEFAULT_CHUNK_SIZE ) : <EOL> self . compression_algo = compression_algo <EOL> self . encrypt_pass_file = encrypt_pass_file <EOL> self . dereference_symlink = dereference_symlink <EOL> self . exclude = exclude <EOL> self . _main_storage = main_storage <EOL> self . is_windows = is_windows <EOL> self . dry_run = dry_run <EOL> self . chunk_size = chunk_size <EOL> @ property <EOL> def main_storage ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _main_storage <EOL> def post_backup ( self , backup , manifest ) : <EOL> self . main_storage . upload_meta_file ( backup , manifest ) <EOL> def backup_data ( self , backup_path , manifest_path ) : <EOL> logging . info ( "<STR_LIT>" ) <EOL> tar_command = tar_builders . TarCommandBuilder ( <EOL> backup_path , self . compression_algo , self . is_windows ) <EOL> if self . encrypt_pass_file : <EOL> tar_command . set_encryption ( self . encrypt_pass_file ) <EOL> if self . dereference_symlink : <EOL> tar_command . set_dereference ( self . dereference_symlink ) <EOL> tar_command . set_exclude ( self . exclude ) <EOL> tar_command . set_listed_incremental ( manifest_path ) <EOL> command = tar_command . build ( ) <EOL> logging . info ( "<STR_LIT>" . format ( command ) ) <EOL> tar_process = subprocess . Popen ( command , stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , shell = True ) <EOL> read_pipe = tar_process . stdout <EOL> tar_chunk = read_pipe . read ( self . chunk_size ) <EOL> while tar_chunk : <EOL> yield tar_chunk <EOL> tar_chunk = read_pipe . read ( self . chunk_size ) <EOL> tar_err = tar_process . communicate ( ) [ <NUM_LIT:1> ] <EOL> if '<STR_LIT:error>' in tar_err . lower ( ) : <EOL> logging . exception ( '<STR_LIT>' . format ( tar_err ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if tar_process . returncode : <EOL> logging . error ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> logging . info ( "<STR_LIT>" ) <EOL> @ staticmethod <EOL> def check_process_output ( process ) : <EOL> tar_err = process . communicate ( ) [ <NUM_LIT:1> ] <EOL> if '<STR_LIT:error>' in tar_err . lower ( ) : <EOL> logging . exception ( '<STR_LIT>' . format ( tar_err ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if process . returncode : <EOL> logging . error ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def restore_level ( self , restore_path , read_pipe ) : <EOL> """<STR_LIT>""" <EOL> tar_command = tar_builders . TarCommandRestoreBuilder ( <EOL> restore_path , self . compression_algo , self . is_windows ) <EOL> if self . encrypt_pass_file : <EOL> tar_command . set_encryption ( self . encrypt_pass_file ) <EOL> if self . dry_run : <EOL> tar_command . set_dry_run ( ) <EOL> command = tar_command . build ( ) <EOL> if winutils . is_windows ( ) : <EOL> os . chdir ( restore_path ) <EOL> tar_process = subprocess . Popen ( <EOL> command , stdin = subprocess . PIPE , stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , shell = True ) <EOL> try : <EOL> while True : <EOL> tar_process . stdin . write ( read_pipe . recv_bytes ( ) ) <EOL> except EOFError : <EOL> logging . info ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . check_process_output ( tar_process ) </s>
