diff --git a/patch-tracking/patch_tracking/app.py b/patch-tracking/patch_tracking/app.py index e39ba4cb2f15f4f35ef927a9e737be0a44ab865c..1d941f611ef30f07c4a5275b09fad3cc649268b8 100644 --- a/patch-tracking/patch_tracking/app.py +++ b/patch-tracking/patch_tracking/app.py @@ -22,8 +22,12 @@ def check_token(): gitee_token = app.config['GITEE_ACCESS_TOKEN'] github_token = app.config['GITHUB_ACCESS_TOKEN'] token_error = False - github_ret = github_api.get_user_info(github_token) - if github_ret[0] != "success": + try: + github_ret = github_api.get_user_info(github_token) + if github_ret[0] != "success": + logger.error('github token is bad credentials.') + token_error = True + except UnicodeEncodeError: logger.error('github token is bad credentials.') token_error = True @@ -33,7 +37,7 @@ def check_token(): token_error = True if token_error: - sys.exit() + sys.exit(1) def check_listen(listen_param): @@ -81,11 +85,21 @@ def check_settings_conf(): logger.error('%s not configured in settings.conf.', setting) setting_error = True if setting_error: - sys.exit() + sys.exit(1) settings_file = os.path.join(os.path.abspath(os.curdir), "settings.conf") -app.config.from_pyfile(settings_file) +try: + app.config.from_pyfile(settings_file) + app.config["LISTEN"] = app.config["LISTEN"].strip() + app.config["GITHUB_ACCESS_TOKEN"] = app.config["GITHUB_ACCESS_TOKEN"].strip() + app.config["GITEE_ACCESS_TOKEN"] = app.config["GITEE_ACCESS_TOKEN"].strip() + app.config["USER"] = app.config["USER"].strip() + app.config["PASSWORD"] = app.config["PASSWORD"].strip() +except (SyntaxError, NameError): + logger.error('settings.py content format error.') + sys.exit(1) + check_settings_conf() check_token() diff --git a/patch-tracking/patch_tracking/patch-tracking b/patch-tracking/patch_tracking/patch-tracking index 9e43fa1e1254e8bada2e8a40868f285bf3ad729a..e70ea6751d4de7d77ad70c7dbecee5670f18a644 100755 --- a/patch-tracking/patch_tracking/patch-tracking +++ b/patch-tracking/patch_tracking/patch-tracking @@ -6,6 +6,5 @@ chdir_path=${app_file%/patch_tracking/app.py} settings_file='/etc/patch-tracking/settings.conf' -server=`grep 'LISTEN' $settings_file | awk -F'=' '{print $2}' | sed -e 's/^[ ]"//g' | sed -e 's/"$//g'` - +server=`grep 'LISTEN' $settings_file | awk -F'=' '{print $2}' | sed -e 's/^[ ]"*//g' -e "s/^'*//g" | sed -e 's/"*$//g' -e "s/'*$//g" | sed -e 's/^[ \t]*//g' | sed -e 's/[ \t]*$//g'` uwsgi --master --https "${server},/etc/patch-tracking/self-signed.crt,/etc/patch-tracking/self-signed.key" --wsgi-file "${app_file}" --callable app --chdir "${chdir_path}" --threads 100 --lazy