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 parameter_pool.has(ParameterName.CurrentBranch) else None if cur_branch and ParameterSource.is_ahead( parameter_pool.get_source(ParameterName.Branches), ParameterSource.ConfigFile): branch_setting = parameter_pool.get_value( ParameterName.Branches)[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( 'Skipped updating credential file as credentials are not changed.' ) return location = config_file.default_aws_credential_file_location() # Create directory if needed try: config_file.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('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 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 parameter_pool.has(ParameterName.CurrentBranch) else None ) if cur_branch and ParameterSource.is_ahead( parameter_pool.get_source(ParameterName.Branches), ParameterSource.ConfigFile ): branch_setting = parameter_pool.get_value(ParameterName.Branches)[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: config_file.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.getcwd() + os.path.sep + EbLocalDir.Path): if not spec_dir: output_file = _getLogFile(filename) else: config_file.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, '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['root']['level'].upper() == 'NONE': # completely disable log config_dict['root']['level'] = 'NOTSET' _disable_logging(config_dict) else: if level is not None: config_dict['root']['level'] = level _set_log_handlers(config_dict, 'default') except (IOError, ValueError, KeyError) as ex: #JSON logging config file parsing error if not quiet: print(('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('Could not open {0} for logging. Using stderr instead.'.\ format(output_file), file=sys.stderr) _set_log_handlers(config_dict, 'to_stderr') _config.dictConfig(config_dict) config_file.set_access_permission(output_file, True)
def configureLogging( level=None, quiet=False, filename=EbLogFile.Name, spec_dir=os.getcwd() + os.path.sep + EbLocalDir.Path ): if not spec_dir: output_file = _getLogFile(filename) else: config_file.create_directory(spec_dir) output_file = spec_dir + os.path.sep + filename ori_path = misc.ori_path() log_config_location = os.path.join(ori_path, "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["root"]["level"].upper() == "NONE": # completely disable log config_dict["root"]["level"] = "NOTSET" _disable_logging(config_dict) else: if level is not None: config_dict["root"]["level"] = level _set_log_handlers(config_dict, "default") except (IOError, ValueError, KeyError) as ex: # JSON logging config file parsing error if not quiet: print( ( '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("Could not open {0} for logging. Using stderr instead.".format(output_file), file=_sys.stderr) _set_log_handlers(config_dict, "to_stderr") _config.dictConfig(config_dict)
def configureLogging(level = None, quiet = False, filename = EbLogFile.Name, spec_dir = os.getcwd() + os.path.sep + EbLocalDir.Path): if not spec_dir: output_file=_getLogFile(filename) else: config_file.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, '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['root']['level'].upper() == 'NONE': # completely disable log config_dict['root']['level'] = 'NOTSET' _disable_logging(config_dict) else: if level is not None: config_dict['root']['level'] = level _set_log_handlers(config_dict, 'default') except (IOError, ValueError, KeyError) as ex: #JSON logging config file parsing error if not quiet: print(('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('Could not open {0} for logging. Using stderr instead.'.\ format(output_file), file=sys.stderr) _set_log_handlers(config_dict, 'to_stderr') _config.dictConfig(config_dict) config_file.set_access_permission(output_file, True)
def execute(self, parameter_pool): func_matrix = [] for param in CredentialFileParameters: if not parameter_pool.has(param[0]): continue elif ParameterSource.is_ahead(ParameterSource.Terminal,\ parameter_pool.get_source(param[0])): continue else: func_matrix.append((param[0], param[2])) if len(func_matrix) < 1: log.info( 'Skipped updating credential file as credentials are not changed.' ) return location = config_file.default_aws_credential_file_location() # Create directory if needed try: config_file.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('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 execute(self, parameter_pool): func_matrix = [] for param in CredentialFileParameters: if not parameter_pool.has(param[0]): continue elif ParameterSource.is_ahead(ParameterSource.Terminal,\ parameter_pool.get_source(param[0])): continue else: func_matrix.append((param[0], param[2])) if len(func_matrix) < 1: log.info('Skipped updating credential file as credentials are not changed.') return location = config_file.default_aws_credential_file_location() # Create directory if needed try: config_file.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('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 create_eb_local_dir(): config_file.create_directory(os.getcwd() + os.path.sep + EbLocalDir.Path)