load_data.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import configparser
  2. import json
  3. # Load the necessary data
  4. def load_DBs():
  5. #load config file as library
  6. config = configparser.ConfigParser()
  7. config.read('./config_global.txt')
  8. if config.sections == []:
  9. print('configuration file not found\n')
  10. sys.exit(1)
  11. dsatable = dict()
  12. src2dsa = dict()
  13. dsa2cve = dict()
  14. cvetable = dict()
  15. src2month = dict()
  16. src2sloccount = dict()
  17. src2pop = dict()
  18. src2deps = dict()
  19. pkg_with_cvss = dict()
  20. src2cwe = dict()
  21. cache = config['DIR']['cache_dir']
  22. cache_dsatable = cache + 'dsatable'
  23. try:
  24. with open(cache_dsatable) as fp:
  25. dsatable = json.load(fp)
  26. except (IOError, ValueError):
  27. print('read cache dsatable failed!! Maybe first run of the system?')
  28. cache_src2dsa = cache + 'src2dsa'
  29. try:
  30. with open(cache_src2dsa) as fp:
  31. src2dsa = json.load(fp)
  32. except (IOError, ValueError):
  33. print('read cache src2dsa failed!! Maybe first run of the system?')
  34. cache_dsa2cve = cache + 'dsa2cve'
  35. try:
  36. with open(cache_dsa2cve) as fp:
  37. dsa2cve = json.load(fp)
  38. except (IOError, ValueError):
  39. print('read cache dsa2cve failed!! Maybe first run of the system?')
  40. cache_cvetable = cache + 'cvetable'
  41. try:
  42. with open(cache_cvetable) as fp:
  43. cvetable = json.load(fp)
  44. except (IOError, ValueError):
  45. print('read cache cvetable failed!! Maybe first run of the system?')
  46. cache_src2deps = cache + 'src2deps'
  47. try:
  48. with open(cache_src2deps) as fp:
  49. src2deps = json.load(fp)
  50. except (IOError, ValueError):
  51. print('read cache src2deps failed!! Maybe first run of the system?')
  52. cache_src2month = cache + 'src2month'
  53. try:
  54. with open(cache_src2month) as fp:
  55. src2month = json.load(fp)
  56. except (IOError, ValueError):
  57. print('read cache src2month failed!! Maybe first run of the system?')
  58. cache_pkg_with_cvss = cache + 'pkg_with_cvss'
  59. try:
  60. with open(cache_pkg_with_cvss) as fp:
  61. pkg_with_cvss = json.load(fp)
  62. except (IOError, ValueError):
  63. print('read cache pkg_with_cvss failed!! Maybe first run of the system?')
  64. cache_src2sloccount = cache + 'src2sloccount'
  65. try:
  66. with open(cache_src2sloccount) as fp:
  67. src2sloccount = json.load(fp)
  68. except (IOError, ValueError):
  69. print('read cache src2sloccount failed!! Maybe first run of the system?')
  70. cache_src2pop = cache + 'src2pop'
  71. try:
  72. with open(cache_src2pop) as fp:
  73. src2pop = json.load(fp)
  74. except (IOError, ValueError):
  75. print('read cache src2pop failed!! Maybe first run of the system?')
  76. src2cwe = cache + 'src2cwe'
  77. try:
  78. with open(src2cwe) as fp:
  79. src2cwe = json.load(fp)
  80. except (IOError, ValueError):
  81. print('read cache src2cwe failed!! Maybe first run of the system?')
  82. return(dsatable, src2dsa, dsa2cve, cvetable, src2month, src2sloccount, src2pop, src2deps, pkg_with_cvss, src2cwe)