diff --git a/packageship/packageship/application/apps/__init__.py b/packageship/packageship/application/apps/__init__.py index 6a86c78c92c6943cd11840e2b114989bc6bf50ab..0cb8d57f664444dcde627a8b0ec155954847abd0 100644 --- a/packageship/packageship/application/apps/__init__.py +++ b/packageship/packageship/application/apps/__init__.py @@ -5,7 +5,7 @@ Blueprint collection trying to page from packageship.application.apps.package import package, api as package_api blue_point = [ - (package, package_api) + (package, package_api), ] __all__ = ['blue_point'] diff --git a/packageship/packageship/application/apps/package/function/constants.py b/packageship/packageship/application/apps/package/function/constants.py index 7efe41274fccca7c6e135a6abf0af3bb2a0d08be..d201bcd2e4cbed16192a7666fb8a7c869d8c3d2e 100644 --- a/packageship/packageship/application/apps/package/function/constants.py +++ b/packageship/packageship/application/apps/package/function/constants.py @@ -42,6 +42,7 @@ class ResponseCode(): FILE_NOT_FOUND = "4006" # Database operation module error status code DELETE_DB_ERROR = "40051" + SERVICE_ERROR = "50000" CONFIGFILE_PATH_EMPTY = "50001" FAILED_CREATE_DATABASE_TABLE = "50002" TYPE_ERROR = "50003" @@ -64,7 +65,8 @@ class ResponseCode(): TYPE_ERROR: "The source code and binary path types in the initialization file are abnormal", DATA_MERGE_ERROR: "abnormal multi-file database integration", FILE_NOT_FIND_ERROR: "system initialization configuration file does not exist", - DIS_CONNECTION_DB: "Unable to connect to the database, check the database configuration"} + DIS_CONNECTION_DB: "Unable to connect to the database, check the database configuration", + SERVICE_ERROR: "An exception occurred in the system, please try again later"} @classmethod def response_json(cls, code, data=None): diff --git a/packageship/packageship/libs/dbutils/sqlalchemy_helper.py b/packageship/packageship/libs/dbutils/sqlalchemy_helper.py index 228aee2252d88c34574d6951650280adec404e0e..70e3489a5b0b9c7552c7330c218963b570b5c13d 100644 --- a/packageship/packageship/libs/dbutils/sqlalchemy_helper.py +++ b/packageship/packageship/libs/dbutils/sqlalchemy_helper.py @@ -211,6 +211,7 @@ class DBHelper(): self.session.add(entity) except SQLAlchemyError as sql_error: + self.session.rollback() raise Error(sql_error) else: self.session.commit() @@ -246,6 +247,7 @@ class DBHelper(): dicts ) except SQLAlchemyError as sql_error: + self.session.rollback() raise Error(sql_error) else: self.session.commit() diff --git a/packageship/packageship/libs/log/loghelper.py b/packageship/packageship/libs/log/loghelper.py index 190e43a753883685397d865e050111332f9d952b..92294feba490723560439ee2b4ff4f86292e50d6 100644 --- a/packageship/packageship/libs/log/loghelper.py +++ b/packageship/packageship/libs/log/loghelper.py @@ -24,11 +24,13 @@ def setup_log(config=None): _level = 'INFO' logging.basicConfig(level=_level) path = READCONFIG.get_config('LOG', 'log_path') - if path is None: - log_name = READCONFIG.get_config('LOG', 'log_name') - if log_name is None: - log_name = 'log_info.log' + log_name = READCONFIG.get_config('LOG', 'log_name') + if not log_name: + log_name = 'log_info.log' + if not path: path = os.path.join(LOG_FOLDER_PATH, log_name) + else: + path = os.path.join(path, log_name) if not os.path.exists(path): try: os.makedirs(os.path.split(path)[0]) @@ -53,17 +55,20 @@ class Log(): def __init__(self, name=__name__, path=None): self.__name = name - self.__path = path + self.__file_handler = None - if self.__path is None: + + log_name = READCONFIG.get_config('LOG', 'log_name') + if not log_name: + log_name = 'log_info.log' + if path: + self.__path = os.path.join(LOG_FOLDER_PATH, path) + else: self.__path = READCONFIG.get_system('log_path') - log_name = READCONFIG.get_config('LOG', 'log_name') - if log_name is None: - log_name = 'log_info.log' - if self.__path is None: + if not self.__path: self.__path = os.path.join(LOG_FOLDER_PATH, log_name) - else: - self.__path = os.path.join(LOG_FOLDER_PATH, path) + else: + self.__path = os.path.join(self.__path, log_name) if not os.path.exists(self.__path): try: diff --git a/packageship/packageship/package.ini b/packageship/packageship/package.ini index f21decee56deb0a3f37cff6a55f9b12941e2cda0..093b599587e0bbeef4b53ea4d4022106f0e25ea5 100644 --- a/packageship/packageship/package.ini +++ b/packageship/packageship/package.ini @@ -25,6 +25,10 @@ write_ip_addr=127.0.0.1 query_ip_addr=127.0.0.1 +; The address of the remote service, the command line can directly +; call the remote service to complete the data request +remote_host=https://api.openeuler.org/pkgmanage + [DATABASE] diff --git a/packageship/packageship/pkgship.py b/packageship/packageship/pkgship.py index 290ac3cb598e26481d585cae19497ed67109ae19..d5308e5f1fe17a81efdb15d985a11682a49fcf9f 100644 --- a/packageship/packageship/pkgship.py +++ b/packageship/packageship/pkgship.py @@ -84,9 +84,10 @@ class BaseCommand(): wirte_port = self._read_config.get_system('write_port') write_ip = self._read_config.get_system('write_ip_addr') - + if not all([write_ip, wirte_port]): + raise Error( + "The system does not configure the relevant port and ip correctly") _write_host = self.__http + write_ip + ":" + wirte_port - setattr(self, 'write_host', _write_host) def load_read_host(self): @@ -101,10 +102,21 @@ class BaseCommand(): read_port = self._read_config.get_system('query_port') read_ip = self._read_config.get_system('query_ip_addr') + if all([read_ip, read_port]): + _read_host = self.__http + read_ip + ":" + read_port - _read_host = self.__http + read_ip + ":" + read_port + setattr(self, 'read_host', _read_host) - setattr(self, 'read_host', _read_host) + def _set_read_host(self, remote=False): + """ + Set read domain name + """ + if remote: + _host = self._read_config.get_system('remote_host') + self.read_host = _host + if self.read_host is None: + raise Error( + "The system does not configure the relevant port and ip correctly") class PkgshipCommand(BaseCommand): @@ -161,9 +173,9 @@ class PkgshipCommand(BaseCommand): for command_params in self.params: self.parse.add_argument( # pylint: disable=E1101 command_params[0], - type=eval(command_params[1]), # pylint: disable=W0123 help=command_params[2], - default=command_params[3]) + default=command_params[3], + action=command_params[4]) @classmethod def parser_args(cls): @@ -361,7 +373,8 @@ class RemoveCommand(PkgshipCommand): super(RemoveCommand, self).__init__() self.parse = PkgshipCommand.subparsers.add_parser( 'rm', help='delete database operation') - self.params = [('db', 'str', 'name of the database operated', '')] + self.params = [ + ('db', 'str', 'name of the database operated', '', 'store')] def register(self): """ @@ -425,7 +438,7 @@ class InitDatabaseCommand(PkgshipCommand): self.parse = PkgshipCommand.subparsers.add_parser( 'init', help='initialization of the database') self.params = [ - ('-filepath', 'str', 'name of the database operated', '')] + ('-filepath', 'str', 'name of the database operated', '', 'store')] def register(self): """ @@ -486,7 +499,8 @@ class UpdateDatabaseCommand(PkgshipCommand): self.parse = PkgshipCommand.subparsers.add_parser( 'updatedb', help='database update operation') - self.params = [('db', 'str', 'name of the database operated', '')] + self.params = [ + ('db', 'str', 'name of the database operated', '', 'store')] def register(self): """ @@ -533,7 +547,10 @@ class AllPackageCommand(PkgshipCommand): 'list', help='get all package data') self.table = self.create_table( ['packagenames', 'database', 'version', 'license']) - self.params = [('-db', 'str', 'name of the database operated', '')] + self.params = [('-db', 'str', 'name of the database operated', '', 'store'), + ('-remote', 'str', 'The address of the remote service', + False, 'store_true'), + ] def register(self): """ @@ -558,6 +575,7 @@ class AllPackageCommand(PkgshipCommand): Raises: ConnectionError: Request connection error """ + self._set_read_host(params.remote) _url = self.read_host + \ '/packages?dbName={dbName}'.format(dbName=params.db) try: @@ -592,10 +610,10 @@ class UpdatePackageCommand(PkgshipCommand): self.parse = PkgshipCommand.subparsers.add_parser( 'updatepkg', help='update package data') self.params = [ - ('packagename', 'str', 'Source package name', ''), - ('db', 'str', 'name of the database operated', ''), - ('-m', 'str', 'Maintainers name', ''), - ('-l', 'int', 'database priority', 1) + ('packagename', 'str', 'Source package name', '', 'store'), + ('db', 'str', 'name of the database operated', '', 'store'), + ('-m', 'str', 'Maintainers name', '', 'store'), + ('-l', 'int', 'database priority', 1, 'store'), ] def register(self): @@ -664,7 +682,8 @@ class BuildDepCommand(PkgshipCommand): 'builddep', help='query the compilation dependencies of the specified package') self.collection = True self.params = [ - ('packagename', 'str', 'source package name', ''), + ('packagename', 'str', 'source package name', '', 'store'), + ('-remote', 'str', 'The address of the remote service', False, 'store_true') ] self.collection_params = [ ('-dbs', 'Operational database collection') @@ -698,6 +717,8 @@ class BuildDepCommand(PkgshipCommand): Raises: ConnectionError: Request connection error """ + self._set_read_host(params.remote) + _url = self.read_host + '/packages/findBuildDepend' try: response = requests.post( @@ -741,7 +762,8 @@ class InstallDepCommand(PkgshipCommand): 'installdep', help='query the installation dependencies of the specified package') self.collection = True self.params = [ - ('packagename', 'str', 'source package name', ''), + ('packagename', 'str', 'source package name', '', 'store'), + ('-remote', 'str', 'The address of the remote service', False, 'store_true') ] self.collection_params = [ ('-dbs', 'Operational database collection') @@ -829,6 +851,8 @@ class InstallDepCommand(PkgshipCommand): Raises: ConnectionError: requests connection error """ + self._set_read_host(params.remote) + _url = self.read_host + '/packages/findInstallDepend' try: response = requests.post(_url, data=json.dumps( @@ -877,10 +901,11 @@ class SelfBuildCommand(PkgshipCommand): self.src_package_table = self.create_table([ 'src name', 'version', 'database']) self.params = [ - ('packagename', 'str', 'source package name', ''), - ('-t', 'str', 'Source of data query', 'binary'), - ('-w', 'str', 'whether to include other subpackages of binary', 0), - ('-s', 'str', 'whether it is self-compiled', 0) + ('packagename', 'str', 'source package name', '', 'store'), + ('-t', 'str', 'Source of data query', 'binary', 'store'), + ('-w', 'str', 'whether to include other subpackages of binary', 0, 'store'), + ('-s', 'str', 'whether it is self-compiled', 0, 'store'), + ('-remote', 'str', 'The address of the remote service', False, 'store_true') ] self.collection_params = [ @@ -1020,6 +1045,7 @@ class SelfBuildCommand(PkgshipCommand): Raises: ConnectionError: requests connection error """ + self._set_read_host(params.remote) _url = self.read_host + '/packages/findSelfDepend' try: response = requests.post(_url, @@ -1067,9 +1093,10 @@ class BeDependCommand(PkgshipCommand): self.parse = PkgshipCommand.subparsers.add_parser( 'bedepend', help='dependency query for the specified package') self.params = [ - ('packagename', 'str', 'source package name', ''), - ('db', 'str', 'name of the database operated', ''), - ('-w', 'str', 'whether to include other subpackages of binary', 0), + ('packagename', 'str', 'source package name', '', 'store'), + ('db', 'str', 'name of the database operated', '', 'store'), + ('-w', 'str', 'whether to include other subpackages of binary', 0, 'store'), + ('-remote', 'str', 'The address of the remote service', False, 'store_true') ] def register(self): @@ -1095,6 +1122,7 @@ class BeDependCommand(PkgshipCommand): Raises: ConnectionError: requests connection error """ + self._set_read_host(params.remote) _url = self.read_host + '/packages/findBeDepend' try: response = requests.post(_url, data=json.dumps( @@ -1138,8 +1166,9 @@ class SingleCommand(PkgshipCommand): self.parse = PkgshipCommand.subparsers.add_parser( 'single', help='query the information of a single package') self.params = [ - ('packagename', 'str', 'source package name', ''), - ('-db', 'str', 'name of the database operated', '') + ('packagename', 'str', 'source package name', '', 'store'), + ('-db', 'str', 'name of the database operated', '', 'store'), + ('-remote', 'str', 'The address of the remote service', False, 'store_true') ] def register(self): @@ -1195,6 +1224,7 @@ class SingleCommand(PkgshipCommand): Raises: ConnectionError: requests connection error """ + self._set_read_host(params.remote) _url = self.read_host + \ '/packages/packageInfo?dbName={db_name}&sourceName={packagename}' \ .format(db_name=params.db, packagename=params.packagename) diff --git a/packageship/packageship/selfpkg.py b/packageship/packageship/selfpkg.py index b5878168bafa43ee8128e925b182b324798b30b4..f748eb3fb615d2a59a812873bf837329d62a5729 100644 --- a/packageship/packageship/selfpkg.py +++ b/packageship/packageship/selfpkg.py @@ -3,7 +3,6 @@ Description: Entry for project initialization and service startupc """ import os -from flask_script import Manager from packageship.libs.exception import Error from packageship.libs.configutils.readconfig import ReadConfig diff --git a/packageship/pkgship.spec b/packageship/pkgship.spec index 860f3624326e449ab9a8cdff0e7e62121eb1a297..e837b5463219fdfc911407e54b8509b5e0d25130 100644 --- a/packageship/pkgship.spec +++ b/packageship/pkgship.spec @@ -1,6 +1,6 @@ Name: pkgship Version: 1.0 -Release: 4 +Release: 5 Summary: Pkgship implements rpm package dependence ,maintainer, patch query and so no. License: Mulan 2.0 URL: https://gitee.com/openeuler/openEuler-Advisor @@ -61,6 +61,9 @@ rm -rf %{python3_sitelib}/packageship/build %{python3_sitelib}/packageship/dist %changelog +* Mon Aug 10 2020 Zhengtang Gong - 1.0-5 +- Command line supports calling remote services + * Wed Aug 5 2020 Yiru Wang - 1.0-4 - change Requires rpm pakcages' name to latest one