def execute(self, parameter_pool): current_branch, _ = shell_utils.get_working_branch(False) parameter_pool.put(Parameter(ParameterName.CurrentBranch, current_branch, ParameterSource.ConfigFile)) if current_branch: log.info(u'Current working branch is "{0}".'.format(current_branch)) branch_pool = _copy.deepcopy(parameter_pool) # Fill branch environment parameter values branches = parameter_pool.get_value(ParameterName.Branches) for key in EbConfigFile.BranchSectionKeys | EbConfigFile.BranchSectionHiddenKeys: if branches and current_branch in branches.keys() \ and key in branches[current_branch].keys(): # Copy parameter if current branch has corresponding setting branch_pool.put(Parameter(key, branches[current_branch][key], ParameterSource.ConfigFile)) else: # TODO: we will leave following parameter if not presents in branch, since # we are not asking for them for now but they are required in terminal if not key in (ParameterName.ApplicationName, ParameterName.Region, ParameterName.ServiceEndpoint, ParameterName.DevToolsEndpoint): branch_pool.remove(key) branch_pool.put(Parameter(ParameterName.DefaultEnvironmentName, parameter_pool.get_value(ParameterName.EnvironmentName, False), ParameterSource.ConfigFile)) # Call terminal copy = BeanstalkTerminal.ask_branch(branch_pool) # Create mapping and branch-environment section if branches is None: parameter_pool.put(Parameter(ParameterName.Branches, dict(), ParameterSource.Terminal)) branches = parameter_pool.get_value(ParameterName.Branches, False) branches[current_branch] = dict() source = ParameterSource.ConfigFile for key in EbConfigFile.BranchSectionKeys | EbConfigFile.BranchSectionHiddenKeys: if branch_pool.has(key): branches[current_branch][key] = branch_pool.get_value(key, False) if ParameterSource.is_ahead(branch_pool.get_source(key), source): source = branch_pool.get_source(key) else: # Copy parameter if not exists in branch if parameter_pool.has(key): branches[current_branch][key] = parameter_pool.get_value(key, False) parameter_pool.update(ParameterName.Branches, source=source) # Copy over optionsetting file if copy: default_option_file = parameter_pool.get_value(ParameterName.OptionSettingFile, False) branch_option_file = branches[current_branch][ParameterName.OptionSettingFile] log.debug(u'Copying optionsettings file from {0} to {1}.'.format(default_option_file, branch_option_file)) shell_utils.copy_file(default_option_file, branch_option_file, True) config_file.set_access_permission(branch_option_file, True) # Fill [branch] section if parameter_pool.get_value(ParameterName.BranchMapping) is None: parameter_pool.put(Parameter(ParameterName.BranchMapping, dict(), ParameterSource.Terminal)) branch_mapping = parameter_pool.get_value(ParameterName.BranchMapping, False) branch_mapping[current_branch] = branch_pool.get_value(ParameterName.EnvironmentName, False) else: # local repository does not have branch committed yet. msg = TerminalMessage.NoBranchToRegister log.error(msg) prompt.error(msg)
def execute(self, parameter_pool): current_branch, _ = shell_utils.get_working_branch(False) parameter_pool.put( Parameter(ParameterName.CurrentBranch, current_branch, ParameterSource.ConfigFile)) if current_branch: log.info('Current working branch is "{0}".'.format(current_branch)) branch_pool = _copy.deepcopy(parameter_pool) # Fill branch environment parameter values branches = parameter_pool.get_value(ParameterName.Branches)\ if parameter_pool.has(ParameterName.Branches) else None for key in EbConfigFile.BranchSectionKeys | EbConfigFile.BranchSectionHiddenKeys: if branches and current_branch in list(branches.keys()) \ and key in list(branches[current_branch].keys()): # Copy parameter if current branch has corresponding setting branch_pool.put( Parameter(key, branches[current_branch][key], ParameterSource.ConfigFile)) else: # TODO: we will leave following parameter if not presents in branch, since # we are not asking for them for now but they are required in terminal if not key in (ParameterName.ApplicationName, ParameterName.Region, ParameterName.ServiceEndpoint, ParameterName.DevToolsEndpoint): branch_pool.remove(key) branch_pool.put( Parameter( ParameterName.DefaultEnvironmentName, parameter_pool.get_value(ParameterName.EnvironmentName), ParameterSource.ConfigFile)) # Call terminal copy = BeanstalkTerminal.ask_branch(branch_pool) # Create mapping and branch-environment section if branches is None: parameter_pool.put( Parameter(ParameterName.Branches, dict(), ParameterSource.Terminal)) branches = parameter_pool.get_value(ParameterName.Branches) branches[current_branch] = dict() source = ParameterSource.ConfigFile for key in EbConfigFile.BranchSectionKeys | EbConfigFile.BranchSectionHiddenKeys: if branch_pool.has(key): branches[current_branch][key] = branch_pool.get_value(key) if ParameterSource.is_ahead(branch_pool.get_source(key), source): source = branch_pool.get_source(key) else: # Copy parameter if not exists in branch if parameter_pool.has(key): branches[current_branch][ key] = parameter_pool.get_value(key) parameter_pool.update(ParameterName.Branches, source=source) # Copy over optionsetting file if copy: default_option_file = parameter_pool.get_value( ParameterName.OptionSettingFile) branch_option_file = branches[current_branch][ ParameterName.OptionSettingFile] log.debug('Copying config file from {0} to {1}.'.format( default_option_file, branch_option_file)) shell_utils.copy_file(default_option_file, branch_option_file, True) config_file.set_access_permission(branch_option_file, True) # Fill [branch] section if not parameter_pool.has(ParameterName.BranchMapping)\ or parameter_pool.get_value(ParameterName.BranchMapping) is None: parameter_pool.put( Parameter(ParameterName.BranchMapping, dict(), ParameterSource.Terminal)) branch_mapping = parameter_pool.get_value( ParameterName.BranchMapping) branch_mapping[current_branch] = branch_pool.get_value( ParameterName.EnvironmentName) else: # local repository does not have branch committed yet. msg = TerminalMessage.NoBranchToRegister log.error(msg) prompt.error(msg)