load_data.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. cache = config['DIR']['cache_dir']
  21. cache_dsatable = cache + 'dsatable'
  22. try:
  23. with open(cache_dsatable) as fp:
  24. dsatable = json.load(fp)
  25. except (IOError, ValueError):
  26. print('read cache dsatable failed!! Maybe first run of the system?')
  27. cache_src2dsa = cache + 'src2dsa'
  28. try:
  29. with open(cache_src2dsa) as fp:
  30. src2dsa = json.load(fp)
  31. except (IOError, ValueError):
  32. print('read cache src2dsa failed!! Maybe first run of the system?')
  33. cache_dsa2cve = cache + 'dsa2cve'
  34. try:
  35. with open(cache_dsa2cve) as fp:
  36. dsa2cve = json.load(fp)
  37. except (IOError, ValueError):
  38. print('read cache dsa2cve failed!! Maybe first run of the system?')
  39. cache_cvetable = cache + 'cvetable'
  40. try:
  41. with open(cache_cvetable) as fp:
  42. cvetable = json.load(fp)
  43. except (IOError, ValueError):
  44. print('read cache cvetable failed!! Maybe first run of the system?')
  45. cache_src2deps = cache + 'src2deps'
  46. try:
  47. with open(cache_src2deps) as fp:
  48. src2deps = json.load(fp)
  49. except (IOError, ValueError):
  50. print('read cache src2deps failed!! Maybe first run of the system?')
  51. cache_src2month = cache + 'src2month'
  52. try:
  53. with open(cache_src2month) as fp:
  54. src2month = json.load(fp)
  55. except (IOError, ValueError):
  56. print('read cache src2month failed!! Maybe first run of the system?')
  57. cache_pkg_with_cvss = cache + 'pkg_with_cvss'
  58. try:
  59. with open(cache_pkg_with_cvss) as fp:
  60. pkg_with_cvss = json.load(fp)
  61. except (IOError, ValueError):
  62. print('read cache pkg_with_cvss failed!! Maybe first run of the system?')
  63. cache_src2sloccount = cache + 'src2sloccount'
  64. try:
  65. with open(cache_src2sloccount) as fp:
  66. src2sloccount = json.load(fp)
  67. except (IOError, ValueError):
  68. print('read cache src2sloccount failed!! Maybe first run of the system?')
  69. cache_src2pop = cache + 'src2pop'
  70. try:
  71. with open(cache_src2pop) as fp:
  72. src2pop = json.load(fp)
  73. except (IOError, ValueError):
  74. print('read cache src2pop failed!! Maybe first run of the system?')
  75. return(dsatable, src2dsa, dsa2cve, cvetable, src2month, src2sloccount, src2pop, src2deps, pkg_with_cvss)