<s> from django . utils . translation import ugettext_lazy as _ <EOL> from horizon import forms <EOL> from horizon import workflows <EOL> class Parameter ( object ) : <EOL> def __init__ ( self , config ) : <EOL> self . name = config [ '<STR_LIT:name>' ] <EOL> self . description = config . get ( '<STR_LIT:description>' , "<STR_LIT>" ) <EOL> self . required = not config [ '<STR_LIT>' ] <EOL> self . default_value = config . get ( '<STR_LIT>' , None ) <EOL> self . initial_value = self . default_value <EOL> self . param_type = config [ '<STR_LIT>' ] <EOL> self . priority = int ( config . get ( '<STR_LIT>' , <NUM_LIT:2> ) ) <EOL> self . choices = config . get ( '<STR_LIT>' , None ) <EOL> def build_control ( parameter ) : <EOL> attrs = { "<STR_LIT>" : parameter . priority , <EOL> "<STR_LIT>" : parameter . default_value } <EOL> if parameter . param_type == "<STR_LIT:string>" : <EOL> return forms . CharField ( <EOL> widget = forms . TextInput ( attrs = attrs ) , <EOL> label = parameter . name , <EOL> required = ( parameter . required and <EOL> parameter . default_value is None ) , <EOL> help_text = parameter . description , <EOL> initial = parameter . initial_value ) <EOL> if parameter . param_type == "<STR_LIT:int>" : <EOL> return forms . IntegerField ( <EOL> widget = forms . TextInput ( attrs = attrs ) , <EOL> label = parameter . name , <EOL> required = parameter . required , <EOL> help_text = parameter . description , <EOL> initial = parameter . initial_value ) <EOL> elif parameter . param_type == "<STR_LIT:bool>" : <EOL> return forms . BooleanField ( <EOL> widget = forms . CheckboxInput ( attrs = attrs ) , <EOL> label = parameter . name , <EOL> required = False , <EOL> initial = parameter . initial_value , <EOL> help_text = parameter . description ) <EOL> elif parameter . param_type == "<STR_LIT>" : <EOL> return forms . ChoiceField ( <EOL> widget = forms . Select ( attrs = attrs ) , <EOL> label = parameter . name , <EOL> required = parameter . required , <EOL> choices = parameter . choices , <EOL> help_text = parameter . description ) <EOL> def _create_step_action ( name , title , parameters , advanced_fields = None , <EOL> service = None ) : <EOL> class_fields = { } <EOL> contributes_field = ( ) <EOL> for param in parameters : <EOL> field_name = "<STR_LIT>" + service + "<STR_LIT::>" + param . name <EOL> contributes_field += ( field_name , ) <EOL> class_fields [ field_name ] = build_control ( param ) <EOL> if advanced_fields is not None : <EOL> for ad_field_name , ad_field_value in advanced_fields : <EOL> class_fields [ ad_field_name ] = ad_field_value <EOL> action_meta = type ( '<STR_LIT:Meta>' , ( object , ) , <EOL> dict ( help_text_template = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) ) <EOL> class_fields [ '<STR_LIT:Meta>' ] = action_meta <EOL> action = type ( str ( title ) , <EOL> ( workflows . Action , ) , <EOL> class_fields ) <EOL> step_meta = type ( '<STR_LIT:Meta>' , ( object , ) , dict ( name = title ) ) <EOL> step = type ( str ( name ) , <EOL> ( workflows . Step , ) , <EOL> dict ( name = name , <EOL> process_name = name , <EOL> action_class = action , <EOL> contributes = contributes_field , <EOL> Meta = step_meta ) ) <EOL> return step <EOL> def build_node_group_fields ( action , name , template , count , serialized = None ) : <EOL> action . fields [ name ] = forms . CharField ( <EOL> label = _ ( "<STR_LIT:Name>" ) , <EOL> widget = forms . TextInput ( ) ) <EOL> action . fields [ template ] = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> widget = forms . HiddenInput ( ) ) <EOL> action . fields [ count ] = forms . IntegerField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> min_value = <NUM_LIT:0> , <EOL> widget = forms . HiddenInput ( ) ) <EOL> action . fields [ serialized ] = forms . CharField ( <EOL> widget = forms . HiddenInput ( ) ) <EOL> def parse_configs_from_context ( context , defaults ) : <EOL> configs_dict = dict ( ) <EOL> for key , val in context . items ( ) : <EOL> if str ( key ) . startswith ( "<STR_LIT>" ) : <EOL> key_split = str ( key ) . split ( "<STR_LIT::>" ) <EOL> service = key_split [ <NUM_LIT:1> ] <EOL> config = key_split [ <NUM_LIT:2> ] <EOL> if service not in configs_dict : <EOL> configs_dict [ service ] = dict ( ) <EOL> if ( val is None or <EOL> unicode ( defaults [ service ] [ config ] ) == unicode ( val ) ) : <EOL> continue <EOL> configs_dict [ service ] [ config ] = val <EOL> return configs_dict <EOL> def safe_call ( func , * args , ** kwargs ) : <EOL> try : <EOL> return func ( * args , ** kwargs ) <EOL> except Exception : <EOL> return None <EOL> def get_plugin_and_hadoop_version ( request ) : <EOL> plugin_name = request . REQUEST [ "<STR_LIT>" ] <EOL> hadoop_version = request . REQUEST [ "<STR_LIT>" ] <EOL> return ( plugin_name , hadoop_version ) <EOL> def clean_node_group ( node_group ) : <EOL> node_group_copy = dict ( ( key , value ) <EOL> for key , value in node_group . items ( ) if value ) <EOL> for key in [ "<STR_LIT:id>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> if key in node_group_copy : <EOL> node_group_copy . pop ( key ) <EOL> return node_group_copy <EOL> class PluginAndVersionMixin ( object ) : <EOL> def _generate_plugin_version_fields ( self , sahara ) : <EOL> plugins = sahara . plugins . list ( ) <EOL> plugin_choices = [ ( plugin . name , plugin . title ) for plugin in plugins ] <EOL> self . fields [ "<STR_LIT>" ] = forms . ChoiceField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> choices = plugin_choices , <EOL> widget = forms . Select ( attrs = { "<STR_LIT:class>" : "<STR_LIT>" } ) ) <EOL> for plugin in plugins : <EOL> field_name = plugin . name + "<STR_LIT>" <EOL> choice_field = forms . ChoiceField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> choices = [ ( version , version ) for version in plugin . versions ] , <EOL> widget = forms . Select ( <EOL> attrs = { "<STR_LIT:class>" : "<STR_LIT>" <EOL> + field_name + "<STR_LIT>" } ) <EOL> ) <EOL> self . fields [ field_name ] = choice_field <EOL> class PatchedDynamicWorkflow ( workflows . Workflow ) : <EOL> """<STR_LIT>""" <EOL> def _ensure_dynamic_exist ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . dynamic_steps = list ( ) <EOL> def _register_step ( self , step ) : <EOL> self . _ensure_dynamic_exist ( ) <EOL> self . dynamic_steps . append ( step ) <EOL> def _order_steps ( self ) : <EOL> self . _ensure_dynamic_exist ( ) <EOL> self . _registry = dict ( [ ( step , step ( self ) ) <EOL> for step in self . dynamic_steps ] ) <EOL> return list ( self . default_steps ) + self . dynamic_steps <EOL> class ServiceParametersWorkflow ( PatchedDynamicWorkflow ) : <EOL> """<STR_LIT>""" <EOL> def _populate_tabs ( self , general_parameters , service_parameters ) : <EOL> self . defaults = dict ( ) <EOL> self . _init_step ( '<STR_LIT>' , '<STR_LIT>' , general_parameters ) <EOL> for service , parameters in service_parameters . items ( ) : <EOL> self . _init_step ( service , service + '<STR_LIT>' , parameters ) <EOL> def _init_step ( self , service , title , parameters ) : <EOL> if not parameters : <EOL> return <EOL> self . _populate_initial_values ( service , parameters ) <EOL> step = _create_step_action ( service , title = title , parameters = parameters , <EOL> service = service ) <EOL> self . defaults [ service ] = dict ( ) <EOL> for param in parameters : <EOL> self . defaults [ service ] [ param . name ] = param . default_value <EOL> self . _register_step ( step ) <EOL> def _set_configs_to_copy ( self , configs ) : <EOL> self . configs_to_copy = configs <EOL> def _populate_initial_values ( self , service , parameters ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> return <EOL> configs = self . configs_to_copy <EOL> for param in parameters : <EOL> if ( service in configs and <EOL> param . name in configs [ service ] ) : <EOL> param . initial_value = configs [ service ] [ param . name ] <EOL> class StatusFormatMixin ( workflows . Workflow ) : <EOL> def __init__ ( self , request , context_seed , entry_point , * args , ** kwargs ) : <EOL> super ( StatusFormatMixin , self ) . __init__ ( request , <EOL> context_seed , <EOL> entry_point , <EOL> * args , <EOL> ** kwargs ) <EOL> def format_status_message ( self , message ) : <EOL> error_description = getattr ( self , '<STR_LIT>' , None ) <EOL> if error_description : <EOL> return error_description <EOL> else : <EOL> return message % self . context [ self . name_property ] </s>
