From 5f815b5200aafb26cafdaf62c332f606519b4dc8 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 16:44:17 +0800 Subject: [PATCH 01/25] =?UTF-8?q?=E6=9B=B4=E6=94=B9config=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E7=9A=84=E5=AE=9E=E7=8E=B0=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/__init__.py | 18 +++ .../packageship/application/__init__.py | 11 +- .../apps/lifecycle/function/base.py | 17 --- .../apps/lifecycle/function/download_yaml.py | 65 +++-------- .../apps/lifecycle/function/gitee.py | 15 +-- .../application/apps/lifecycle/url.py | 2 +- .../application/apps/lifecycle/view.py | 17 +-- .../application/initsystem/data_import.py | 31 ++--- .../packageship/application/settings.py | 22 +--- packageship/packageship/libs/conf/__init__.py | 109 ++++++++++++++++++ .../packageship/libs/conf/global_config.py | 95 +++++++++++++++ .../libs/dbutils/sqlalchemy_helper.py | 70 ++++++----- packageship/packageship/libs/log/loghelper.py | 53 +++------ packageship/packageship/manage.py | 32 ++--- packageship/packageship/package.ini | 6 +- packageship/packageship/pkgship.py | 17 +-- packageship/packageship/selfpkg.py | 30 ++--- packageship/setup.py | 1 - 18 files changed, 349 insertions(+), 262 deletions(-) delete mode 100644 packageship/packageship/application/apps/lifecycle/function/base.py create mode 100644 packageship/packageship/libs/conf/__init__.py create mode 100644 packageship/packageship/libs/conf/global_config.py diff --git a/packageship/packageship/__init__.py b/packageship/packageship/__init__.py index e69de29b..009508ee 100644 --- a/packageship/packageship/__init__.py +++ b/packageship/packageship/__init__.py @@ -0,0 +1,18 @@ +#!/usr/bin/python3 +""" +The root path of the project +""" +import os +import sys +from packageship.libs.log import Log + +os.environ["SETTINGS_FILE_PATH"] = '/etc/pkgship/package.ini' + + +# The root directory where the system is running +if getattr(sys, 'frozen', False): + BASE_PATH = os.path.dirname(os.path.realpath(sys.argv[0])) +else: + BASE_PATH = os.path.abspath(os.path.dirname(__file__)) + +LOGGER = Log(__name__) diff --git a/packageship/packageship/application/__init__.py b/packageship/packageship/application/__init__.py index 810d6ce5..f0c78b28 100644 --- a/packageship/packageship/application/__init__.py +++ b/packageship/packageship/application/__init__.py @@ -7,10 +7,10 @@ import threading from flask import Flask from flask_session import Session from flask_apscheduler import APScheduler -from packageship import system_config from packageship.application.settings import Config from packageship.libs.log import setup_log -from packageship.libs.configutils.readconfig import ReadConfig +from packageship.libs.conf import configuration + OPERATION = None @@ -20,13 +20,10 @@ def _timed_task(app): """ from .apps.lifecycle.function.download_yaml import update_pkg_info # pylint: disable=import-outside-toplevel - - _readconfig = ReadConfig(system_config.SYS_CONFIG_PATH) - - _hour = _readconfig.get_config('TIMEDTASK', 'hour') + _hour = configuration.HOUR if not _hour or not isinstance(_hour, int) or _hour < 0 or _hour > 23: _hour = 3 - _minute = _readconfig.get_config('TIMEDTASK', 'minute') + _minute = configuration.MINUTE if not _hour or not isinstance(_hour, int) or _hour < 0 or _hour > 59: _minute = 0 app.apscheduler.add_job( # pylint: disable=no-member diff --git a/packageship/packageship/application/apps/lifecycle/function/base.py b/packageship/packageship/application/apps/lifecycle/function/base.py deleted file mode 100644 index 3631dde4..00000000 --- a/packageship/packageship/application/apps/lifecycle/function/base.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/python3 -""" -General approach to version control tools -""" -from packageship.libs.log import Log - - -class Base(): - """ - Public method to get project tags and download yaml file - """ - - def __init__(self): - self.headers = { - 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW 64; rv:50.0) Gecko/20100101 \ - Firefox / 50.0 '} - self.log = Log(__name__) diff --git a/packageship/packageship/application/apps/lifecycle/function/download_yaml.py b/packageship/packageship/application/apps/lifecycle/function/download_yaml.py index 9e50ba3f..cb18d0e7 100644 --- a/packageship/packageship/application/apps/lifecycle/function/download_yaml.py +++ b/packageship/packageship/application/apps/lifecycle/function/download_yaml.py @@ -12,13 +12,12 @@ import yaml from retrying import retry from sqlalchemy.exc import SQLAlchemyError from requests.exceptions import HTTPError -from packageship import system_config +from packageship import LOGGER +from packageship.libs.conf import configuration from packageship.application.models.package import Packages from packageship.application.models.package import PackagesMaintainer from packageship.libs.dbutils import DBHelper from packageship.libs.exception import Error, ContentNoneException -from packageship.libs.configutils.readconfig import ReadConfig -from .base import Base from .gitee import Gitee from .concurrent import ProducerConsumer @@ -30,46 +29,24 @@ class ParseYaml(): relevant information into the database Attributes: - base: base class instance pkg: Specific package data _table_name: The name of the data table to be operated openeuler_advisor_url: Get the warehouse address of the yaml file _yaml_content: The content of the yaml file """ - def __init__(self, pkg_info, base, table_name): - self.base = base + def __init__(self, pkg_info, table_name): + self.headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW 64; rv:50.0) Gecko/20100101 \ + Firefox / 50.0 '} self.pkg = pkg_info self._table_name = table_name - self.openeuler_advisor_url = self._path_stitching(pkg_info.name) + self.openeuler_advisor_url = configuration.WAREHOUSE_REMOTE + \ + '{pkg_name}.yaml'.format(pkg_name=pkg_info.name) self._yaml_content = None - self.timed_task_open = self._timed_task_status() + self.timed_task_open = configuration.OPEN self.producer_consumer = ProducerConsumer() - def _timed_task_status(self): - """ - The open state of information such as the maintainer in the scheduled task - """ - _timed_task_status = True - _readconfig = ReadConfig(system_config.SYS_CONFIG_PATH) - open_status = _readconfig.get_config('TIMEDTASK', 'open') - if open_status not in ('True', 'False'): - self.base.log.logger.error( - 'Wrong setting of the open state value of the scheduled task') - if open_status == 'False': - self.timed_task_open = False - return _timed_task_status - - def _path_stitching(self, pkg_name): - """ - The path of the remote service call - """ - _readconfig = ReadConfig(system_config.SYS_CONFIG_PATH) - _remote_url = _readconfig.get_config('LIFECYCLE', 'warehouse_remote') - if _remote_url is None: - _remote_url = 'https://gitee.com/openeuler/openEuler-Advisor/raw/master/upstream-info/' - return _remote_url + '{pkg_name}.yaml'.format(pkg_name=pkg_name) - def update_database(self): """ For the current package, determine whether the specific yaml file exists, parse @@ -81,8 +58,8 @@ class ParseYaml(): self._save_to_database() else: msg = "The yaml information of the %s package has not been\ - obtained yet" % self.pkg.name - self.base.log.logger.warning(msg) + obtained yet " % self.pkg.name + LOGGER.logger.warning(msg) def _get_yaml_content(self, url): """ @@ -90,12 +67,12 @@ class ParseYaml(): """ try: response = requests.get( - url, headers=self.base.headers) + url, headers=self.headers) if response.status_code == 200: self._yaml_content = yaml.safe_load(response.content) except HTTPError as error: - self.base.log.logger.error(error) + LOGGER.logger.error(error) def _openeuler_advisor_exists_yaml(self): """ @@ -145,7 +122,7 @@ class ParseYaml(): copy.deepcopy(_packages_maintainer)) _save_maintainer_info() except (Error, ContentNoneException, SQLAlchemyError) as error: - self.base.log.logger.error(error) + LOGGER.logger.error(error) def _parse_warehouse_info(self): """ @@ -179,7 +156,7 @@ class ParseYaml(): self.pkg.used_time = (date.datetime.now() - _end_time).days except (IndexError, Error) as index_error: - self.base.log.logger.error(index_error) + LOGGER.logger.error(index_error) def update_pkg_info(pkg_info_update=True): @@ -188,12 +165,7 @@ def update_pkg_info(pkg_info_update=True): """ try: - base_control = Base() - _readconfig = ReadConfig(system_config.SYS_CONFIG_PATH) - pool_workers = _readconfig.get_config('LIFECYCLE', 'pool_workers') - _warehouse = _readconfig.get_config('LIFECYCLE', 'warehouse') - if _warehouse is None: - _warehouse = 'src-openeuler' + pool_workers = configuration.POOL_WORKERS if not isinstance(pool_workers, int): pool_workers = 10 # Open thread pool @@ -208,14 +180,13 @@ def update_pkg_info(pkg_info_update=True): if pkg_info_update: parse_yaml = ParseYaml( pkg_info=copy.deepcopy(package_item), - base=base_control, table_name=table_name) pool.submit(parse_yaml.update_database) else: # Get the issue of each warehouse and save it gitee_issue = Gitee( - package_item, _warehouse, package_item.name, table_name) + package_item, configuration.WAREHOUSE, package_item.name, table_name) pool.submit(gitee_issue.query_issues_info) pool.shutdown() except SQLAlchemyError as error_msg: - base_control.log.logger.error(error_msg) + LOGGER.logger.error(error_msg) diff --git a/packageship/packageship/application/apps/lifecycle/function/gitee.py b/packageship/packageship/application/apps/lifecycle/function/gitee.py index 5add8671..f6f6f682 100644 --- a/packageship/packageship/application/apps/lifecycle/function/gitee.py +++ b/packageship/packageship/application/apps/lifecycle/function/gitee.py @@ -9,16 +9,12 @@ from retrying import retry import requests from requests.exceptions import HTTPError from sqlalchemy.exc import SQLAlchemyError +from packageship import LOGGER from packageship.libs.dbutils import DBHelper -from packageship.libs.configutils.readconfig import ReadConfig from packageship.libs.exception import Error, ContentNoneException from packageship.application.models.package import PackagesIssue -from packageship import system_config -from packageship.libs.log import Log from .concurrent import ProducerConsumer -LOGGER = Log(__name__) - class Gitee(): """ @@ -30,7 +26,6 @@ class Gitee(): self.pkg_info = pkg_info self.owner = owner self.repo = repo - self._read_config = ReadConfig(system_config.SYS_CONFIG_PATH) self.url = "https://gitee.com/" self.api_url = "https://gitee.com/api/v5/repos" self.pool = None @@ -38,8 +33,6 @@ class Gitee(): self.defect = 0 self.feature = 0 self.cve = 0 - self.patch_files_path = self._read_config.get_system( - "patch_files_path") self.table_name = table_name self.producer_consumer = ProducerConsumer() @@ -54,7 +47,7 @@ class Gitee(): """ issue_url = self.api_url + \ - "/{}/{}/issues/{}".format(self.owner, self.repo, issue_id) + "/{}/{}/issues/{}".format(self.owner, self.repo, issue_id) try: response = requests.get( issue_url, params={"state": "all", "per_page": 100}) @@ -215,10 +208,10 @@ class Gitee(): issue_info_list.append(issue_content) if self.feature != 0: self.defect, self.feature, self.cve = self.pkg_info.defect, self.pkg_info.feature + \ - 1, self.pkg_info.cve + 1, self.pkg_info.cve if self.defect != 0: self.defect, self.feature, self.cve = self.pkg_info.defect + \ - 1, self.pkg_info.feature, self.pkg_info.cve + 1, self.pkg_info.feature, self.pkg_info.cve if self.cve != 0: self.defect, self.feature, self.cve = self.pkg_info.defect, self.pkg_info.feature, self.pkg_info.cve + 1 self._save_issues(issue_info_list) diff --git a/packageship/packageship/application/apps/lifecycle/url.py b/packageship/packageship/application/apps/lifecycle/url.py index 71750d89..7b19965d 100644 --- a/packageship/packageship/application/apps/lifecycle/url.py +++ b/packageship/packageship/application/apps/lifecycle/url.py @@ -17,6 +17,6 @@ urls = [ # pylint: disable=invalid-name (view.IssueType, '/lifeCycle/issuetype', {'query': ('GET')}), (view.IssueStatus, '/lifeCycle/issuestatus', {'query': ('GET')}), (view.IssueCatch, '/lifeCycle/issuecatch', {'write': ('POST')}), -# update a package info + # update a package info (view.UpdatePackages, '/lifeCycle/updatePkgInfo', {'write': ('PUT')}) ] diff --git a/packageship/packageship/application/apps/lifecycle/view.py b/packageship/packageship/application/apps/lifecycle/view.py index efce4bb4..0e41138e 100644 --- a/packageship/packageship/application/apps/lifecycle/view.py +++ b/packageship/packageship/application/apps/lifecycle/view.py @@ -19,21 +19,18 @@ from marshmallow import ValidationError from sqlalchemy.exc import DisconnectionError, SQLAlchemyError -from packageship import system_config -from packageship.libs.configutils.readconfig import ReadConfig +from packageship import LOGGER +from packageship.libs.conf import configuration from packageship.libs.exception import Error from packageship.application.apps.package.function.constants import ResponseCode from packageship.libs.dbutils.sqlalchemy_helper import DBHelper from packageship.application.models.package import PackagesIssue from packageship.application.models.package import Packages from packageship.application.models.package import PackagesMaintainer -from packageship.libs.log import Log from .serialize import IssueDownloadSchema, PackagesDownloadSchema, IssuePageSchema, IssueSchema from ..package.serialize import DataFormatVerfi, UpdatePackagesSchema from .function.gitee import Gitee as gitee -LOGGER = Log(__name__) - # pylint: disable = no-self-use @@ -449,11 +446,8 @@ class IssueCatch(Resource): ResponseCode.response_json(ResponseCode.PARAM_ERROR)) pkg_name = data["repository"]["path"] try: - _readconfig = ReadConfig(system_config.SYS_CONFIG_PATH) - pool_workers = _readconfig.get_config('LIFECYCLE', 'pool_workers') - _warehouse = _readconfig.get_config('LIFECYCLE', 'warehouse') - if _warehouse is None: - _warehouse = 'src-openeuler' + pool_workers = configuration.POOL_WORKERS + _warehouse = configuration.WAREHOUSE if not isinstance(pool_workers, int): pool_workers = 10 pool = ThreadPoolExecutor(max_workers=pool_workers) @@ -550,8 +544,7 @@ class UpdatePackages(Resource): return None try: yaml_data_list = list() - _readconfig = ReadConfig(system_config.SYS_CONFIG_PATH) - pool_workers = _readconfig.get_config('LIFECYCLE', 'pool_workers') + pool_workers = configuration.POOL_WORKERS if not isinstance(pool_workers, int): pool_workers = 10 with ThreadPoolExecutor(max_workers=pool_workers) as pool: diff --git a/packageship/packageship/application/initsystem/data_import.py b/packageship/packageship/application/initsystem/data_import.py index cda86a5c..3eda51b4 100644 --- a/packageship/packageship/application/initsystem/data_import.py +++ b/packageship/packageship/application/initsystem/data_import.py @@ -8,21 +8,18 @@ import os import pathlib import yaml from sqlalchemy.exc import SQLAlchemyError, InternalError +from packageship.libs.conf import configuration 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.configutils.readconfig import ReadConfig -from packageship.libs.log import Log from packageship.application.models.package import SrcPack from packageship.application.models.package import BinPack from packageship.application.models.package import BinRequires from packageship.application.models.package import SrcRequires from packageship.application.models.package import BinProvides from packageship.application.models.package import Packages -from packageship import system_config - -LOGGER = Log(__name__) +from packageship import LOGGER class InitDataBase(): @@ -48,8 +45,7 @@ class InitDataBase(): if self.config_file_path: # yaml configuration file content self.config_file_datas = self.__read_config_file() - self._read_config = ReadConfig(system_config.SYS_CONFIG_PATH) - self.db_type = 'sqlite' + self.db_type = configuration.DATABASE_ENGINE_TYPE self.sql = None self._database = None self._sqlite_db = None @@ -491,9 +487,9 @@ class InitDataBase(): IOError: File or network operation io abnormal """ try: - if not os.path.exists(system_config.DATABASE_FILE_INFO): - pathlib.Path(system_config.DATABASE_FILE_INFO).touch() - with open(system_config.DATABASE_FILE_INFO, 'a+', encoding='utf8') as file_context: + if not os.path.exists(configuration.DATABASE_FILE_INFO): + pathlib.Path(configuration.DATABASE_FILE_INFO).touch() + with open(configuration.DATABASE_FILE_INFO, 'a+', encoding='utf8') as file_context: setting_content = [] if 'database_content' in Kwargs.keys(): content = Kwargs.get('database_content') @@ -520,8 +516,8 @@ class InitDataBase(): """ try: - if os.path.exists(system_config.DATABASE_FILE_INFO): - os.remove(system_config.DATABASE_FILE_INFO) + if os.path.exists(configuration.DATABASE_FILE_INFO): + os.remove(configuration.DATABASE_FILE_INFO) except (IOError, Error) as exception_msg: LOGGER.logger.error(exception_msg) return False @@ -542,14 +538,14 @@ class InitDataBase(): try: del_result = True file_read = open( - system_config.DATABASE_FILE_INFO, 'r', encoding='utf-8') + configuration.DATABASE_FILE_INFO, 'r', encoding='utf-8') _databases = yaml.load( file_read.read(), Loader=yaml.FullLoader) for database in _databases: if database.get('database_name') == db_name: _databases.remove(database) # Delete the successfully imported database configuration node - with open(system_config.DATABASE_FILE_INFO, 'w+', encoding='utf-8') as file_context: + with open(configuration.DATABASE_FILE_INFO, 'w+', encoding='utf-8') as file_context: yaml.safe_dump(_databases, file_context) except (IOError, Error) as del_config_error: LOGGER.logger.error(del_config_error) @@ -694,7 +690,6 @@ class SqliteDatabaseOperations(): kwargs: data related to configuration file nodes """ self.db_name = db_name - self._read_config = ReadConfig(system_config.SYS_CONFIG_PATH) if getattr(kwargs, 'database_path', None) is None: self._database_file_path() else: @@ -711,11 +706,7 @@ class SqliteDatabaseOperations(): Raises: IOError: File or network operation io abnormal """ - self.database_file_folder = self._read_config.get_system( - 'data_base_path') - if not self.database_file_folder: - self.database_file_folder = system_config.DATABASE_FOLDER_PATH - + self.database_file_folder = configuration.DATABASE_FOLDER_PATH if not os.path.exists(self.database_file_folder): try: os.makedirs(self.database_file_folder) diff --git a/packageship/packageship/application/settings.py b/packageship/packageship/application/settings.py index 12d561cb..373512de 100644 --- a/packageship/packageship/application/settings.py +++ b/packageship/packageship/application/settings.py @@ -3,29 +3,25 @@ Description: Basic configuration of flask framework """ import random -from packageship import system_config -from packageship.libs.configutils.readconfig import ReadConfig +from packageship.libs.conf import configuration class Config(): """ Description: Configuration items in a formal environment Attributes: - _read_config: read config - _set_config_val: Set the value of the configuration item + """ SECRET_KEY = None DEBUG = False - LOG_LEVEL = 'INFO' + LOG_LEVEL = configuration.LOG_LEVEL SCHEDULER_API_ENABLED = True def __init__(self): - self._read_config = ReadConfig(system_config.SYS_CONFIG_PATH) - self.set_config_val() @classmethod @@ -36,13 +32,6 @@ class Config(): cls.SECRET_KEY = ''.join( [random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()') for index in range(random_len)]) - @classmethod - def _set_log_level(cls, log_level): - """ - Description: Set the log level - """ - cls.LOG_LEVEL = log_level - def set_config_val(self): """ Description: Set the value of the configuration item @@ -51,8 +40,3 @@ class Config(): Raises: """ Config._random_secret_key() - - log_level = self._read_config.get_config('LOG', 'log_level') - - if log_level: - Config._set_log_level(log_level) diff --git a/packageship/packageship/libs/conf/__init__.py b/packageship/packageship/libs/conf/__init__.py new file mode 100644 index 00000000..54781daa --- /dev/null +++ b/packageship/packageship/libs/conf/__init__.py @@ -0,0 +1,109 @@ +#!/usr/bin/python3 +""" +System configuration file and default configuration file integration +""" +import os +import configparser + +from packageship.libs.exception import Error +from . import global_config + + +USER_SETTINGS_FILE_PATH = 'SETTINGS_FILE_PATH' + + +class PreloadingSettings(): + """ + The system default configuration file and the configuration + file changed by the user are lazily loaded. + """ + _setting_container = None + + def _preloading(self): + """ + Load the default configuration in the system and the related configuration + of the user, and overwrite the default configuration items of the system + with the user's configuration data + """ + settings_file = os.environ.get(USER_SETTINGS_FILE_PATH) + if not settings_file: + raise Error( + "The system does not specify the user configuration" + "that needs to be loaded:" % USER_SETTINGS_FILE_PATH) + + self._setting_container = Configs(settings_file) + + def __getattr__(self, name): + """ + Return the value of a setting and cache it in self.__dict__ + """ + if self._setting_container is None: + self._preloading() + value = getattr(self._setting_container, name, None) + self.__dict__[name] = value + return value + + def __setattr__(self, name, value): + """ + Set the configured value and re-copy the value cached in __dict__ + """ + if name is None: + raise KeyError("The set configuration key value cannot be empty") + if name == '_setting_container': + self.__dict__.clear() + self.__dict__["_setting_container"] = value + else: + self.__dict__.pop(name, None) + if self._setting_container is None: + self._preloading() + setattr(self._setting_container, name, value) + + def __delattr__(self, name): + """ + Delete a setting and clear it from cache if needed + """ + if name is None: + raise KeyError("The set configuration key value cannot be empty") + + if self._setting_container is None: + self._preloading() + delattr(self._setting_container, name) + self.__dict__.pop(name, None) + + @property + def config_ready(self): + """ + Return True if the settings have already been configured + """ + return self._setting_container is not None + + +class Configs(): + """ + The system's default configuration items and the user's + configuration items are integrated + """ + + def __init__(self, settings_file): + for config in dir(global_config): + if not config.startswith('_'): + setattr(self, config, getattr(global_config, config)) + + # Load user's configuration + self._conf_parser = configparser.ConfigParser() + self._conf_parser.read(settings_file) + + for section in self._conf_parser.sections(): + for option in self._conf_parser.items(section): + try: + _config_value = option[1] + _key = option[0] + except IndexError: + pass + else: + if not isinstance(_config_value, (int, bool)) and not _config_value: + continue + setattr(self, _key.upper(), _config_value) + + +configuration = PreloadingSettings() # pylint: disable=invalid-name diff --git a/packageship/packageship/libs/conf/global_config.py b/packageship/packageship/libs/conf/global_config.py new file mode 100644 index 00000000..a470d987 --- /dev/null +++ b/packageship/packageship/libs/conf/global_config.py @@ -0,0 +1,95 @@ +#!/usr/bin/python3 +""" +Global environment variable value when the system is running +""" + +import os + +# Configuration file path for data initialization +INIT_CONF_PATH = os.path.join('/', 'etc', 'pkgship', 'conf.yaml') + + +# data file after successful data import +DATABASE_FILE_INFO = os.path.join( + '/', 'var', 'run', 'database_file_info.yaml') + +# If the path of the imported database is not specified in the configuration file, the +# configuration in the system is used by default +DATABASE_FOLDER_PATH = os.path.join('/', 'var', 'run', 'pkgship_dbs') + + +DATABASE_ENGINE_TYPE = 'sqlite' + +# If the directory of log storage is not configured, +# it will be stored in the following directory specified by the system by default +LOG_FOLDER_PATH = os.path.join('/', 'var', 'log', 'logs') + + +# Port managed by the administrator, with write permission + +WRITE_PORT = 8080 + +# Ordinary user query port, only the right to query data, no permission to write data + +QUERY_PORT = 8090 + +# IP address path with write permission + +WRITE_HOST = '127.0.0.1' + +# IP address path with permission to query data + +QUERY_HOST = '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' + +# Custom log storage path +LOG_PATH = os.path.join('/', 'var', 'log', 'pkgship') + +# Logging level +# The log level option value can only be as follows +# INFO DEBUG WARNING ERROR CRITICAL +LOG_LEVEL = 'INFO' + +# logging name +LOG_NAME = 'log_info.log' + +# The number of dynamically created logs +# after the log file size reaches the upper limit. The default is 10 dynamically created logs +BACKUP_COUNT = 10 + +# The size of each log file, in bytes, the default size of a single log file is 300M +MAX_BYTES = 314572800 + +# Execution frequency and switch of timing tasks +# Whether to execute the switch for batch update of information such +# as the maintainer during initialization. When set to True, the maintainer +# and other information will be updated when the scheduled task starts +# to execute. When it is set to False, it will be updated when the scheduled +# task is executed. , Does not update information such as maintainers and maintenance levels + +OPEN = True + +# The time point at which the timing task is executed in a cycle. +# Every day is a cycle, and the time value can only be any integer period between 0 and 23 +HOUR = 3 + +# Recurring timing task starts to execute the task at the current time point. +# The value range of this configuration item is an integer between 0 and 59 +MINUTE = 0 + +# Configuration during the life cycle for tag information, issue and other information acquisition +# The yaml address of each package is stored in the remote address, which can be +# a remote warehouse address or the address of a static resource service +WAREHOUSE_REMOTE = 'https://gitee.com/wu_fengguang/openEuler-Advisor/raw/master/upstream-info/' + +# When performing timing tasks, you can open multi-threaded execution, and you can set +# the number of threads in the thread pool according to the configuration of the server + +POOL_WORKERS = 10 + +# The main body of the warehouse, the owner of the warehouse +# When this value is not set, the system will default to src-openeuler +WAREHOUSE = 'src-openeuler' diff --git a/packageship/packageship/libs/dbutils/sqlalchemy_helper.py b/packageship/packageship/libs/dbutils/sqlalchemy_helper.py index a0b22e2f..6291a494 100644 --- a/packageship/packageship/libs/dbutils/sqlalchemy_helper.py +++ b/packageship/packageship/libs/dbutils/sqlalchemy_helper.py @@ -14,8 +14,7 @@ from sqlalchemy.engine.url import URL from packageship.libs.exception.ext import Error from packageship.libs.exception.ext import DbnameNoneException from packageship.libs.exception.ext import ContentNoneException -from packageship.libs.configutils.readconfig import ReadConfig -from packageship import system_config +from packageship.libs.conf import configuration class BaseHelper(): @@ -24,7 +23,6 @@ class BaseHelper(): """ def __init__(self): - self.readconfig = ReadConfig(system_config.SYS_CONFIG_PATH) self.engine = None @@ -43,12 +41,11 @@ class MysqlHelper(BaseHelper): def __init__(self, user_name=None, password=None, host=None, # pylint: disable=unused-argument port=None, database=None, **kwargs): super(MysqlHelper, self).__init__() - self.user_name = user_name or self.readconfig.get_database( - 'user_name') - self.password = password or self.readconfig.get_database('password') - self.host = host or self.readconfig.get_database('host') - self.port = port or self.readconfig.get_database('port') - self.database = database or self.readconfig.get_database('database') + self.user_name = user_name or configuration.USER_NAME + self.password = password or configuration.PASSWORD + self.host = host or configuration.HOST + self.port = port or configuration.PORT + self.database = database or configuration.DATABASE self.connection_type = 'mysql+pymysql' def create_database_engine(self): @@ -100,10 +97,7 @@ class SqliteHlper(BaseHelper): Raises: """ - _database_folder_path = self.readconfig.get_system( - 'data_base_path') - if not _database_folder_path: - _database_folder_path = system_config.DATABASE_FOLDER_PATH + _database_folder_path = configuration.DATABASE_FOLDER_PATH try: if not os.path.exists(_database_folder_path): os.makedirs(_database_folder_path) @@ -143,6 +137,7 @@ class DBHelper(BaseHelper): """ # The base class inherited by the data model BASE = declarative_base() + ENGINE_CONTAINER = dict() def __init__(self, user_name=None, password=None, host=None, # pylint: disable=R0913 port=None, db_name=None, connection_type=None, **kwargs): @@ -155,18 +150,39 @@ class DBHelper(BaseHelper): 'mysql': MysqlHelper, 'sqlite': SqliteHlper } + if connection_type is None: - connection_type = self.readconfig.get_database( - 'dbtype') or 'sqlite' + connection_type = configuration.DATABASE_ENGINE_TYPE + self._engine_pool = connection_type + '_' + db_name _database_engine = self._database_engine.get(connection_type) if _database_engine is None: - raise DisconnectionError('') - _engine = _database_engine(user_name=user_name, password=password, - host=host, port=port, database=db_name, **kwargs) - _engine.create_database_engine() - self.engine = _engine.engine + raise DisconnectionError( + 'Database engine connection failed' + 'Not currently supported %s database' % connection_type) + _engine = self.ENGINE_CONTAINER.get(self._engine_pool) + if _engine: + self.engine = _engine + else: + _engine = _database_engine(user_name=user_name, password=password, + host=host, port=port, database=db_name, **kwargs) + _engine.create_database_engine() + self.engine = _engine.engine + self.ENGINE_CONTAINER[self._engine_pool] = self.engine self.session = None + def create_engine(self): + """ + Create related database engine connections + """ + session = sessionmaker() + try: + session.configure(bind=self.engine) + except DisconnectionError: + self.ENGINE_CONTAINER.pop(self._engine_pool) + else: + self.session = session() + return self + def __enter__(self): """ Description: functional description:Create a context manager for the database connection @@ -178,13 +194,8 @@ class DBHelper(BaseHelper): """ - session = sessionmaker() - if not hasattr(self, 'engine'): - raise DisconnectionError('Abnormal database connection') - session.configure(bind=self.engine) - - self.session = session() - return self + database_engine = self.create_engine() + return database_engine def __exit__(self, exc_type, exc_val, exc_tb): """ @@ -199,6 +210,9 @@ class DBHelper(BaseHelper): Raises: """ + if isinstance(exc_type, (AttributeError)): + raise SQLAlchemyError(exc_val) + self.session.close() @classmethod @@ -246,10 +260,8 @@ class DBHelper(BaseHelper): if entity is None: raise ContentNoneException( 'The added entity content cannot be empty') - try: self.session.add(entity) - except SQLAlchemyError as sql_error: self.session.rollback() raise Error(sql_error) diff --git a/packageship/packageship/libs/log/loghelper.py b/packageship/packageship/libs/log/loghelper.py index fc53bb21..7cf1c087 100644 --- a/packageship/packageship/libs/log/loghelper.py +++ b/packageship/packageship/libs/log/loghelper.py @@ -6,38 +6,26 @@ import os import pathlib import logging from concurrent_log_handler import ConcurrentRotatingFileHandler -from packageship import system_config -from packageship.libs.configutils.readconfig import ReadConfig - - -READCONFIG = ReadConfig(system_config.SYS_CONFIG_PATH) +from packageship.libs.conf import configuration def setup_log(config=None): """ Log logging in the context of flask """ + _level = configuration.LOG_LEVEL if config: - logging.basicConfig(level=config.LOG_LEVEL) - else: - _level = READCONFIG.get_config('LOG', 'log_level') - if _level is None: - _level = 'INFO' - logging.basicConfig(level=_level) - path = READCONFIG.get_config('LOG', 'log_path') - log_name = READCONFIG.get_config('LOG', 'log_name') - backup_count = READCONFIG.get_config('LOG', 'backup_count') + _level = config.LOG_LEVEL + logging.basicConfig(level=_level) + backup_count = configuration.BACKUP_COUNT if not backup_count or not isinstance(backup_count, int): backup_count = 10 - max_bytes = READCONFIG.get_config('LOG', 'max_bytes') + max_bytes = configuration.MAX_BYTES if not max_bytes or not isinstance(max_bytes, int): max_bytes = 314572800 - if not log_name: - log_name = 'log_info.log' - if not path: - path = os.path.join(system_config.LOG_FOLDER_PATH, log_name) - else: - path = os.path.join(path, log_name) + + path = os.path.join(configuration.LOG_PATH, configuration.LOG_NAME) + if not os.path.exists(path): try: os.makedirs(os.path.split(path)[0]) @@ -65,33 +53,24 @@ class Log(): self.__file_handler = None - log_name = READCONFIG.get_config('LOG', 'log_name') - if not log_name: - log_name = 'log_info.log' + self.__path = os.path.join( + configuration.LOG_PATH, configuration.LOG_NAME) if path: - self.__path = os.path.join(system_config.LOG_FOLDER_PATH, path) - else: - self.__path = READCONFIG.get_config('LOG', 'log_path') - if not self.__path: - self.__path = os.path.join( - system_config.LOG_FOLDER_PATH, log_name) - else: - self.__path = os.path.join(self.__path, log_name) + self.__path = path if not os.path.exists(self.__path): try: os.makedirs(os.path.split(self.__path)[0]) except FileExistsError: pathlib.Path(self.__path).touch() - self.__level = READCONFIG.get_config('LOG', 'log_level') - if self.__level is None: - self.__level = 'INFO' + + self.__level = configuration.LOG_LEVEL self.__logger = logging.getLogger(self.__name) self.__logger.setLevel(self.__level) - self.backup_count = READCONFIG.get_config('LOG', 'backup_count') + self.backup_count = configuration.BACKUP_COUNT if not self.backup_count or not isinstance(self.backup_count, int): self.backup_count = 10 - self.max_bytes = READCONFIG.get_config('LOG', 'max_bytes') + self.max_bytes = configuration.MAX_BYTES if not self.max_bytes or not isinstance(self.max_bytes, int): self.max_bytes = 314572800 diff --git a/packageship/packageship/manage.py b/packageship/packageship/manage.py index 25d8aa77..01f6525b 100644 --- a/packageship/packageship/manage.py +++ b/packageship/packageship/manage.py @@ -3,27 +3,14 @@ Description: Entry for project initialization and service startupc """ import os -from packageship.libs.exception import Error -try: - from packageship import system_config - if not os.path.exists(system_config.SYS_CONFIG_PATH): - raise FileNotFoundError( - 'the system configuration file does not exist and the log cannot be started') -except FileNotFoundError as file_not_found: - from packageship.libs.log.loghelper import Log - Log(__name__).logger.error(file_not_found) - raise Exception( - 'the system configuration file does not exist and the log cannot be started') -else: - from packageship.libs.configutils.readconfig import ReadConfig - from packageship.application import init_app -try: - app = init_app('write') -except Error as error: - raise Exception('Service failed to start') -else: - from packageship.application.app_global import identity_verification +from packageship.application.app_global import identity_verification + + +if not os.path.exists(os.environ.get('SETTINGS_FILE_PATH')): + raise FileNotFoundError( + 'the system configuration file does not exist and the log cannot be started') +app = init_app('write') @app.before_request @@ -36,7 +23,4 @@ def before_request(): if __name__ == "__main__": - _readconfig = ReadConfig(system_config.SYS_CONFIG_PATH) - port = _readconfig.get_system('write_port') - addr = _readconfig.get_system('write_ip_addr') - app.run(port=port, host=addr) + app.run() diff --git a/packageship/packageship/package.ini b/packageship/packageship/package.ini index e0f4f472..12785563 100644 --- a/packageship/packageship/package.ini +++ b/packageship/packageship/package.ini @@ -4,7 +4,7 @@ init_conf_path=/etc/pkgship/conf.yaml ; Where to store data files when using sqlite database -; data_base_path=/var/run/pkgship_dbs +; database_folder_path=/var/run/pkgship_dbs ; Port managed by the administrator, with write permission @@ -16,11 +16,11 @@ query_port=8090 ; IP address path with write permission -write_ip_addr=127.0.0.1 +write_host=127.0.0.1 ; IP address path with permission to query data -query_ip_addr=127.0.0.1 +query_host=127.0.0.1 ; The address of the remote service, the command line can directly ; call the remote service to complete the data request diff --git a/packageship/packageship/pkgship.py b/packageship/packageship/pkgship.py index ea32b527..9f4030ff 100644 --- a/packageship/packageship/pkgship.py +++ b/packageship/packageship/pkgship.py @@ -17,12 +17,8 @@ try: from requests.exceptions import HTTPError import prettytable from prettytable import PrettyTable - from packageship import system_config - from packageship.libs.log import Log from packageship.libs.exception import Error - from packageship.libs.configutils.readconfig import ReadConfig - - LOGGER = Log(__name__) + from packageship.libs.conf import configuration except ImportError as import_error: print('Error importing related dependencies, \ please check if related dependencies are installed') @@ -66,7 +62,6 @@ class BaseCommand(): Description: Class instance initialization """ - self._read_config = ReadConfig(system_config.SYS_CONFIG_PATH) self.write_host = None self.read_host = None self.__http = 'http://' @@ -85,9 +80,9 @@ class BaseCommand(): Raises: """ - wirte_port = self._read_config.get_system('write_port') + wirte_port = configuration.WRITE_PORT - write_ip = self._read_config.get_system('write_ip_addr') + write_ip = configuration.WRITE_HOST if not all([write_ip, wirte_port]): raise Error( "The system does not configure the relevant port and ip correctly") @@ -103,9 +98,9 @@ class BaseCommand(): Raises: """ - read_port = self._read_config.get_system('query_port') + read_port = configuration.QUERY_PORT - read_ip = self._read_config.get_system('query_ip_addr') + read_ip = configuration.QUERY_HOST if all([read_ip, read_port]): _read_host = self.__http + read_ip + ":" + read_port @@ -116,7 +111,7 @@ class BaseCommand(): Set read domain name """ if remote: - _host = self._read_config.get_system('remote_host') + _host = configuration.REMOTE_HOST self.read_host = _host if self.read_host is None: raise Error( diff --git a/packageship/packageship/selfpkg.py b/packageship/packageship/selfpkg.py index b8895531..cf758dd5 100644 --- a/packageship/packageship/selfpkg.py +++ b/packageship/packageship/selfpkg.py @@ -3,27 +3,14 @@ Description: Entry for project initialization and service startupc """ import os -from packageship.libs.exception import Error -from packageship.libs.configutils.readconfig import ReadConfig +from packageship.application import init_app +from packageship.application.app_global import identity_verification -try: - from packageship import system_config - if not os.path.exists(system_config.SYS_CONFIG_PATH): - raise FileNotFoundError( - 'the system configuration file does not exist and the log cannot be started') -except FileNotFoundError as file_not_found: - from packageship.libs.log.loghelper import Log - Log(__name__).logger.error(file_not_found) - raise Exception( - 'the system configuration file does not exist and the log cannot be started') -from packageship.application import init_app -try: - app = init_app('query') -except Error as error: - raise Exception('Service failed to start') -else: - from packageship.application.app_global import identity_verification +if not os.path.exists(os.environ.get('SETTINGS_FILE_PATH')): + raise FileNotFoundError( + 'the system configuration file does not exist and the log cannot be started') +app = init_app('query') @app.before_request @@ -36,7 +23,4 @@ def before_request(): if __name__ == "__main__": - _readconfig = ReadConfig(system_config.SYS_CONFIG_PATH) - port = _readconfig.get_system('query_port') - addr = _readconfig.get_system('query_ip_addr') - app.run(port=port, host=addr) + app.run() diff --git a/packageship/setup.py b/packageship/setup.py index 346a0c62..03ad5fce 100644 --- a/packageship/setup.py +++ b/packageship/setup.py @@ -24,7 +24,6 @@ setup( 'packageship.application.apps.package.function.packages', 'packageship.application.apps.package.function.searchdb', 'packageship.application.apps.package.function.self_depend', - 'packageship.application.apps.lifecycle.function.base', 'packageship.application.apps.lifecycle.function.download_yaml', 'packageship.application.apps.lifecycle.function.gitee', 'packageship.application.apps.lifecycle.function.concurrent', -- Gitee From 2b6eae3cf6fe0e61a1377a9548de066cc58c71a3 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 16:50:18 +0800 Subject: [PATCH 02/25] =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=E4=B8=AD?= =?UTF-8?q?=E7=9A=84logger=E6=97=A5=E5=BF=97=E5=87=BD=E6=95=B0=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/pkgship.py | 1 + 1 file changed, 1 insertion(+) diff --git a/packageship/packageship/pkgship.py b/packageship/packageship/pkgship.py index 9f4030ff..d50ce771 100644 --- a/packageship/packageship/pkgship.py +++ b/packageship/packageship/pkgship.py @@ -17,6 +17,7 @@ try: from requests.exceptions import HTTPError import prettytable from prettytable import PrettyTable + from packageship import LOGGER from packageship.libs.exception import Error from packageship.libs.conf import configuration except ImportError as import_error: -- Gitee From 75d6c18b6ac3d6c5ce4ed2fe3934e04f2470bbbf Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 17:06:35 +0800 Subject: [PATCH 03/25] =?UTF-8?q?log=E6=97=A5=E5=BF=97=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E5=8C=85=E6=9C=AA=E5=BC=95=E5=85=A5=EF=BC=8C=E6=9A=82?= =?UTF-8?q?=E6=97=B6=E6=9B=B4=E6=94=B9=E4=B8=BA=E4=B9=8B=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E6=97=A5=E5=BF=97=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/libs/log/loghelper.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packageship/packageship/libs/log/loghelper.py b/packageship/packageship/libs/log/loghelper.py index 7cf1c087..2dbb40d5 100644 --- a/packageship/packageship/libs/log/loghelper.py +++ b/packageship/packageship/libs/log/loghelper.py @@ -5,7 +5,8 @@ Logging related import os import pathlib import logging -from concurrent_log_handler import ConcurrentRotatingFileHandler +from logging.handlers import RotatingFileHandler +# from concurrent_log_handler import ConcurrentRotatingFileHandler from packageship.libs.conf import configuration @@ -32,7 +33,7 @@ def setup_log(config=None): except FileExistsError: pathlib.Path(path).touch() - file_log_handler = ConcurrentRotatingFileHandler( + file_log_handler = RotatingFileHandler( path, maxBytes=max_bytes, backupCount=backup_count) formatter = logging.Formatter( @@ -75,7 +76,7 @@ class Log(): self.max_bytes = 314572800 def __init_handler(self): - self.__file_handler = ConcurrentRotatingFileHandler( + self.__file_handler = RotatingFileHandler( self.__path, maxBytes=self.max_bytes, backupCount=self.backup_count, encoding="utf-8") def __set_handler(self): -- Gitee From 2d05ca9dc0d8aa51c44edf75ffe9149bbcce43bd Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 17:39:41 +0800 Subject: [PATCH 04/25] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E4=B8=AD=E9=92=88?= =?UTF-8?q?=E5=AF=B9=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E9=A1=B9=E7=9A=84?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/test/common_files/conf.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packageship/test/common_files/conf.yaml b/packageship/test/common_files/conf.yaml index 190b6f7f..1a2d9df2 100644 --- a/packageship/test/common_files/conf.yaml +++ b/packageship/test/common_files/conf.yaml @@ -2,9 +2,9 @@ dbname: mainline priority: 1 src_db_file: - status: enable + lifecycle: enable - bin_db_file: dbname: fedora30 priority: 2 src_db_file: - status: enable + lifecycle: enable -- Gitee From 81b116a84bfcc2f7bc248fee3a04b05e575c9c87 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 17:58:52 +0800 Subject: [PATCH 05/25] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=AD=E5=A2=9E=E5=8A=A0log=5Fpath=E7=9A=84=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/test/common_files/package.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/packageship/test/common_files/package.ini b/packageship/test/common_files/package.ini index b312707c..3261a7ee 100644 --- a/packageship/test/common_files/package.ini +++ b/packageship/test/common_files/package.ini @@ -17,6 +17,7 @@ dbtype = sqlite [LOG] log_level = INFO log_name = log_info.log +log_path=/var/log/pkgship [UWSGI] daemonize = /var/log/uwsgi.log -- Gitee From 7610887fd31f477ddf1a31ba730f99e4fbbd20c8 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 18:04:54 +0800 Subject: [PATCH 06/25] =?UTF-8?q?=E6=9B=B4=E6=94=B9log=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/package.ini | 2 +- packageship/pkgship.spec | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packageship/packageship/package.ini b/packageship/packageship/package.ini index 12785563..32d01764 100644 --- a/packageship/packageship/package.ini +++ b/packageship/packageship/package.ini @@ -29,7 +29,7 @@ remote_host=https://api.openeuler.org/pkgmanage [LOG] ; Custom log storage path -; log_path=/var/log/pkgship/ +log_path=/var/log/pkgship/ ; Logging level ; The log level option value can only be as follows diff --git a/packageship/pkgship.spec b/packageship/pkgship.spec index 8a7adbc5..301bacd7 100644 --- a/packageship/pkgship.spec +++ b/packageship/pkgship.spec @@ -35,6 +35,7 @@ export TZ=Asia/Shanghai # change log_path to solve default log_path permission denied problem log_path=`pwd`/tmp/ sed -i "/\[LOG\]/a\log_path=$log_path" test/common_files/package.ini +sed -i "/\[LOG\]/a\log_path=$log_path" packageship/package.ini %{__python3} -m unittest test/init_test.py %{__python3} -m unittest test/read_test.py %{__python3} -m unittest test/write_test.py -- Gitee From 1d4a93fbd566ddfe6846fedcf33e79c85a823658 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 18:08:52 +0800 Subject: [PATCH 07/25] =?UTF-8?q?log=E6=97=A5=E5=BF=97=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E7=9A=84=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/libs/conf/global_config.py | 2 +- packageship/packageship/package.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packageship/packageship/libs/conf/global_config.py b/packageship/packageship/libs/conf/global_config.py index a470d987..21cbc6b0 100644 --- a/packageship/packageship/libs/conf/global_config.py +++ b/packageship/packageship/libs/conf/global_config.py @@ -46,7 +46,7 @@ QUERY_HOST = '127.0.0.1' REMOTE_HOST = 'https://api.openeuler.org/pkgmanage' # Custom log storage path -LOG_PATH = os.path.join('/', 'var', 'log', 'pkgship') +LOG_PATH = os.path.join('/', 'tmp') # Logging level # The log level option value can only be as follows diff --git a/packageship/packageship/package.ini b/packageship/packageship/package.ini index 32d01764..e5eef47a 100644 --- a/packageship/packageship/package.ini +++ b/packageship/packageship/package.ini @@ -29,7 +29,7 @@ remote_host=https://api.openeuler.org/pkgmanage [LOG] ; Custom log storage path -log_path=/var/log/pkgship/ +log_path=/tmp/ ; Logging level ; The log level option value can only be as follows -- Gitee From 5ba7e85c404fd99ace89bacb44c1f27b8250ba60 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 18:11:47 +0800 Subject: [PATCH 08/25] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84log=E8=B7=AF=E5=BE=84=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/test/common_files/package.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/packageship/test/common_files/package.ini b/packageship/test/common_files/package.ini index 3261a7ee..b312707c 100644 --- a/packageship/test/common_files/package.ini +++ b/packageship/test/common_files/package.ini @@ -17,7 +17,6 @@ dbtype = sqlite [LOG] log_level = INFO log_name = log_info.log -log_path=/var/log/pkgship [UWSGI] daemonize = /var/log/uwsgi.log -- Gitee From a6b13f1a44eefc2f0112bf4a108af90df0b6d7b5 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 18:12:21 +0800 Subject: [PATCH 09/25] =?UTF-8?q?spec=E6=96=87=E4=BB=B6=E7=9A=84=E6=9B=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/pkgship.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/packageship/pkgship.spec b/packageship/pkgship.spec index 301bacd7..8a7adbc5 100644 --- a/packageship/pkgship.spec +++ b/packageship/pkgship.spec @@ -35,7 +35,6 @@ export TZ=Asia/Shanghai # change log_path to solve default log_path permission denied problem log_path=`pwd`/tmp/ sed -i "/\[LOG\]/a\log_path=$log_path" test/common_files/package.ini -sed -i "/\[LOG\]/a\log_path=$log_path" packageship/package.ini %{__python3} -m unittest test/init_test.py %{__python3} -m unittest test/read_test.py %{__python3} -m unittest test/write_test.py -- Gitee From 0e4419091fb5dffbd10796b12322b7a2197f446c Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 18:12:21 +0800 Subject: [PATCH 10/25] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/pkgship.spec | 1 - packageship/test/read_test.py | 1 + packageship/test/write_test.py | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packageship/pkgship.spec b/packageship/pkgship.spec index 301bacd7..8a7adbc5 100644 --- a/packageship/pkgship.spec +++ b/packageship/pkgship.spec @@ -35,7 +35,6 @@ export TZ=Asia/Shanghai # change log_path to solve default log_path permission denied problem log_path=`pwd`/tmp/ sed -i "/\[LOG\]/a\log_path=$log_path" test/common_files/package.ini -sed -i "/\[LOG\]/a\log_path=$log_path" packageship/package.ini %{__python3} -m unittest test/init_test.py %{__python3} -m unittest test/read_test.py %{__python3} -m unittest test/write_test.py diff --git a/packageship/test/read_test.py b/packageship/test/read_test.py index 16eb5b9d..fc296c50 100644 --- a/packageship/test/read_test.py +++ b/packageship/test/read_test.py @@ -1,5 +1,6 @@ import unittest import datetime +import packageship from test.base_code.my_test_runner import MyTestRunner RUNNER = MyTestRunner() diff --git a/packageship/test/write_test.py b/packageship/test/write_test.py index dded68e6..eafbcac3 100644 --- a/packageship/test/write_test.py +++ b/packageship/test/write_test.py @@ -5,6 +5,7 @@ Execute all test cases """ import unittest import datetime +import packageship from test.base_code.my_test_runner import MyTestRunner RUNNER = MyTestRunner() -- Gitee From 0ec6d71d737cc0dbb0fc1450e077978a0accb750 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 18:29:40 +0800 Subject: [PATCH 11/25] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/manage.py | 3 ++- packageship/packageship/selfpkg.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packageship/packageship/manage.py b/packageship/packageship/manage.py index 01f6525b..0a3bf9b0 100644 --- a/packageship/packageship/manage.py +++ b/packageship/packageship/manage.py @@ -9,7 +9,8 @@ from packageship.application.app_global import identity_verification if not os.path.exists(os.environ.get('SETTINGS_FILE_PATH')): raise FileNotFoundError( - 'the system configuration file does not exist and the log cannot be started') + 'System configuration file:%s' % os.environ.get('SETTINGS_FILE_PATH'), + 'does not exist, software service cannot be started') app = init_app('write') diff --git a/packageship/packageship/selfpkg.py b/packageship/packageship/selfpkg.py index cf758dd5..cc175494 100644 --- a/packageship/packageship/selfpkg.py +++ b/packageship/packageship/selfpkg.py @@ -9,7 +9,8 @@ from packageship.application.app_global import identity_verification if not os.path.exists(os.environ.get('SETTINGS_FILE_PATH')): raise FileNotFoundError( - 'the system configuration file does not exist and the log cannot be started') + 'System configuration file:%s' % os.environ.get('SETTINGS_FILE_PATH'), + 'does not exist, software service cannot be started') app = init_app('query') -- Gitee From f005315d673c5fbbe1a2cff12927d5ba002e67c4 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 18:52:13 +0800 Subject: [PATCH 12/25] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/test/base_code/read_data_base.py | 5 ++++- packageship/test/read_test.py | 1 - packageship/test/write_test.py | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packageship/test/base_code/read_data_base.py b/packageship/test/base_code/read_data_base.py index 8e6a4c0f..47b6c30b 100644 --- a/packageship/test/base_code/read_data_base.py +++ b/packageship/test/base_code/read_data_base.py @@ -8,7 +8,10 @@ from .basetest import TestBase from packageship.libs.exception import Error try: from packageship import system_config - + os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), + 'test', + 'common_files', + 'package.ini') system_config.SYS_CONFIG_PATH = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', 'common_files', diff --git a/packageship/test/read_test.py b/packageship/test/read_test.py index fc296c50..16eb5b9d 100644 --- a/packageship/test/read_test.py +++ b/packageship/test/read_test.py @@ -1,6 +1,5 @@ import unittest import datetime -import packageship from test.base_code.my_test_runner import MyTestRunner RUNNER = MyTestRunner() diff --git a/packageship/test/write_test.py b/packageship/test/write_test.py index eafbcac3..dded68e6 100644 --- a/packageship/test/write_test.py +++ b/packageship/test/write_test.py @@ -5,7 +5,6 @@ Execute all test cases """ import unittest import datetime -import packageship from test.base_code.my_test_runner import MyTestRunner RUNNER = MyTestRunner() -- Gitee From 668e072dc9cc1e6aa54f6b868ae0526cb0db7ee5 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 18:56:33 +0800 Subject: [PATCH 13/25] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=B8=AD=E7=9A=84=E6=93=8D=E4=BD=9C=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E7=9A=84=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/test/base_code/operate_data_base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packageship/test/base_code/operate_data_base.py b/packageship/test/base_code/operate_data_base.py index bbdee421..c752af59 100644 --- a/packageship/test/base_code/operate_data_base.py +++ b/packageship/test/base_code/operate_data_base.py @@ -10,6 +10,10 @@ from packageship.libs.exception import Error try: from packageship import system_config + os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), + 'test', + 'common_files', + 'package.ini') system_config.SYS_CONFIG_PATH = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', -- Gitee From 7f6ef8b2e26caae4a12614546febeba97e3eabad Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 19:07:23 +0800 Subject: [PATCH 14/25] =?UTF-8?q?=E6=9B=B4=E6=94=B9log=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E7=9A=84=E7=9A=84=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/libs/conf/global_config.py | 2 +- packageship/packageship/package.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packageship/packageship/libs/conf/global_config.py b/packageship/packageship/libs/conf/global_config.py index 21cbc6b0..a470d987 100644 --- a/packageship/packageship/libs/conf/global_config.py +++ b/packageship/packageship/libs/conf/global_config.py @@ -46,7 +46,7 @@ QUERY_HOST = '127.0.0.1' REMOTE_HOST = 'https://api.openeuler.org/pkgmanage' # Custom log storage path -LOG_PATH = os.path.join('/', 'tmp') +LOG_PATH = os.path.join('/', 'var', 'log', 'pkgship') # Logging level # The log level option value can only be as follows diff --git a/packageship/packageship/package.ini b/packageship/packageship/package.ini index e5eef47a..ee739ccf 100644 --- a/packageship/packageship/package.ini +++ b/packageship/packageship/package.ini @@ -29,7 +29,7 @@ remote_host=https://api.openeuler.org/pkgmanage [LOG] ; Custom log storage path -log_path=/tmp/ +log_path=/var/log/pkgship ; Logging level ; The log level option value can only be as follows -- Gitee From 90fb9033f1c98855beae3dd491d2887f4964cb10 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 19:14:08 +0800 Subject: [PATCH 15/25] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E4=B8=AD=E9=92=88=E5=AF=B9=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E8=B7=AF=E5=BE=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../init_system_tests/test_importdata.py | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/packageship/test/test_module/init_system_tests/test_importdata.py b/packageship/test/test_module/init_system_tests/test_importdata.py index 59beb960..b52c4741 100644 --- a/packageship/test/test_module/init_system_tests/test_importdata.py +++ b/packageship/test/test_module/init_system_tests/test_importdata.py @@ -13,7 +13,10 @@ from packageship import system_config from packageship.libs.exception import Error try: - + os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), + 'test', + 'common_files', + 'package.ini') system_config.SYS_CONFIG_PATH = os.path.join( os.path.dirname( system_config.BASE_PATH), @@ -64,7 +67,8 @@ class ImportData(unittest.TestCase): # Yaml file exists but the content is empty try: - _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path') + _config_path = ReadConfig( + system_config.SYS_CONFIG_PATH).get_system('init_conf_path') shutil.copyfile(_config_path, _config_path + '.bak') with open(_config_path, 'w', encoding='utf-8') as w_f: @@ -83,7 +87,8 @@ class ImportData(unittest.TestCase): # Yaml file exists but DB exists_ The same with name try: - _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path') + _config_path = ReadConfig( + system_config.SYS_CONFIG_PATH).get_system('init_conf_path') shutil.copyfile(_config_path, _config_path + '.bak') with open(_config_path, 'r', encoding='utf-8') as file: origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) @@ -118,7 +123,8 @@ class ImportData(unittest.TestCase): config.set("SYSTEM", "init_conf_path", "D:\\Users\\conf.yaml") config.write(open(system_config.SYS_CONFIG_PATH, "w")) - _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path') + _config_path = ReadConfig( + system_config.SYS_CONFIG_PATH).get_system('init_conf_path') InitDataBase(config_file_path=_config_path).init_data() except FileNotFoundError as error: self.assertEqual( @@ -135,7 +141,8 @@ class ImportData(unittest.TestCase): def test_dbname(self): """test dbname""" try: - _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path') + _config_path = ReadConfig( + system_config.SYS_CONFIG_PATH).get_system('init_conf_path') shutil.copyfile(_config_path, _config_path + '.bak') with open(_config_path, 'r', encoding='utf-8') as file: origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) @@ -159,7 +166,8 @@ class ImportData(unittest.TestCase): def test_src_db_file(self): """test src db file""" try: - _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path') + _config_path = ReadConfig( + system_config.SYS_CONFIG_PATH).get_system('init_conf_path') shutil.copyfile(_config_path, _config_path + '.bak') with open(_config_path, 'r', encoding='utf-8') as file: origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) @@ -183,7 +191,8 @@ class ImportData(unittest.TestCase): def test_priority(self): """test priority""" try: - _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path') + _config_path = ReadConfig( + system_config.SYS_CONFIG_PATH).get_system('init_conf_path') shutil.copyfile(_config_path, _config_path + '.bak') with open(_config_path, 'r', encoding='utf-8') as file: origin_yaml = yaml.load(file.read(), Loader=yaml.FullLoader) @@ -211,7 +220,8 @@ class ImportData(unittest.TestCase): Initialization of system data """ # Normal configuration - _config_path = ReadConfig(system_config.SYS_CONFIG_PATH).get_system('init_conf_path') + _config_path = ReadConfig( + system_config.SYS_CONFIG_PATH).get_system('init_conf_path') InitDataBase(config_file_path=_config_path).init_data() # In the correct case, an import will be generated under the initsystem -- Gitee From 0216702171e87dbb944e2f0342297137d8bf6ae6 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 19:29:41 +0800 Subject: [PATCH 16/25] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=9A=84=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/__init__.py | 3 ++- packageship/test/base_code/operate_data_base.py | 1 + packageship/test/base_code/read_data_base.py | 2 ++ .../test/test_module/init_system_tests/test_importdata.py | 4 +++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packageship/packageship/__init__.py b/packageship/packageship/__init__.py index 009508ee..9aaf0d0d 100644 --- a/packageship/packageship/__init__.py +++ b/packageship/packageship/__init__.py @@ -6,7 +6,8 @@ import os import sys from packageship.libs.log import Log -os.environ["SETTINGS_FILE_PATH"] = '/etc/pkgship/package.ini' +if "SETTINGS_FILE_PATH" not in os.environ: + os.environ["SETTINGS_FILE_PATH"] = '/etc/pkgship/package.ini' # The root directory where the system is running diff --git a/packageship/test/base_code/operate_data_base.py b/packageship/test/base_code/operate_data_base.py index c752af59..1c5958f0 100644 --- a/packageship/test/base_code/operate_data_base.py +++ b/packageship/test/base_code/operate_data_base.py @@ -9,6 +9,7 @@ import unittest from packageship.libs.exception import Error try: + os.environ["SETTINGS_FILE_PATH"] = None from packageship import system_config os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', diff --git a/packageship/test/base_code/read_data_base.py b/packageship/test/base_code/read_data_base.py index 47b6c30b..84f212cd 100644 --- a/packageship/test/base_code/read_data_base.py +++ b/packageship/test/base_code/read_data_base.py @@ -7,11 +7,13 @@ from .basetest import TestBase from packageship.libs.exception import Error try: + os.environ["SETTINGS_FILE_PATH"] = None from packageship import system_config os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', 'common_files', 'package.ini') + system_config.SYS_CONFIG_PATH = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', 'common_files', diff --git a/packageship/test/test_module/init_system_tests/test_importdata.py b/packageship/test/test_module/init_system_tests/test_importdata.py index b52c4741..aa7bf7db 100644 --- a/packageship/test/test_module/init_system_tests/test_importdata.py +++ b/packageship/test/test_module/init_system_tests/test_importdata.py @@ -9,14 +9,16 @@ import unittest import warnings from configparser import ConfigParser import yaml -from packageship import system_config from packageship.libs.exception import Error try: + os.environ["SETTINGS_FILE_PATH"] = None + from packageship import system_config os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', 'common_files', 'package.ini') + system_config.SYS_CONFIG_PATH = os.path.join( os.path.dirname( system_config.BASE_PATH), -- Gitee From 45dd627c5cf36b4477b79feb140f84fdb3016add Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 19:35:42 +0800 Subject: [PATCH 17/25] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=B8=AD=E5=AF=BC=E5=8C=85=E9=A1=BA=E5=BA=8F=E7=9A=84=E6=9B=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/test/base_code/operate_data_base.py | 3 +-- packageship/test/base_code/read_data_base.py | 3 ++- .../test/test_module/init_system_tests/test_importdata.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packageship/test/base_code/operate_data_base.py b/packageship/test/base_code/operate_data_base.py index 1c5958f0..df7f4698 100644 --- a/packageship/test/base_code/operate_data_base.py +++ b/packageship/test/base_code/operate_data_base.py @@ -6,11 +6,10 @@ OperateTestBase import os import unittest -from packageship.libs.exception import Error - try: os.environ["SETTINGS_FILE_PATH"] = None from packageship import system_config + from packageship.libs.exception import Error os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', 'common_files', diff --git a/packageship/test/base_code/read_data_base.py b/packageship/test/base_code/read_data_base.py index 84f212cd..d701f3ff 100644 --- a/packageship/test/base_code/read_data_base.py +++ b/packageship/test/base_code/read_data_base.py @@ -5,10 +5,11 @@ import unittest import json from .basetest import TestBase -from packageship.libs.exception import Error + try: os.environ["SETTINGS_FILE_PATH"] = None from packageship import system_config + from packageship.libs.exception import Error os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', 'common_files', diff --git a/packageship/test/test_module/init_system_tests/test_importdata.py b/packageship/test/test_module/init_system_tests/test_importdata.py index aa7bf7db..ab746600 100644 --- a/packageship/test/test_module/init_system_tests/test_importdata.py +++ b/packageship/test/test_module/init_system_tests/test_importdata.py @@ -9,11 +9,11 @@ import unittest import warnings from configparser import ConfigParser import yaml -from packageship.libs.exception import Error try: os.environ["SETTINGS_FILE_PATH"] = None from packageship import system_config + from packageship.libs.exception import Error os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', 'common_files', -- Gitee From 4971e6d87a7d93c04f7dc669f6b7776ce846512b Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 19:39:17 +0800 Subject: [PATCH 18/25] =?UTF-8?q?=E5=AF=BC=E5=8C=85=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/test/base_code/operate_data_base.py | 4 ++-- packageship/test/base_code/read_data_base.py | 4 ++-- .../test/test_module/init_system_tests/test_importdata.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packageship/test/base_code/operate_data_base.py b/packageship/test/base_code/operate_data_base.py index df7f4698..a8e1413c 100644 --- a/packageship/test/base_code/operate_data_base.py +++ b/packageship/test/base_code/operate_data_base.py @@ -31,8 +31,8 @@ try: from test.base_code.init_config_path import init_config from packageship.manage import app -except Error: - raise +except ImportError: + raise ImportError class OperateTestBase(unittest.TestCase): diff --git a/packageship/test/base_code/read_data_base.py b/packageship/test/base_code/read_data_base.py index d701f3ff..7a27bbf3 100644 --- a/packageship/test/base_code/read_data_base.py +++ b/packageship/test/base_code/read_data_base.py @@ -32,8 +32,8 @@ try: from test.base_code.init_config_path import init_config from packageship.selfpkg import app -except Error: - raise +except ImportError: + raise ImportError class ReadTestBase(TestBase): diff --git a/packageship/test/test_module/init_system_tests/test_importdata.py b/packageship/test/test_module/init_system_tests/test_importdata.py index ab746600..608a52cd 100644 --- a/packageship/test/test_module/init_system_tests/test_importdata.py +++ b/packageship/test/test_module/init_system_tests/test_importdata.py @@ -38,8 +38,8 @@ try: from test.base_code.init_config_path import init_config -except Error: - raise Error +except ImportError: + raise ImportError from packageship.application.initsystem.data_import import InitDataBase from packageship.libs.exception import ContentNoneException -- Gitee From ec341ac7290e82e5b625ff0066ccae0b85f40a05 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 19:42:19 +0800 Subject: [PATCH 19/25] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=80=BC=E7=9A=84=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/test/base_code/operate_data_base.py | 2 +- packageship/test/base_code/read_data_base.py | 2 +- .../test/test_module/init_system_tests/test_importdata.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packageship/test/base_code/operate_data_base.py b/packageship/test/base_code/operate_data_base.py index a8e1413c..eae1f843 100644 --- a/packageship/test/base_code/operate_data_base.py +++ b/packageship/test/base_code/operate_data_base.py @@ -7,7 +7,7 @@ import os import unittest try: - os.environ["SETTINGS_FILE_PATH"] = None + os.environ["SETTINGS_FILE_PATH"] = '' from packageship import system_config from packageship.libs.exception import Error os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), diff --git a/packageship/test/base_code/read_data_base.py b/packageship/test/base_code/read_data_base.py index 7a27bbf3..2e1371d7 100644 --- a/packageship/test/base_code/read_data_base.py +++ b/packageship/test/base_code/read_data_base.py @@ -7,7 +7,7 @@ from .basetest import TestBase try: - os.environ["SETTINGS_FILE_PATH"] = None + os.environ["SETTINGS_FILE_PATH"] = '' from packageship import system_config from packageship.libs.exception import Error os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), diff --git a/packageship/test/test_module/init_system_tests/test_importdata.py b/packageship/test/test_module/init_system_tests/test_importdata.py index 608a52cd..38f93467 100644 --- a/packageship/test/test_module/init_system_tests/test_importdata.py +++ b/packageship/test/test_module/init_system_tests/test_importdata.py @@ -11,7 +11,7 @@ from configparser import ConfigParser import yaml try: - os.environ["SETTINGS_FILE_PATH"] = None + os.environ["SETTINGS_FILE_PATH"] = '' from packageship import system_config from packageship.libs.exception import Error os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), -- Gitee From d089c796512e9b37e8ee99431dca2543a552e57b Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 19:50:55 +0800 Subject: [PATCH 20/25] =?UTF-8?q?log=E5=85=AC=E5=85=B1=E5=AE=9E=E4=BE=8B?= =?UTF-8?q?=E7=9A=84=E4=BD=8D=E7=BD=AE=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/__init__.py | 3 --- .../application/apps/lifecycle/function/download_yaml.py | 2 +- .../application/apps/lifecycle/function/gitee.py | 2 +- packageship/packageship/application/apps/lifecycle/view.py | 2 +- .../packageship/application/initsystem/data_import.py | 2 +- packageship/packageship/libs/log/loghelper.py | 3 +++ packageship/packageship/pkgship.py | 2 +- packageship/test/base_code/operate_data_base.py | 5 ++--- packageship/test/base_code/read_data_base.py | 7 +++---- .../test/test_module/init_system_tests/test_importdata.py | 7 +++---- 10 files changed, 16 insertions(+), 19 deletions(-) diff --git a/packageship/packageship/__init__.py b/packageship/packageship/__init__.py index 9aaf0d0d..8d516bd6 100644 --- a/packageship/packageship/__init__.py +++ b/packageship/packageship/__init__.py @@ -4,7 +4,6 @@ The root path of the project """ import os import sys -from packageship.libs.log import Log if "SETTINGS_FILE_PATH" not in os.environ: os.environ["SETTINGS_FILE_PATH"] = '/etc/pkgship/package.ini' @@ -15,5 +14,3 @@ if getattr(sys, 'frozen', False): BASE_PATH = os.path.dirname(os.path.realpath(sys.argv[0])) else: BASE_PATH = os.path.abspath(os.path.dirname(__file__)) - -LOGGER = Log(__name__) diff --git a/packageship/packageship/application/apps/lifecycle/function/download_yaml.py b/packageship/packageship/application/apps/lifecycle/function/download_yaml.py index cb18d0e7..7a8726b1 100644 --- a/packageship/packageship/application/apps/lifecycle/function/download_yaml.py +++ b/packageship/packageship/application/apps/lifecycle/function/download_yaml.py @@ -12,7 +12,7 @@ import yaml from retrying import retry from sqlalchemy.exc import SQLAlchemyError from requests.exceptions import HTTPError -from packageship import LOGGER +from packageship.libs.log.loghelper import LOGGER from packageship.libs.conf import configuration from packageship.application.models.package import Packages from packageship.application.models.package import PackagesMaintainer diff --git a/packageship/packageship/application/apps/lifecycle/function/gitee.py b/packageship/packageship/application/apps/lifecycle/function/gitee.py index f6f6f682..b809e9bc 100644 --- a/packageship/packageship/application/apps/lifecycle/function/gitee.py +++ b/packageship/packageship/application/apps/lifecycle/function/gitee.py @@ -9,7 +9,7 @@ from retrying import retry import requests from requests.exceptions import HTTPError from sqlalchemy.exc import SQLAlchemyError -from packageship import LOGGER +from packageship.libs.log.loghelper import LOGGER from packageship.libs.dbutils import DBHelper from packageship.libs.exception import Error, ContentNoneException from packageship.application.models.package import PackagesIssue diff --git a/packageship/packageship/application/apps/lifecycle/view.py b/packageship/packageship/application/apps/lifecycle/view.py index 0e41138e..04337a42 100644 --- a/packageship/packageship/application/apps/lifecycle/view.py +++ b/packageship/packageship/application/apps/lifecycle/view.py @@ -19,7 +19,7 @@ from marshmallow import ValidationError from sqlalchemy.exc import DisconnectionError, SQLAlchemyError -from packageship import LOGGER +from packageship.libs.log.loghelper import LOGGER from packageship.libs.conf import configuration from packageship.libs.exception import Error from packageship.application.apps.package.function.constants import ResponseCode diff --git a/packageship/packageship/application/initsystem/data_import.py b/packageship/packageship/application/initsystem/data_import.py index 3eda51b4..48b565c9 100644 --- a/packageship/packageship/application/initsystem/data_import.py +++ b/packageship/packageship/application/initsystem/data_import.py @@ -19,7 +19,7 @@ from packageship.application.models.package import BinRequires from packageship.application.models.package import SrcRequires from packageship.application.models.package import BinProvides from packageship.application.models.package import Packages -from packageship import LOGGER +from packageship.libs.log.loghelper import LOGGER class InitDataBase(): diff --git a/packageship/packageship/libs/log/loghelper.py b/packageship/packageship/libs/log/loghelper.py index 2dbb40d5..dcb65d35 100644 --- a/packageship/packageship/libs/log/loghelper.py +++ b/packageship/packageship/libs/log/loghelper.py @@ -105,3 +105,6 @@ class Log(): self.__set_formatter() self.close_handler() return self.__logger + + +LOGGER = Log(__name__) diff --git a/packageship/packageship/pkgship.py b/packageship/packageship/pkgship.py index d50ce771..308f9c86 100644 --- a/packageship/packageship/pkgship.py +++ b/packageship/packageship/pkgship.py @@ -17,7 +17,7 @@ try: from requests.exceptions import HTTPError import prettytable from prettytable import PrettyTable - from packageship import LOGGER + from packageship.libs.log.loghelper import LOGGER from packageship.libs.exception import Error from packageship.libs.conf import configuration except ImportError as import_error: diff --git a/packageship/test/base_code/operate_data_base.py b/packageship/test/base_code/operate_data_base.py index eae1f843..aac5fb9b 100644 --- a/packageship/test/base_code/operate_data_base.py +++ b/packageship/test/base_code/operate_data_base.py @@ -5,11 +5,10 @@ OperateTestBase """ import os import unittest +from packageship import system_config +from packageship.libs.exception import Error try: - os.environ["SETTINGS_FILE_PATH"] = '' - from packageship import system_config - from packageship.libs.exception import Error os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', 'common_files', diff --git a/packageship/test/base_code/read_data_base.py b/packageship/test/base_code/read_data_base.py index 2e1371d7..f76ac34b 100644 --- a/packageship/test/base_code/read_data_base.py +++ b/packageship/test/base_code/read_data_base.py @@ -4,12 +4,11 @@ import os import unittest import json from .basetest import TestBase - +from packageship import system_config +from packageship.libs.exception import Error try: - os.environ["SETTINGS_FILE_PATH"] = '' - from packageship import system_config - from packageship.libs.exception import Error + os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', 'common_files', diff --git a/packageship/test/test_module/init_system_tests/test_importdata.py b/packageship/test/test_module/init_system_tests/test_importdata.py index 38f93467..7c0cdd92 100644 --- a/packageship/test/test_module/init_system_tests/test_importdata.py +++ b/packageship/test/test_module/init_system_tests/test_importdata.py @@ -9,11 +9,10 @@ import unittest import warnings from configparser import ConfigParser import yaml - +from packageship import system_config +from packageship.libs.exception import Error try: - os.environ["SETTINGS_FILE_PATH"] = '' - from packageship import system_config - from packageship.libs.exception import Error + os.environ["SETTINGS_FILE_PATH"] = os.path.join(os.path.dirname(system_config.BASE_PATH), 'test', 'common_files', -- Gitee From 9682d021949cde1651645ea37d0efe871c9f09e2 Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 21:31:48 +0800 Subject: [PATCH 21/25] =?UTF-8?q?=E6=9B=B4=E6=94=B9setup.py=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E7=9A=84=E5=AF=BC=E5=85=A5=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/packageship/setup.py b/packageship/setup.py index 03ad5fce..f478d405 100644 --- a/packageship/setup.py +++ b/packageship/setup.py @@ -34,6 +34,7 @@ setup( 'packageship.application.models.package', 'packageship.application.settings', 'packageship.libs.__init__', + 'packageship.libs.conf.global_config', 'packageship.libs.configutils.readconfig', 'packageship.libs.dbutils.sqlalchemy_helper', 'packageship.libs.exception.ext', -- Gitee From 193a6e686f9ccc5a77bba71457e9b792affdea3e Mon Sep 17 00:00:00 2001 From: gongzt Date: Tue, 1 Sep 2020 21:53:17 +0800 Subject: [PATCH 22/25] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=85=B1=E6=9C=89?= =?UTF-8?q?=E7=9A=84=E6=97=A5=E5=BF=97=E6=96=B9=E6=B3=95=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/apps/lifecycle/function/download_yaml.py | 2 +- .../packageship/application/apps/lifecycle/function/gitee.py | 2 +- packageship/packageship/application/apps/lifecycle/view.py | 2 +- packageship/packageship/application/initsystem/data_import.py | 2 +- packageship/packageship/libs/log/__init__.py | 3 ++- packageship/packageship/pkgship.py | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packageship/packageship/application/apps/lifecycle/function/download_yaml.py b/packageship/packageship/application/apps/lifecycle/function/download_yaml.py index 7a8726b1..d2204f36 100644 --- a/packageship/packageship/application/apps/lifecycle/function/download_yaml.py +++ b/packageship/packageship/application/apps/lifecycle/function/download_yaml.py @@ -12,7 +12,7 @@ import yaml from retrying import retry from sqlalchemy.exc import SQLAlchemyError from requests.exceptions import HTTPError -from packageship.libs.log.loghelper import LOGGER +from packageship.libs.log import LOGGER from packageship.libs.conf import configuration from packageship.application.models.package import Packages from packageship.application.models.package import PackagesMaintainer diff --git a/packageship/packageship/application/apps/lifecycle/function/gitee.py b/packageship/packageship/application/apps/lifecycle/function/gitee.py index b809e9bc..7dc08e38 100644 --- a/packageship/packageship/application/apps/lifecycle/function/gitee.py +++ b/packageship/packageship/application/apps/lifecycle/function/gitee.py @@ -9,7 +9,7 @@ from retrying import retry import requests from requests.exceptions import HTTPError from sqlalchemy.exc import SQLAlchemyError -from packageship.libs.log.loghelper import LOGGER +from packageship.libs.log import LOGGER from packageship.libs.dbutils import DBHelper from packageship.libs.exception import Error, ContentNoneException from packageship.application.models.package import PackagesIssue diff --git a/packageship/packageship/application/apps/lifecycle/view.py b/packageship/packageship/application/apps/lifecycle/view.py index 04337a42..c8a4ae5f 100644 --- a/packageship/packageship/application/apps/lifecycle/view.py +++ b/packageship/packageship/application/apps/lifecycle/view.py @@ -19,7 +19,7 @@ from marshmallow import ValidationError from sqlalchemy.exc import DisconnectionError, SQLAlchemyError -from packageship.libs.log.loghelper import LOGGER +from packageship.libs.log import LOGGER from packageship.libs.conf import configuration from packageship.libs.exception import Error from packageship.application.apps.package.function.constants import ResponseCode diff --git a/packageship/packageship/application/initsystem/data_import.py b/packageship/packageship/application/initsystem/data_import.py index 48b565c9..b895fde0 100644 --- a/packageship/packageship/application/initsystem/data_import.py +++ b/packageship/packageship/application/initsystem/data_import.py @@ -19,7 +19,7 @@ from packageship.application.models.package import BinRequires from packageship.application.models.package import SrcRequires from packageship.application.models.package import BinProvides from packageship.application.models.package import Packages -from packageship.libs.log.loghelper import LOGGER +from packageship.libs.log import LOGGER class InitDataBase(): diff --git a/packageship/packageship/libs/log/__init__.py b/packageship/packageship/libs/log/__init__.py index 3decd458..28f7f56c 100644 --- a/packageship/packageship/libs/log/__init__.py +++ b/packageship/packageship/libs/log/__init__.py @@ -4,5 +4,6 @@ Common methods for logging """ from packageship.libs.log.loghelper import setup_log from packageship.libs.log.loghelper import Log +from packageship.libs.log.loghelper import LOGGER -__all__ = ['setup_log', 'Log'] +__all__ = ['setup_log', 'Log', 'LOGGER'] diff --git a/packageship/packageship/pkgship.py b/packageship/packageship/pkgship.py index 308f9c86..33d38c3c 100644 --- a/packageship/packageship/pkgship.py +++ b/packageship/packageship/pkgship.py @@ -17,7 +17,7 @@ try: from requests.exceptions import HTTPError import prettytable from prettytable import PrettyTable - from packageship.libs.log.loghelper import LOGGER + from packageship.libs.log import LOGGER from packageship.libs.exception import Error from packageship.libs.conf import configuration except ImportError as import_error: -- Gitee From 50129585eff50c1902c766ff271d8a2bcb8f067d Mon Sep 17 00:00:00 2001 From: gongzt Date: Wed, 2 Sep 2020 09:03:59 +0800 Subject: [PATCH 23/25] =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E7=AB=AF=E5=8F=A3=E5=92=8C=E5=9F=9F=E5=90=8D=E7=9A=84?= =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/pkgship.py | 4 ++-- packageship/packageship/pkgshipd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packageship/packageship/pkgship.py b/packageship/packageship/pkgship.py index 33d38c3c..fa66e8ac 100644 --- a/packageship/packageship/pkgship.py +++ b/packageship/packageship/pkgship.py @@ -81,7 +81,7 @@ class BaseCommand(): Raises: """ - wirte_port = configuration.WRITE_PORT + wirte_port = str(configuration.WRITE_PORT) write_ip = configuration.WRITE_HOST if not all([write_ip, wirte_port]): @@ -99,7 +99,7 @@ class BaseCommand(): Raises: """ - read_port = configuration.QUERY_PORT + read_port = str(configuration.QUERY_PORT) read_ip = configuration.QUERY_HOST if all([read_ip, read_port]): diff --git a/packageship/packageship/pkgshipd b/packageship/packageship/pkgshipd index c6e742f0..7b4bdd30 100755 --- a/packageship/packageship/pkgshipd +++ b/packageship/packageship/pkgshipd @@ -24,7 +24,7 @@ function create_config_file(){ echo "[INFO] run packageship under path: $wsgi_file_path" if [ $service = "manage" -o $service = "all" ];then write_port=$(get_config "$service" "write_port") - write_ip_addr=$(get_config "$service" "write_ip_addr") + write_ip_addr=$(get_config "$service" "write_host") if [[ -z "$daemonize" ]] || [[ -z "$buffer_size" ]] || [[ -z "$write_ip_addr" ]] || [[ -z "$http_timeout" ]] || [[ -z "$harakiri" ]] || [[ -z "$write_port" ]]; then echo "[ERROR] CAN NOT find all config name in: $SYS_PATH/package.ini, Please check the file" @@ -51,7 +51,7 @@ daemonize=$daemonize" > $OUT_PATH/manage.ini if [ $service = "selfpkg" -o $service = "all" ];then query_port=$(get_config "$service" "query_port") - query_ip_addr=$(get_config "$service" "query_ip_addr") + query_ip_addr=$(get_config "$service" "query_host") if [[ -z "$daemonize" ]] || [[ -z "$buffer_size" ]] || [[ -z "$query_ip_addr" ]] || [[ -z "$http_timeout" ]] || [[ -z "$harakiri" ]] || [[ -z "$query_port" ]];then echo "[ERROR] CAN NOT find all config name in: $SYS_PATH/package.ini, Please check the file." -- Gitee From 35a67d5bdd6dd5a81e32563c75c87eb9c9f066ab Mon Sep 17 00:00:00 2001 From: gongzt Date: Wed, 2 Sep 2020 09:36:23 +0800 Subject: [PATCH 24/25] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=94=B1=E4=BA=8E?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=BC=95=E8=B5=B7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/application/__init__.py | 8 +------- packageship/packageship/application/app_global.py | 8 +++++--- .../packageship/application/apps/lifecycle/__init__.py | 5 +++-- .../packageship/application/apps/package/__init__.py | 4 +++- packageship/packageship/manage.py | 7 ++++++- packageship/packageship/selfpkg.py | 7 ++++++- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/packageship/packageship/application/__init__.py b/packageship/packageship/application/__init__.py index f0c78b28..ef52e65f 100644 --- a/packageship/packageship/application/__init__.py +++ b/packageship/packageship/application/__init__.py @@ -12,9 +12,6 @@ from packageship.libs.log import setup_log from packageship.libs.conf import configuration -OPERATION = None - - def _timed_task(app): """ @@ -37,7 +34,7 @@ def _timed_task(app): args=(False,)) -def init_app(operation): +def init_app(): """ Project initialization function """ @@ -58,9 +55,6 @@ def init_app(operation): # Open session function Session(app) - global OPERATION # pylint: disable=global-statement - OPERATION = operation - # Register Blueprint from packageship.application import apps # pylint: disable=import-outside-toplevel for blue, api in apps.blue_point: diff --git a/packageship/packageship/application/app_global.py b/packageship/packageship/application/app_global.py index 611f309e..8ad15088 100644 --- a/packageship/packageship/application/app_global.py +++ b/packageship/packageship/application/app_global.py @@ -2,13 +2,15 @@ """ Description: Interception before request """ +import os from flask import request -from packageship import application from packageship.application.apps.package.url import urls __all__ = ['identity_verification'] +PERMISSION_SERVICE = os.environ.get('PERMISSION_SERVICE') + def identity_verification(): """ @@ -20,8 +22,8 @@ def identity_verification(): if request.url_rule: url_rule = request.url_rule.rule for _view, url, authentication in urls: - if url.lower() == url_rule.lower() and application.OPERATION in authentication.keys(): - if request.method not in authentication.get(application.OPERATION): + if url.lower() == url_rule.lower() and PERMISSION_SERVICE in authentication.keys(): + if request.method not in authentication.get(PERMISSION_SERVICE): return False break return True diff --git a/packageship/packageship/application/apps/lifecycle/__init__.py b/packageship/packageship/application/apps/lifecycle/__init__.py index d17a06a5..8783b8a0 100644 --- a/packageship/packageship/application/apps/lifecycle/__init__.py +++ b/packageship/packageship/application/apps/lifecycle/__init__.py @@ -2,18 +2,19 @@ """ Blueprint registration for life cycle """ +import os from flask.blueprints import Blueprint from flask_restful import Api from packageship.application.apps.lifecycle.url import urls -from packageship import application lifecycle = Blueprint('lifecycle', __name__) +PERMISSION_SERVICE = os.environ.get('PERMISSION_SERVICE') # init restapi api = Api() for view, url, operation in urls: - if application.OPERATION and application.OPERATION in operation.keys(): + if PERMISSION_SERVICE and PERMISSION_SERVICE in operation.keys(): api.add_resource(view, url) diff --git a/packageship/packageship/application/apps/package/__init__.py b/packageship/packageship/application/apps/package/__init__.py index 987ad614..38161fe6 100644 --- a/packageship/packageship/application/apps/package/__init__.py +++ b/packageship/packageship/application/apps/package/__init__.py @@ -1,3 +1,4 @@ +import os from flask.blueprints import Blueprint from flask_restful import Api from packageship.application.apps.package.url import urls @@ -7,9 +8,10 @@ package = Blueprint('package', __name__) # init restapi api = Api() +PERMISSION_SERVICE = os.environ.get('PERMISSION_SERVICE') for view, url, operation in urls: - if application.OPERATION and application.OPERATION in operation.keys(): + if PERMISSION_SERVICE and PERMISSION_SERVICE in operation.keys(): api.add_resource(view, url) diff --git a/packageship/packageship/manage.py b/packageship/packageship/manage.py index 0a3bf9b0..ddc0bb64 100644 --- a/packageship/packageship/manage.py +++ b/packageship/packageship/manage.py @@ -3,6 +3,10 @@ Description: Entry for project initialization and service startupc """ import os +try: + os.environ['PERMISSION_SERVICE'] = 'write' +except: + pass from packageship.application import init_app from packageship.application.app_global import identity_verification @@ -11,7 +15,8 @@ if not os.path.exists(os.environ.get('SETTINGS_FILE_PATH')): raise FileNotFoundError( 'System configuration file:%s' % os.environ.get('SETTINGS_FILE_PATH'), 'does not exist, software service cannot be started') -app = init_app('write') + +app = init_app() @app.before_request diff --git a/packageship/packageship/selfpkg.py b/packageship/packageship/selfpkg.py index cc175494..88506615 100644 --- a/packageship/packageship/selfpkg.py +++ b/packageship/packageship/selfpkg.py @@ -3,6 +3,10 @@ Description: Entry for project initialization and service startupc """ import os +try: + os.environ['PERMISSION_SERVICE'] = 'query' +except: + pass from packageship.application import init_app from packageship.application.app_global import identity_verification @@ -11,7 +15,8 @@ if not os.path.exists(os.environ.get('SETTINGS_FILE_PATH')): raise FileNotFoundError( 'System configuration file:%s' % os.environ.get('SETTINGS_FILE_PATH'), 'does not exist, software service cannot be started') -app = init_app('query') + +app = init_app() @app.before_request -- Gitee From f2d2c7d49ae5ca886f4adcc794ee88db6e79f80b Mon Sep 17 00:00:00 2001 From: gongzt Date: Wed, 2 Sep 2020 09:54:24 +0800 Subject: [PATCH 25/25] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packageship/packageship/libs/log/loghelper.py | 7 +++---- packageship/packageship/manage.py | 2 +- packageship/packageship/selfpkg.py | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packageship/packageship/libs/log/loghelper.py b/packageship/packageship/libs/log/loghelper.py index dcb65d35..64d24fe9 100644 --- a/packageship/packageship/libs/log/loghelper.py +++ b/packageship/packageship/libs/log/loghelper.py @@ -5,8 +5,7 @@ Logging related import os import pathlib import logging -from logging.handlers import RotatingFileHandler -# from concurrent_log_handler import ConcurrentRotatingFileHandler +from concurrent_log_handler import ConcurrentRotatingFileHandler from packageship.libs.conf import configuration @@ -33,7 +32,7 @@ def setup_log(config=None): except FileExistsError: pathlib.Path(path).touch() - file_log_handler = RotatingFileHandler( + file_log_handler = ConcurrentRotatingFileHandler( path, maxBytes=max_bytes, backupCount=backup_count) formatter = logging.Formatter( @@ -76,7 +75,7 @@ class Log(): self.max_bytes = 314572800 def __init_handler(self): - self.__file_handler = RotatingFileHandler( + self.__file_handler = ConcurrentRotatingFileHandler( self.__path, maxBytes=self.max_bytes, backupCount=self.backup_count, encoding="utf-8") def __set_handler(self): diff --git a/packageship/packageship/manage.py b/packageship/packageship/manage.py index ddc0bb64..f98f34aa 100644 --- a/packageship/packageship/manage.py +++ b/packageship/packageship/manage.py @@ -5,7 +5,7 @@ Description: Entry for project initialization and service startupc import os try: os.environ['PERMISSION_SERVICE'] = 'write' -except: +except RuntimeError: pass from packageship.application import init_app from packageship.application.app_global import identity_verification diff --git a/packageship/packageship/selfpkg.py b/packageship/packageship/selfpkg.py index 88506615..0fad1136 100644 --- a/packageship/packageship/selfpkg.py +++ b/packageship/packageship/selfpkg.py @@ -5,7 +5,7 @@ Description: Entry for project initialization and service startupc import os try: os.environ['PERMISSION_SERVICE'] = 'query' -except: +except RuntimeError: pass from packageship.application import init_app from packageship.application.app_global import identity_verification -- Gitee