upgrade_alipay_app.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import os
  4. import sys
  5. import bson
  6. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  7. sys.path.insert(0, PROJECT_ROOT)
  8. from script.base import init_env, get_logger
  9. logger = get_logger(__name__)
  10. init_env(interactive = True)
  11. def is_valid_string(str):
  12. try:
  13. bson._make_c_string(str)
  14. return True
  15. except Exception as e:
  16. return False
  17. from apps.web.core.models import AliApp
  18. apps = AliApp.objects.all()
  19. for app in apps:
  20. if app.public_key_path:
  21. if os.path.isfile(app.public_key_path):
  22. with open(app.public_key_path) as f:
  23. content = str(f.read())
  24. if is_valid_string(content):
  25. app.alipayPublicKey = content
  26. else:
  27. print('public_key_path is not exist.')
  28. if app.app_private_key_path:
  29. if os.path.isfile(app.app_private_key_path):
  30. with open(app.app_private_key_path) as f:
  31. content = str(f.read())
  32. if is_valid_string(content):
  33. app.appPrivateKey = content
  34. else:
  35. print('app_private_key_path is not exist.')
  36. if app.app_publickey_cert_path:
  37. if os.path.isfile(app.app_publickey_cert_path):
  38. with open(app.app_publickey_cert_path) as f:
  39. content = str(f.read())
  40. if is_valid_string(content):
  41. app.appPublicKeyCert = content
  42. else:
  43. print('app_publickey_cert_path is not exist.')
  44. if app.publickey_cert_path:
  45. if os.path.isfile(app.publickey_cert_path):
  46. with open(app.publickey_cert_path) as f:
  47. content = str(f.read())
  48. if is_valid_string(content):
  49. app.publicKeyCert = content
  50. else:
  51. print('publickey_cert_path is not exist.')
  52. if app.root_cert_path:
  53. if os.path.isfile(app.root_cert_path):
  54. with open(app.root_cert_path) as f:
  55. content = str(f.read())
  56. if is_valid_string(content):
  57. app.rootCert = content
  58. else:
  59. print('root_cert_path is not exist.')
  60. app.save()