def execute(self, parameter_pool): func_matrix = [] # Loop over default settings for name, _, to_file in CredentialFileParameters: if not parameter_pool.has(name): continue elif ParameterSource.is_ahead(ParameterSource.Terminal,\ parameter_pool.get_source(name)): continue else: func_matrix.append((None, name, to_file)) # Loop over current branch settings cur_branch = parameter_pool.get_value(ParameterName.CurrentBranch) if cur_branch and ParameterSource.is_ahead( parameter_pool.get_source(ParameterName.Branches), ParameterSource.ConfigFile): branch_setting = parameter_pool.get_value(ParameterName.Branches, False)[cur_branch] for name, _, to_file in CredentialFileParameters: if not name in branch_setting: continue else: func_matrix.append((cur_branch, name, to_file)) if len(func_matrix) < 1: log.info( u'Skipped updating credential file as credentials are not changed.' ) return location = config_file.default_aws_credential_file_location() # Create directory if needed try: shell_utils.create_directory( config_file.default_aws_credential_file_path()) config_file.write_aws_credential_file(location, parameter_pool, func_matrix) except BaseException as ex: log.error(u'Encountered error when creating AWS Credential file at "{0}", because {1}.'.\ format(location, ex)) return else: log.info(WriteAwsCredentialFileOpMessage.Succeed.format(location)) prompt.result( WriteAwsCredentialFileOpMessage.Succeed.format(location)) parameter_pool.put( Parameter(ParameterName.AwsCredentialFile, location, ParameterSource.OperationOutput), True) ret_result = OperationResult(self, None, None, None) return ret_result
def configureLogging(level=None, quiet=False, filename=EbLogFile.Name, spec_dir=os.getcwdu() + os.path.sep + EbLocalDir.Path): if not spec_dir: output_file = _getLogFile(filename) else: shell_utils.create_directory(spec_dir) output_file = spec_dir + os.path.sep + filename ori_path = shell_utils.ori_path() log_config_location = os.path.join(ori_path, u'logconfig.json') try: with codecs.open(log_config_location, 'r', encoding='utf-8') as input_file: config_dict = json.loads(input_file.read()) _set_log_filename(config_dict, output_file) if level is None and config_dict[u'root'][u'level'].upper() == u'NONE': # completely disable log config_dict[u'root'][u'level'] = u'NOTSET' _disable_logging(config_dict) else: if level is not None: config_dict[u'root'][u'level'] = level _set_log_handlers(config_dict, u'default') except (IOError, ValueError, KeyError) as ex: #JSON logging config file parsing error if not quiet: print(u'Encountered error when reading logging configuration file from "{0}": {1}.'.\ format(log_config_location, ex)) _disable_logging() return try: _config.dictConfig(config_dict) except IOError: if not quiet: print >> sys.stderr, u'Could not open {0} for logging. Using stderr instead.'.\ format(output_file) _set_log_handlers(config_dict, u'to_stderr') _config.dictConfig(config_dict) config_file.set_access_permission(output_file, True)
def execute(self, parameter_pool): func_matrix = [] # Loop over default settings for name, _, to_file in CredentialFileParameters: if not parameter_pool.has(name): continue elif ParameterSource.is_ahead(ParameterSource.Terminal,\ parameter_pool.get_source(name)): continue else: func_matrix.append((None, name, to_file)) # Loop over current branch settings cur_branch = parameter_pool.get_value(ParameterName.CurrentBranch) if cur_branch and ParameterSource.is_ahead(parameter_pool.get_source(ParameterName.Branches), ParameterSource.ConfigFile): branch_setting = parameter_pool.get_value(ParameterName.Branches, False)[cur_branch] for name, _, to_file in CredentialFileParameters: if not name in branch_setting: continue else: func_matrix.append((cur_branch, name, to_file)) if len(func_matrix) < 1: log.info(u'Skipped updating credential file as credentials are not changed.') return location = config_file.default_aws_credential_file_location() # Create directory if needed try: shell_utils.create_directory(config_file.default_aws_credential_file_path()) config_file.write_aws_credential_file(location, parameter_pool, func_matrix) except BaseException as ex: log.error(u'Encountered error when creating AWS Credential file at "{0}", because {1}.'.\ format(location, ex)) return else: log.info(WriteAwsCredentialFileOpMessage.Succeed.format(location)) prompt.result(WriteAwsCredentialFileOpMessage.Succeed.format(location)) parameter_pool.put(Parameter(ParameterName.AwsCredentialFile, location, ParameterSource.OperationOutput), True) ret_result = OperationResult(self, None, None, None) return ret_result
def configureLogging(level = None, quiet = False, filename = EbLogFile.Name, spec_dir = os.getcwdu() + os.path.sep + EbLocalDir.Path): if not spec_dir: output_file=_getLogFile(filename) else: shell_utils.create_directory(spec_dir) output_file = spec_dir + os.path.sep + filename ori_path = shell_utils.ori_path() log_config_location = os.path.join(ori_path, u'logconfig.json') try: with codecs.open(log_config_location, 'r', encoding='utf-8') as input_file: config_dict = json.loads(input_file.read()) _set_log_filename(config_dict, output_file) if level is None and config_dict[u'root'][u'level'].upper() == u'NONE': # completely disable log config_dict[u'root'][u'level'] = u'NOTSET' _disable_logging(config_dict) else: if level is not None: config_dict[u'root'][u'level'] = level _set_log_handlers(config_dict, u'default') except (IOError, ValueError, KeyError) as ex: #JSON logging config file parsing error if not quiet: print(u'Encountered error when reading logging configuration file from "{0}": {1}.'.\ format(log_config_location, ex)) _disable_logging() return try: _config.dictConfig(config_dict) except IOError: if not quiet: print >> sys.stderr, u'Could not open {0} for logging. Using stderr instead.'.\ format(output_file) _set_log_handlers(config_dict, u'to_stderr') _config.dictConfig(config_dict) config_file.set_access_permission(output_file, True)
def create_eb_local_dir(): shell_utils.create_directory(os.getcwdu() + os.path.sep + EbLocalDir.Path)