<s> from smbclient import SambaClient <EOL> import os <EOL> from airflow . hooks . base_hook import BaseHook <EOL> class SambaHook ( BaseHook ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , samba_conn_id ) : <EOL> self . conn = self . get_connection ( samba_conn_id ) <EOL> def get_conn ( self ) : <EOL> samba = SambaClient ( <EOL> server = self . conn . host , <EOL> share = self . conn . schema , <EOL> username = self . conn . login , <EOL> ip = self . conn . host , <EOL> password = self . conn . password ) <EOL> return samba <EOL> def push_from_local ( self , destination_filepath , local_filepath ) : <EOL> samba = self . get_conn ( ) <EOL> if samba . exists ( destination_filepath ) : <EOL> if samba . isfile ( destination_filepath ) : <EOL> samba . remove ( destination_filepath ) <EOL> else : <EOL> folder = os . path . dirname ( destination_filepath ) <EOL> if not samba . exists ( folder ) : <EOL> samba . mkdir ( folder ) <EOL> samba . upload ( local_filepath , destination_filepath ) </s>
