提交 33a3322a 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!117 针对数据库初始化配置文件格式或内容错误时,命令行中提示信息的修改

Merge pull request !117 from gongzhengtang/master
......@@ -188,12 +188,12 @@ class TableColView(Resource):
('version', 'Version', True),
('release', 'Release', True),
('url', 'Url', True),
('linense', 'License', False),
('rpm_license', 'License', False),
('feature', 'Feature', False),
('maintainer', 'Maintainer', True),
('maintainlevel', 'Maintenance Level', True),
('release_time', 'Release Time', False),
('end_of_lifecycle', 'End of Life Cycle', True),
('used_time', 'Used Time', True),
('maintainer_status', 'Maintain Status', True),
('latest_version', 'Latest Version', False),
('latest_version_time', 'Latest Version Release Time', False),
......
......@@ -85,16 +85,20 @@ class ResponseCode():
TABLE_NAME_NOT_EXIST_IN_DATABASE: "the table name dose not match the existed database",
YAML_FILE_ERROR: "Data error in yaml file",
EMPTY_FOLDER: "This is an empty folder, no yaml file"
}
}
@classmethod
def response_json(cls, code, data=None):
def response_json(cls, code, data=None, msg=None):
"""
Description: classmethod
"""
try:
_msg = cls.CODE_MSG_MAP[code]
except KeyError:
_msg = msg
return {
"code": code,
"msg": cls.CODE_MSG_MAP[code],
"msg": _msg,
"data": data
}
......
......@@ -17,6 +17,7 @@ from packageship.libs.configutils.readconfig import ReadConfig
from packageship.libs.exception import Error
from packageship.libs.exception import ContentNoneException
from packageship.libs.exception import DataMergeException
from packageship.libs.exception import ConfigurationException
from packageship.libs.log import Log
from packageship.system_config import DATABASE_FILE_INFO
from .function.constants import ResponseCode
......@@ -601,6 +602,10 @@ class InitSystem(Resource):
except TypeError as type_error:
LOGGER.logger.error(type_error)
abnormal = ResponseCode.TYPE_ERROR
except ConfigurationException as error:
LOGGER.logger.error(error)
abnormal = error
return jsonify(ResponseCode.response_json('5000', msg=abnormal.message))
except DataMergeException as data_merge_error:
LOGGER.logger.error(data_merge_error)
abnormal = ResponseCode.DATA_MERGE_ERROR
......
......@@ -12,6 +12,7 @@ from packageship.libs.dbutils.sqlalchemy_helper import DBHelper
from packageship.libs.exception import ContentNoneException
from packageship.libs.exception import DatabaseRepeatException
from packageship.libs.exception import Error
from packageship.libs.exception import ConfigurationException
from packageship.libs.configutils.readconfig import ReadConfig
from packageship.libs.log import Log
from packageship.application.models.package import SrcPack
......@@ -90,21 +91,25 @@ class InitDataBase():
init_database_config = yaml.load(
file_context.read(), Loader=yaml.FullLoader)
except yaml.YAMLError as yaml_error:
raise Error(
'The format of the yaml configuration file is wrong, please check and try again\
:%s' % yaml_error)
raise ConfigurationException(' '.join("The format of the yaml configuration\
file is wrong please check and try again:{0}".format(yaml_error).split()))
if init_database_config is None:
raise ContentNoneException(
raise ConfigurationException(
'The content of the database initialization configuration file cannot be empty')
if not isinstance(init_database_config, list):
raise TypeError(
'The format of the initial database configuration file is incorrect:%s'
% self.config_file_path)
raise ConfigurationException(
' '.join('The format of the initial database configuration file\
is incorrect.When multiple databases need to be initialized, \
it needs to be configured in the form of multiple \
nodes:{}'.format(self.config_file_path).split()))
for config_item in init_database_config:
if not isinstance(config_item, dict):
raise TypeError('The format of the initial database configuration file is \
incorrect:%s' % self.config_file_path)
raise ConfigurationException(' '.join('The format of the initial database\
configuration file is incorrect, and the value in a single node should\
be presented in the form of key - val pairs: \
{}'.format(self.config_file_path).split()))
return init_database_config
def init_data(self):
......
......@@ -7,6 +7,11 @@ from packageship.libs.exception.ext import DatabaseRepeatException
from packageship.libs.exception.ext import DataMergeException
from packageship.libs.exception.ext import Error
from packageship.libs.exception.ext import DbnameNoneException
from packageship.libs.exception.ext import ConfigurationException
__all__ = ['ContentNoneException',
'DatabaseRepeatException', 'DataMergeException', 'Error', 'DbnameNoneException']
'DatabaseRepeatException',
'DataMergeException',
'Error',
'DbnameNoneException',
'ConfigurationException']
......@@ -62,3 +62,12 @@ class DataMergeException(Error):
def __init__(self, message):
Error.__init__(self, 'DataMerge exception: %r' % (message,))
class ConfigurationException(Error):
"""
Description: Configuration file exception information
"""
def __init__(self, message):
Error.__init__(self, 'Configuration exception : %r' % (message,))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册