# -*- coding: utf-8 -*- # !/usr/bin/env python import datetime import os import sys import bson PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..') sys.path.insert(0, PROJECT_ROOT) from script.base import init_env, get_logger logger = get_logger(__name__) init_env(interactive = True) from apps.web.core.models import WechatPayApp def is_valid_string(str): try: bson._make_c_string(str) return True except Exception as e: return False apps = WechatPayApp.objects.all() for app in apps: print('app id is: {}'.format(str(app.id))) if os.path.isfile(app.sslcert_path): with open(app.sslcert_path) as f: content = str(f.read()) if is_valid_string(content): app.sslCert = content else: print('ssl cert is not valid.') else: print('ssl cert path is not exist.') if os.path.isfile(app.sslkey_path): with open(app.sslkey_path) as f: content = str(f.read()) if is_valid_string(content): app.sslKey = content else: print('ssl key is not valid.') else: print('ssl key path is not exist.') # if os.path.isfile(app.rootca_path): # with open(app.rootca_path) as f: # content = str(f.read()) # if is_valid_string(content): # app.rootCA = content # else: # print('root ca is not valid.') # else: # print('root ca path is not exist.') app.dateTimeUpdated = datetime.datetime.now() app.save()