<s> import os <EOL> import logging <EOL> from cactus . deployment . file import BaseFile <EOL> from cactus . utils . filesystem import fileList <EOL> from cactus . utils . helpers import get_or_prompt , memoize , map_apply <EOL> from cactus . utils . parallel import multiMap , PARALLEL_DISABLED <EOL> logger = logging . getLogger ( __name__ ) <EOL> class BaseDeploymentEngine ( object ) : <EOL> FileClass = BaseFile <EOL> CredentialsManagerClass = None <EOL> config_bucket_name = None <EOL> config_bucket_website = None <EOL> _index_page = "<STR_LIT>" <EOL> _error_page = "<STR_LIT>" <EOL> _connection = None <EOL> def __init__ ( self , site ) : <EOL> """<STR_LIT>""" <EOL> self . site = site <EOL> self . credentials_manager = self . CredentialsManagerClass ( self ) <EOL> def deploy ( self ) : <EOL> self . configure ( ) <EOL> mapper = multiMap if self . site . _parallel > PARALLEL_DISABLED else map_apply <EOL> totalFiles = mapper ( lambda p : p . upload ( ) , self . files ( ) ) <EOL> return totalFiles <EOL> def _ignore_file ( self , path ) : <EOL> if os . path . basename ( path ) . startswith ( "<STR_LIT:.>" ) : <EOL> return True <EOL> if "<STR_LIT:\r>" in os . path . basename ( path ) : <EOL> return True <EOL> return False <EOL> @ memoize <EOL> def files ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ self . FileClass ( self , file_path ) for file_path in fileList ( <EOL> self . site . build_path , relative = True ) if self . _ignore_file ( file_path ) is False ] <EOL> def total_bytes ( self ) : <EOL> """<STR_LIT>""" <EOL> return sum ( [ f . total_bytes for f in self . files ( ) ] ) <EOL> def total_bytes_uploaded ( self ) : <EOL> """<STR_LIT>""" <EOL> return sum ( [ f . total_bytes_uploaded for f in self . files ( ) ] ) <EOL> def progress ( self ) : <EOL> """<STR_LIT>""" <EOL> total_bytes = float ( self . total_bytes ( ) ) <EOL> total_bytes_uploaded = float ( self . total_bytes_uploaded ( ) ) <EOL> if total_bytes == <NUM_LIT:0> or total_bytes_uploaded == <NUM_LIT:0> : <EOL> return <NUM_LIT:0.0> <EOL> return total_bytes_uploaded / total_bytes <EOL> def get_connection ( self ) : <EOL> if self . _connection is None : <EOL> self . _connection = self . _create_connection ( ) <EOL> return self . _connection <EOL> def _create_connection ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def get_bucket ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def create_bucket ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def get_website_endpoint ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def configure ( self ) : <EOL> """<STR_LIT>""" <EOL> self . bucket_name = get_or_prompt ( self . site . config , self . config_bucket_name , self . site . ui . prompt_normalized , <EOL> "<STR_LIT>" ) <EOL> self . bucket = self . get_bucket ( ) <EOL> created = False <EOL> if self . bucket is None : <EOL> if self . site . ui . prompt_yes_no ( "<STR_LIT>" ) : <EOL> self . bucket = self . create_bucket ( ) <EOL> created = True <EOL> else : <EOL> return <EOL> website_endpoint = self . get_website_endpoint ( ) <EOL> self . site . config . set ( self . config_bucket_website , website_endpoint ) <EOL> self . site . config . write ( ) <EOL> self . credentials_manager . save_credentials ( ) <EOL> if created : <EOL> logger . info ( '<STR_LIT>' , self . bucket_name , website_endpoint ) <EOL> logger . info ( "<STR_LIT>" , self . bucket_name ) <EOL> logger . info ( "<STR_LIT>" , website_endpoint ) </s>
