<s> import six <EOL> from anvil import exceptions as excp <EOL> from anvil import log as logging <EOL> from anvil import patcher <EOL> from anvil import settings <EOL> from anvil import shell as sh <EOL> from anvil import trace as tr <EOL> from anvil import type_utils as tu <EOL> from anvil import utils <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class Component ( object ) : <EOL> def __init__ ( self , name , subsystems , instances , options , siblings , distro , ** kwargs ) : <EOL> self . subsystems = subsystems <EOL> self . name = name <EOL> self . options = options <EOL> self . instances = instances <EOL> self . siblings = siblings <EOL> self . distro = distro <EOL> self . activated = False <EOL> self . bin_dir = "<STR_LIT>" <EOL> self . cfg_dir = sh . joinpths ( "<STR_LIT>" , self . name ) <EOL> def get_password ( self , option ) : <EOL> pw_val = self . passwords . get ( option ) <EOL> if pw_val is None : <EOL> raise excp . PasswordException ( "<STR_LIT>" % ( option ) ) <EOL> return pw_val <EOL> def get_interpolated_option ( self , option , default_value = None ) : <EOL> tried = [ option ] <EOL> while True : <EOL> option_value = utils . get_deep ( self . options , [ option ] ) <EOL> if option_value is None : <EOL> return default_value <EOL> else : <EOL> if not isinstance ( option_value , six . string_types ) : <EOL> return option_value <EOL> if option_value . startswith ( "<STR_LIT:$>" ) : <EOL> maybe_option = option_value [ <NUM_LIT:1> : ] <EOL> if maybe_option in tried : <EOL> tried . append ( maybe_option ) <EOL> raise excp . ConfigException ( "<STR_LIT>" % tried ) <EOL> else : <EOL> tried . append ( maybe_option ) <EOL> option = maybe_option <EOL> else : <EOL> return option_value <EOL> def get_option ( self , option , * options , ** kwargs ) : <EOL> option_value = utils . get_deep ( self . options , [ option ] + list ( options ) ) <EOL> if option_value is None : <EOL> return kwargs . get ( '<STR_LIT>' ) <EOL> else : <EOL> return option_value <EOL> def get_bool_option ( self , option , * options , ** kwargs ) : <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = False <EOL> return tu . make_bool ( self . get_option ( option , * options , ** kwargs ) ) <EOL> def get_int_option ( self , option , * options , ** kwargs ) : <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> return int ( self . get_option ( option , * options , ** kwargs ) ) <EOL> @ property <EOL> def env_exports ( self ) : <EOL> return { } <EOL> def verify ( self ) : <EOL> pass <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( tu . obj_name ( self ) , self . name ) <EOL> @ property <EOL> def params ( self ) : <EOL> return { <EOL> '<STR_LIT>' : self . get_option ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . get_option ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . get_option ( '<STR_LIT>' ) , <EOL> } <EOL> def warm_configs ( self ) : <EOL> pass <EOL> def subsystem_names ( self ) : <EOL> return self . subsystems . keys ( ) <EOL> @ property <EOL> def packages ( self ) : <EOL> return [ ] <EOL> def package_names ( self ) : <EOL> """<STR_LIT>""" <EOL> names = set ( ) <EOL> for pack in self . packages : <EOL> try : <EOL> names . add ( pack [ "<STR_LIT:name>" ] ) <EOL> except KeyError : <EOL> pass <EOL> daemon_to_package = self . get_option ( "<STR_LIT>" ) <EOL> if not daemon_to_package : <EOL> daemon_to_package = { } <EOL> for key in self . subsystem_names ( ) : <EOL> try : <EOL> names . add ( daemon_to_package [ key ] ) <EOL> except KeyError : <EOL> names . add ( "<STR_LIT>" % ( self . name , key ) ) <EOL> return names <EOL> class BasicComponent ( Component ) : <EOL> def __init__ ( self , * args , ** kargs ) : <EOL> super ( BasicComponent , self ) . __init__ ( * args , ** kargs ) <EOL> trace_fn = tr . trace_filename ( self . get_option ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . tracewriter = tr . TraceWriter ( trace_fn , break_if_there = False ) <EOL> def download ( self ) : <EOL> return [ ] <EOL> def list_patches ( self , section ) : <EOL> what_patches = self . get_option ( '<STR_LIT>' , section ) <EOL> if not what_patches : <EOL> what_patches = [ sh . joinpths ( settings . CONFIG_DIR , '<STR_LIT>' , <EOL> self . name , section ) ] <EOL> canon_what_patches = [ ] <EOL> for path in what_patches : <EOL> if sh . isdir ( path ) : <EOL> patches = sorted ( fn for fn in sh . listdir ( path , files_only = True ) <EOL> if fn . endswith ( '<STR_LIT>' ) ) <EOL> canon_what_patches . extend ( patches ) <EOL> elif sh . isfile ( path ) : <EOL> canon_what_patches . append ( path ) <EOL> return canon_what_patches <EOL> def patch ( self , section ) : <EOL> canon_what_patches = self . list_patches ( section ) <EOL> if canon_what_patches : <EOL> target_dir = self . get_option ( '<STR_LIT>' ) <EOL> patcher . apply_patches ( canon_what_patches , target_dir ) </s>
