<s> """<STR_LIT>""" <EOL> import os <EOL> import tempfile <EOL> from django . conf import settings <EOL> from pysftp import Connection <EOL> from . base import BaseStorage , StorageError <EOL> from . . import settings as dbbackup_settings <EOL> class Storage ( BaseStorage ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> SFTP_HOST = getattr ( settings , '<STR_LIT>' , None ) <EOL> SFTP_USER = getattr ( settings , '<STR_LIT>' , None ) <EOL> SFTP_PASSWORD = getattr ( settings , '<STR_LIT>' , None ) <EOL> SFTP_PATH = getattr ( settings , '<STR_LIT>' , "<STR_LIT:.>" ) <EOL> SFTP_PATH = '<STR_LIT>' % SFTP_PATH . strip ( '<STR_LIT:/>' ) <EOL> SFTP_PASSIVE_MODE = getattr ( settings , '<STR_LIT>' , False ) <EOL> def __init__ ( self , server_name = None ) : <EOL> self . _check_settings ( ) <EOL> self . sftp = Connection ( host = self . SFTP_HOST , username = self . SFTP_USER , <EOL> password = self . SFTP_PASSWORD ) <EOL> def _check_settings ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . SFTP_HOST : <EOL> msg = '<STR_LIT>' % self . name <EOL> raise StorageError ( msg ) <EOL> @ property <EOL> def backup_dir ( self ) : <EOL> return self . SFTP_PATH <EOL> def delete_file ( self , filepath ) : <EOL> """<STR_LIT>""" <EOL> self . sftp . remove ( filepath ) <EOL> def list_directory ( self , raw = False ) : <EOL> """<STR_LIT>""" <EOL> return sorted ( self . sftp . listdir ( self . SFTP_PATH ) ) <EOL> def write_file ( self , filehandle , filename ) : <EOL> """<STR_LIT>""" <EOL> filehandle . seek ( <NUM_LIT:0> ) <EOL> backuppath = os . path . join ( self . SFTP_PATH , filename ) <EOL> self . sftp . putfo ( filehandle , backuppath ) <EOL> def read_file ( self , filepath ) : <EOL> """<STR_LIT>""" <EOL> outputfile = tempfile . SpooledTemporaryFile ( <EOL> max_size = dbbackup_settings . TMP_FILE_MAX_SIZE , <EOL> dir = dbbackup_settings . TMP_DIR ) <EOL> self . sftp . getfo ( filepath , outputfile ) <EOL> return outputfile </s>
