upgrade_wechatpay_app.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import datetime
  4. import os
  5. import sys
  6. import bson
  7. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  8. sys.path.insert(0, PROJECT_ROOT)
  9. from script.base import init_env, get_logger
  10. logger = get_logger(__name__)
  11. init_env(interactive = True)
  12. from apps.web.core.models import WechatPayApp
  13. def is_valid_string(str):
  14. try:
  15. bson._make_c_string(str)
  16. return True
  17. except Exception as e:
  18. return False
  19. apps = WechatPayApp.objects.all()
  20. for app in apps:
  21. print('app id is: {}'.format(str(app.id)))
  22. if os.path.isfile(app.sslcert_path):
  23. with open(app.sslcert_path) as f:
  24. content = str(f.read())
  25. if is_valid_string(content):
  26. app.sslCert = content
  27. else:
  28. print('ssl cert is not valid.')
  29. else:
  30. print('ssl cert path is not exist.')
  31. if os.path.isfile(app.sslkey_path):
  32. with open(app.sslkey_path) as f:
  33. content = str(f.read())
  34. if is_valid_string(content):
  35. app.sslKey = content
  36. else:
  37. print('ssl key is not valid.')
  38. else:
  39. print('ssl key path is not exist.')
  40. # if os.path.isfile(app.rootca_path):
  41. # with open(app.rootca_path) as f:
  42. # content = str(f.read())
  43. # if is_valid_string(content):
  44. # app.rootCA = content
  45. # else:
  46. # print('root ca is not valid.')
  47. # else:
  48. # print('root ca path is not exist.')
  49. app.dateTimeUpdated = datetime.datetime.now()
  50. app.save()