pkg-stats 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. #!/usr/bin/env python3
  2. # Copyright (C) 2009 by Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. import aiohttp
  18. import argparse
  19. import asyncio
  20. import datetime
  21. import fnmatch
  22. import os
  23. from collections import defaultdict
  24. import re
  25. import subprocess
  26. import json
  27. import sys
  28. import time
  29. import gzip
  30. import xml.etree.ElementTree
  31. import requests
  32. brpath = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", ".."))
  33. sys.path.append(os.path.join(brpath, "utils"))
  34. from getdeveloperlib import parse_developers # noqa: E402
  35. from cpedb import CPEDB_URL # noqa: E402
  36. INFRA_RE = re.compile(r"\$\(eval \$\(([a-z-]*)-package\)\)")
  37. URL_RE = re.compile(r"\s*https?://\S*\s*$")
  38. RM_API_STATUS_ERROR = 1
  39. RM_API_STATUS_FOUND_BY_DISTRO = 2
  40. RM_API_STATUS_FOUND_BY_PATTERN = 3
  41. RM_API_STATUS_NOT_FOUND = 4
  42. class Defconfig:
  43. def __init__(self, name, path):
  44. self.name = name
  45. self.path = path
  46. self.developers = None
  47. def set_developers(self, developers):
  48. """
  49. Fills in the .developers field
  50. """
  51. self.developers = [
  52. developer.name
  53. for developer in developers
  54. if developer.hasfile(self.path)
  55. ]
  56. def get_defconfig_list():
  57. """
  58. Builds the list of Buildroot defconfigs, returning a list of Defconfig
  59. objects.
  60. """
  61. return [
  62. Defconfig(name[:-len('_defconfig')], os.path.join('configs', name))
  63. for name in os.listdir(os.path.join(brpath, 'configs'))
  64. if name.endswith('_defconfig')
  65. ]
  66. class Package:
  67. all_licenses = dict()
  68. all_license_files = list()
  69. all_versions = dict()
  70. all_ignored_cves = dict()
  71. all_cpeids = dict()
  72. # This is the list of all possible checks. Add new checks to this list so
  73. # a tool that post-processeds the json output knows the checks before
  74. # iterating over the packages.
  75. status_checks = ['cve', 'developers', 'hash', 'license',
  76. 'license-files', 'patches', 'pkg-check', 'url', 'version']
  77. def __init__(self, name, path):
  78. self.name = name
  79. self.path = path
  80. self.pkg_path = os.path.dirname(path)
  81. # Contains a list of tuple (type, infra), such as ("target",
  82. # "autotools"). When pkg-stats is run without -c, it contains
  83. # the list of all infra/type supported by the package. When
  84. # pkg-stats is run with -c, it contains the list of infra/type
  85. # used by the current configuration.
  86. self.infras = None
  87. self.license = None
  88. self.has_license = False
  89. self.has_license_files = False
  90. self.has_hash = False
  91. self.patch_files = []
  92. self.warnings = 0
  93. self.current_version = None
  94. self.url = None
  95. self.url_worker = None
  96. self.cpeid = None
  97. self.cves = list()
  98. self.ignored_cves = list()
  99. self.unsure_cves = list()
  100. self.latest_version = {'status': RM_API_STATUS_ERROR, 'version': None, 'id': None}
  101. self.status = {}
  102. def pkgvar(self):
  103. return self.name.upper().replace("-", "_")
  104. def set_url(self):
  105. """
  106. Fills in the .url field
  107. """
  108. self.status['url'] = ("warning", "no Config.in")
  109. pkgdir = os.path.dirname(os.path.join(brpath, self.path))
  110. for filename in os.listdir(pkgdir):
  111. if fnmatch.fnmatch(filename, 'Config.*'):
  112. fp = open(os.path.join(pkgdir, filename), "r")
  113. for config_line in fp:
  114. if URL_RE.match(config_line):
  115. self.url = config_line.strip()
  116. self.status['url'] = ("ok", "found")
  117. fp.close()
  118. return
  119. self.status['url'] = ("error", "missing")
  120. fp.close()
  121. @property
  122. def patch_count(self):
  123. return len(self.patch_files)
  124. @property
  125. def has_valid_infra(self):
  126. if self.infras is None:
  127. return False
  128. return len(self.infras) > 0
  129. @property
  130. def is_actual_package(self):
  131. try:
  132. if not self.has_valid_infra:
  133. return False
  134. if self.infras[0][1] == 'virtual':
  135. return False
  136. except IndexError:
  137. return False
  138. return True
  139. def set_infra(self, show_info_js):
  140. """
  141. Fills in the .infras field
  142. """
  143. # If we're running pkg-stats for a given Buildroot
  144. # configuration, keep only the type/infra that applies
  145. if show_info_js:
  146. keep_host = "host-%s" % self.name in show_info_js
  147. keep_target = self.name in show_info_js
  148. # Otherwise, keep all
  149. else:
  150. keep_host = True
  151. keep_target = True
  152. self.infras = list()
  153. with open(os.path.join(brpath, self.path), 'r') as f:
  154. lines = f.readlines()
  155. for line in lines:
  156. match = INFRA_RE.match(line)
  157. if not match:
  158. continue
  159. infra = match.group(1)
  160. if infra.startswith("host-") and keep_host:
  161. self.infras.append(("host", infra[5:]))
  162. elif keep_target:
  163. self.infras.append(("target", infra))
  164. def set_license(self):
  165. """
  166. Fills in the .status['license'] and .status['license-files'] fields
  167. """
  168. if not self.is_actual_package:
  169. self.status['license'] = ("na", "no valid package infra")
  170. self.status['license-files'] = ("na", "no valid package infra")
  171. return
  172. var = self.pkgvar()
  173. self.status['license'] = ("error", "missing")
  174. self.status['license-files'] = ("error", "missing")
  175. if var in self.all_licenses:
  176. self.license = self.all_licenses[var]
  177. self.status['license'] = ("ok", "found")
  178. if var in self.all_license_files:
  179. self.status['license-files'] = ("ok", "found")
  180. def set_hash_info(self):
  181. """
  182. Fills in the .status['hash'] field
  183. """
  184. if not self.is_actual_package:
  185. self.status['hash'] = ("na", "no valid package infra")
  186. self.status['hash-license'] = ("na", "no valid package infra")
  187. return
  188. hashpath = self.path.replace(".mk", ".hash")
  189. if os.path.exists(os.path.join(brpath, hashpath)):
  190. self.status['hash'] = ("ok", "found")
  191. else:
  192. self.status['hash'] = ("error", "missing")
  193. def set_patch_count(self):
  194. """
  195. Fills in the .patch_count, .patch_files and .status['patches'] fields
  196. """
  197. if not self.is_actual_package:
  198. self.status['patches'] = ("na", "no valid package infra")
  199. return
  200. pkgdir = os.path.dirname(os.path.join(brpath, self.path))
  201. for subdir, _, _ in os.walk(pkgdir):
  202. self.patch_files = fnmatch.filter(os.listdir(subdir), '*.patch')
  203. if self.patch_count == 0:
  204. self.status['patches'] = ("ok", "no patches")
  205. elif self.patch_count < 5:
  206. self.status['patches'] = ("warning", "some patches")
  207. else:
  208. self.status['patches'] = ("error", "lots of patches")
  209. def set_current_version(self):
  210. """
  211. Fills in the .current_version field
  212. """
  213. var = self.pkgvar()
  214. if var in self.all_versions:
  215. self.current_version = self.all_versions[var]
  216. def set_cpeid(self):
  217. """
  218. Fills in the .cpeid field
  219. """
  220. var = self.pkgvar()
  221. if not self.is_actual_package:
  222. self.status['cpe'] = ("na", "N/A - virtual pkg")
  223. return
  224. if not self.current_version:
  225. self.status['cpe'] = ("na", "no version information available")
  226. return
  227. if var in self.all_cpeids:
  228. self.cpeid = self.all_cpeids[var]
  229. # Set a preliminary status, it might be overridden by check_package_cpes()
  230. self.status['cpe'] = ("warning", "not checked against CPE dictionnary")
  231. else:
  232. self.status['cpe'] = ("error", "no verified CPE identifier")
  233. def set_check_package_warnings(self):
  234. """
  235. Fills in the .warnings and .status['pkg-check'] fields
  236. """
  237. cmd = [os.path.join(brpath, "utils/check-package")]
  238. pkgdir = os.path.dirname(os.path.join(brpath, self.path))
  239. self.status['pkg-check'] = ("error", "Missing")
  240. for root, dirs, files in os.walk(pkgdir):
  241. for f in files:
  242. if f.endswith(".mk") or f.endswith(".hash") or f == "Config.in" or f == "Config.in.host":
  243. cmd.append(os.path.join(root, f))
  244. o = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[1]
  245. lines = o.splitlines()
  246. for line in lines:
  247. m = re.match("^([0-9]*) warnings generated", line.decode())
  248. if m:
  249. self.warnings = int(m.group(1))
  250. if self.warnings == 0:
  251. self.status['pkg-check'] = ("ok", "no warnings")
  252. else:
  253. self.status['pkg-check'] = ("error", "{} warnings".format(self.warnings))
  254. return
  255. def set_ignored_cves(self):
  256. """
  257. Give the list of CVEs ignored by the package
  258. """
  259. self.ignored_cves = list(self.all_ignored_cves.get(self.pkgvar(), []))
  260. def set_developers(self, developers):
  261. """
  262. Fills in the .developers and .status['developers'] field
  263. """
  264. self.developers = [
  265. dev.name
  266. for dev in developers
  267. if dev.hasfile(self.path)
  268. ]
  269. if self.developers:
  270. self.status['developers'] = ("ok", "{} developers".format(len(self.developers)))
  271. else:
  272. self.status['developers'] = ("warning", "no developers")
  273. def is_status_ok(self, name):
  274. return name in self.status and self.status[name][0] == 'ok'
  275. def is_status_error(self, name):
  276. return name in self.status and self.status[name][0] == 'error'
  277. def is_status_na(self, name):
  278. return name in self.status and self.status[name][0] == 'na'
  279. def __eq__(self, other):
  280. return self.path == other.path
  281. def __lt__(self, other):
  282. return self.path < other.path
  283. def __str__(self):
  284. return "%s (path='%s', license='%s', license_files='%s', hash='%s', patches=%d)" % \
  285. (self.name, self.path, self.is_status_ok('license'),
  286. self.is_status_ok('license-files'), self.status['hash'], self.patch_count)
  287. def get_pkglist(npackages, package_list):
  288. """
  289. Builds the list of Buildroot packages, returning a list of Package
  290. objects. Only the .name and .path fields of the Package object are
  291. initialized.
  292. npackages: limit to N packages
  293. package_list: limit to those packages in this list
  294. """
  295. WALK_USEFUL_SUBDIRS = ["boot", "linux", "package", "toolchain"]
  296. WALK_EXCLUDES = ["boot/common.mk",
  297. "linux/linux-ext-.*.mk",
  298. "package/freescale-imx/freescale-imx.mk",
  299. "package/gcc/gcc.mk",
  300. "package/gstreamer/gstreamer.mk",
  301. "package/gstreamer1/gstreamer1.mk",
  302. "package/gtk2-themes/gtk2-themes.mk",
  303. "package/matchbox/matchbox.mk",
  304. "package/opengl/opengl.mk",
  305. "package/qt5/qt5.mk",
  306. "package/x11r7/x11r7.mk",
  307. "package/doc-asciidoc.mk",
  308. "package/pkg-.*.mk",
  309. "toolchain/toolchain-external/pkg-toolchain-external.mk",
  310. "toolchain/toolchain-external/toolchain-external.mk",
  311. "toolchain/toolchain.mk",
  312. "toolchain/helpers.mk",
  313. "toolchain/toolchain-wrapper.mk"]
  314. packages = list()
  315. count = 0
  316. for root, dirs, files in os.walk(brpath):
  317. root = os.path.relpath(root, brpath)
  318. rootdir = root.split("/")
  319. if len(rootdir) < 1:
  320. continue
  321. if rootdir[0] not in WALK_USEFUL_SUBDIRS:
  322. continue
  323. for f in files:
  324. if not f.endswith(".mk"):
  325. continue
  326. # Strip ending ".mk"
  327. pkgname = f[:-3]
  328. if package_list and pkgname not in package_list:
  329. continue
  330. pkgpath = os.path.join(root, f)
  331. skip = False
  332. for exclude in WALK_EXCLUDES:
  333. if re.match(exclude, pkgpath):
  334. skip = True
  335. continue
  336. if skip:
  337. continue
  338. p = Package(pkgname, pkgpath)
  339. packages.append(p)
  340. count += 1
  341. if npackages and count == npackages:
  342. return packages
  343. return packages
  344. def get_show_info_js():
  345. cmd = ["make", "--no-print-directory", "show-info"]
  346. return json.loads(subprocess.check_output(cmd))
  347. def package_init_make_info():
  348. # Fetch all variables at once
  349. variables = subprocess.check_output(["make", "--no-print-directory", "-s",
  350. "BR2_HAVE_DOT_CONFIG=y", "printvars",
  351. "VARS=%_LICENSE %_LICENSE_FILES %_VERSION %_IGNORE_CVES %_CPE_ID"])
  352. variable_list = variables.decode().splitlines()
  353. # We process first the host package VERSION, and then the target
  354. # package VERSION. This means that if a package exists in both
  355. # target and host variants, with different values (eg. version
  356. # numbers (unlikely)), we'll report the target one.
  357. variable_list = [x[5:] for x in variable_list if x.startswith("HOST_")] + \
  358. [x for x in variable_list if not x.startswith("HOST_")]
  359. for item in variable_list:
  360. # Get variable name and value
  361. pkgvar, value = item.split("=", maxsplit=1)
  362. # Strip the suffix according to the variable
  363. if pkgvar.endswith("_LICENSE"):
  364. # If value is "unknown", no license details available
  365. if value == "unknown":
  366. continue
  367. pkgvar = pkgvar[:-8]
  368. Package.all_licenses[pkgvar] = value
  369. elif pkgvar.endswith("_LICENSE_FILES"):
  370. if pkgvar.endswith("_MANIFEST_LICENSE_FILES"):
  371. continue
  372. pkgvar = pkgvar[:-14]
  373. Package.all_license_files.append(pkgvar)
  374. elif pkgvar.endswith("_VERSION"):
  375. if pkgvar.endswith("_DL_VERSION"):
  376. continue
  377. pkgvar = pkgvar[:-8]
  378. Package.all_versions[pkgvar] = value
  379. elif pkgvar.endswith("_IGNORE_CVES"):
  380. pkgvar = pkgvar[:-12]
  381. Package.all_ignored_cves[pkgvar] = value.split()
  382. elif pkgvar.endswith("_CPE_ID"):
  383. pkgvar = pkgvar[:-7]
  384. Package.all_cpeids[pkgvar] = value
  385. check_url_count = 0
  386. async def check_url_status(session, pkg, npkgs, retry=True):
  387. global check_url_count
  388. try:
  389. async with session.get(pkg.url) as resp:
  390. if resp.status >= 400:
  391. pkg.status['url'] = ("error", "invalid {}".format(resp.status))
  392. check_url_count += 1
  393. print("[%04d/%04d] %s" % (check_url_count, npkgs, pkg.name))
  394. return
  395. except (aiohttp.ClientError, asyncio.TimeoutError):
  396. if retry:
  397. return await check_url_status(session, pkg, npkgs, retry=False)
  398. else:
  399. pkg.status['url'] = ("error", "invalid (err)")
  400. check_url_count += 1
  401. print("[%04d/%04d] %s" % (check_url_count, npkgs, pkg.name))
  402. return
  403. pkg.status['url'] = ("ok", "valid")
  404. check_url_count += 1
  405. print("[%04d/%04d] %s" % (check_url_count, npkgs, pkg.name))
  406. async def check_package_urls(packages):
  407. tasks = []
  408. connector = aiohttp.TCPConnector(limit_per_host=5)
  409. async with aiohttp.ClientSession(connector=connector, trust_env=True,
  410. timeout=aiohttp.ClientTimeout(total=15)) as sess:
  411. packages = [p for p in packages if p.status['url'][0] == 'ok']
  412. for pkg in packages:
  413. tasks.append(asyncio.ensure_future(check_url_status(sess, pkg, len(packages))))
  414. await asyncio.wait(tasks)
  415. def check_package_latest_version_set_status(pkg, status, version, identifier):
  416. pkg.latest_version = {
  417. "status": status,
  418. "version": version,
  419. "id": identifier,
  420. }
  421. if pkg.latest_version['status'] == RM_API_STATUS_ERROR:
  422. pkg.status['version'] = ('warning', "Release Monitoring API error")
  423. elif pkg.latest_version['status'] == RM_API_STATUS_NOT_FOUND:
  424. pkg.status['version'] = ('warning', "Package not found on Release Monitoring")
  425. if pkg.latest_version['version'] is None:
  426. pkg.status['version'] = ('warning', "No upstream version available on Release Monitoring")
  427. elif pkg.latest_version['version'] != pkg.current_version:
  428. pkg.status['version'] = ('error', "The newer version {} is available upstream".format(pkg.latest_version['version']))
  429. else:
  430. pkg.status['version'] = ('ok', 'up-to-date')
  431. async def check_package_get_latest_version_by_distro(session, pkg, retry=True):
  432. url = "https://release-monitoring.org//api/project/Buildroot/%s" % pkg.name
  433. try:
  434. async with session.get(url) as resp:
  435. if resp.status != 200:
  436. return False
  437. data = await resp.json()
  438. if 'stable_versions' in data and data['stable_versions']:
  439. version = data['stable_versions'][0]
  440. elif 'version' in data:
  441. version = data['version']
  442. else:
  443. version = None
  444. check_package_latest_version_set_status(pkg,
  445. RM_API_STATUS_FOUND_BY_DISTRO,
  446. version,
  447. data['id'])
  448. return True
  449. except (aiohttp.ClientError, asyncio.TimeoutError):
  450. if retry:
  451. return await check_package_get_latest_version_by_distro(session, pkg, retry=False)
  452. else:
  453. return False
  454. async def check_package_get_latest_version_by_guess(session, pkg, retry=True):
  455. url = "https://release-monitoring.org/api/projects/?pattern=%s" % pkg.name
  456. try:
  457. async with session.get(url) as resp:
  458. if resp.status != 200:
  459. return False
  460. data = await resp.json()
  461. # filter projects that have the right name and a version defined
  462. projects = [p for p in data['projects'] if p['name'] == pkg.name and 'stable_versions' in p]
  463. projects.sort(key=lambda x: x['id'])
  464. if len(projects) == 0:
  465. return False
  466. if len(projects[0]['stable_versions']) == 0:
  467. return False
  468. check_package_latest_version_set_status(pkg,
  469. RM_API_STATUS_FOUND_BY_PATTERN,
  470. projects[0]['stable_versions'][0],
  471. projects[0]['id'])
  472. return True
  473. except (aiohttp.ClientError, asyncio.TimeoutError):
  474. if retry:
  475. return await check_package_get_latest_version_by_guess(session, pkg, retry=False)
  476. else:
  477. return False
  478. check_latest_count = 0
  479. async def check_package_latest_version_get(session, pkg, npkgs):
  480. global check_latest_count
  481. if await check_package_get_latest_version_by_distro(session, pkg):
  482. check_latest_count += 1
  483. print("[%04d/%04d] %s" % (check_latest_count, npkgs, pkg.name))
  484. return
  485. if await check_package_get_latest_version_by_guess(session, pkg):
  486. check_latest_count += 1
  487. print("[%04d/%04d] %s" % (check_latest_count, npkgs, pkg.name))
  488. return
  489. check_package_latest_version_set_status(pkg,
  490. RM_API_STATUS_NOT_FOUND,
  491. None, None)
  492. check_latest_count += 1
  493. print("[%04d/%04d] %s" % (check_latest_count, npkgs, pkg.name))
  494. async def check_package_latest_version(packages):
  495. """
  496. Fills in the .latest_version field of all Package objects
  497. This field is a dict and has the following keys:
  498. - status: one of RM_API_STATUS_ERROR,
  499. RM_API_STATUS_FOUND_BY_DISTRO, RM_API_STATUS_FOUND_BY_PATTERN,
  500. RM_API_STATUS_NOT_FOUND
  501. - version: string containing the latest version known by
  502. release-monitoring.org for this package
  503. - id: string containing the id of the project corresponding to this
  504. package, as known by release-monitoring.org
  505. """
  506. for pkg in [p for p in packages if not p.is_actual_package]:
  507. pkg.status['version'] = ("na", "no valid package infra")
  508. tasks = []
  509. connector = aiohttp.TCPConnector(limit_per_host=5)
  510. async with aiohttp.ClientSession(connector=connector, trust_env=True) as sess:
  511. packages = [p for p in packages if p.is_actual_package]
  512. for pkg in packages:
  513. tasks.append(asyncio.ensure_future(check_package_latest_version_get(sess, pkg, len(packages))))
  514. await asyncio.wait(tasks)
  515. def check_package_cve_affects(cve, cpe_product_pkgs):
  516. for product in cve.affected_products:
  517. if product not in cpe_product_pkgs:
  518. continue
  519. for pkg in cpe_product_pkgs[product]:
  520. cve_status = cve.affects(pkg.name, pkg.current_version, pkg.ignored_cves, pkg.cpeid)
  521. if cve_status == cve.CVE_AFFECTS:
  522. pkg.cves.append(cve.identifier)
  523. elif cve_status == cve.CVE_UNKNOWN:
  524. pkg.unsure_cves.append(cve.identifier)
  525. def check_package_cves(nvd_path, packages):
  526. if not os.path.isdir(nvd_path):
  527. os.makedirs(nvd_path)
  528. cpe_product_pkgs = defaultdict(list)
  529. for pkg in packages:
  530. if not pkg.is_actual_package:
  531. pkg.status['cve'] = ("na", "N/A")
  532. continue
  533. if not pkg.current_version:
  534. pkg.status['cve'] = ("na", "no version information available")
  535. continue
  536. if pkg.cpeid:
  537. cpe_product = cvecheck.cpe_product(pkg.cpeid)
  538. cpe_product_pkgs[cpe_product].append(pkg)
  539. else:
  540. cpe_product_pkgs[pkg.name].append(pkg)
  541. for cve in cvecheck.CVE.read_nvd_dir(nvd_path):
  542. check_package_cve_affects(cve, cpe_product_pkgs)
  543. for pkg in packages:
  544. if 'cve' not in pkg.status:
  545. if pkg.cves or pkg.unsure_cves:
  546. pkg.status['cve'] = ("error", "affected by CVEs")
  547. else:
  548. pkg.status['cve'] = ("ok", "not affected by CVEs")
  549. def check_package_cpes(nvd_path, packages):
  550. class CpeXmlParser:
  551. cpes = []
  552. def start(self, tag, attrib):
  553. if tag == "{http://scap.nist.gov/schema/cpe-extension/2.3}cpe23-item":
  554. self.cpes.append(attrib['name'])
  555. def close(self):
  556. return self.cpes
  557. print("CPE: Setting up NIST dictionary")
  558. if not os.path.exists(os.path.join(nvd_path, "cpe")):
  559. os.makedirs(os.path.join(nvd_path, "cpe"))
  560. cpe_dict_local = os.path.join(nvd_path, "cpe", os.path.basename(CPEDB_URL))
  561. if not os.path.exists(cpe_dict_local) or os.stat(cpe_dict_local).st_mtime < time.time() - 86400:
  562. print("CPE: Fetching xml manifest from [" + CPEDB_URL + "]")
  563. cpe_dict = requests.get(CPEDB_URL)
  564. open(cpe_dict_local, "wb").write(cpe_dict.content)
  565. print("CPE: Unzipping xml manifest...")
  566. nist_cpe_file = gzip.GzipFile(fileobj=open(cpe_dict_local, 'rb'))
  567. parser = xml.etree.ElementTree.XMLParser(target=CpeXmlParser())
  568. while True:
  569. c = nist_cpe_file.read(1024*1024)
  570. if not c:
  571. break
  572. parser.feed(c)
  573. cpes = parser.close()
  574. for p in packages:
  575. if not p.cpeid:
  576. continue
  577. if p.cpeid in cpes:
  578. p.status['cpe'] = ("ok", "verified CPE identifier")
  579. else:
  580. p.status['cpe'] = ("error", "CPE version unknown in CPE database")
  581. def calculate_stats(packages):
  582. stats = defaultdict(int)
  583. stats['packages'] = len(packages)
  584. for pkg in packages:
  585. # If packages have multiple infra, take the first one. For the
  586. # vast majority of packages, the target and host infra are the
  587. # same. There are very few packages that use a different infra
  588. # for the host and target variants.
  589. if len(pkg.infras) > 0:
  590. infra = pkg.infras[0][1]
  591. stats["infra-%s" % infra] += 1
  592. else:
  593. stats["infra-unknown"] += 1
  594. if pkg.is_status_ok('license'):
  595. stats["license"] += 1
  596. else:
  597. stats["no-license"] += 1
  598. if pkg.is_status_ok('license-files'):
  599. stats["license-files"] += 1
  600. else:
  601. stats["no-license-files"] += 1
  602. if pkg.is_status_ok('hash'):
  603. stats["hash"] += 1
  604. else:
  605. stats["no-hash"] += 1
  606. if pkg.latest_version['status'] == RM_API_STATUS_FOUND_BY_DISTRO:
  607. stats["rmo-mapping"] += 1
  608. else:
  609. stats["rmo-no-mapping"] += 1
  610. if not pkg.latest_version['version']:
  611. stats["version-unknown"] += 1
  612. elif pkg.latest_version['version'] == pkg.current_version:
  613. stats["version-uptodate"] += 1
  614. else:
  615. stats["version-not-uptodate"] += 1
  616. stats["patches"] += pkg.patch_count
  617. stats["total-cves"] += len(pkg.cves)
  618. stats["total-unsure-cves"] += len(pkg.unsure_cves)
  619. if len(pkg.cves) != 0:
  620. stats["pkg-cves"] += 1
  621. if len(pkg.unsure_cves) != 0:
  622. stats["pkg-unsure-cves"] += 1
  623. if pkg.cpeid:
  624. stats["cpe-id"] += 1
  625. else:
  626. stats["no-cpe-id"] += 1
  627. return stats
  628. html_header = """
  629. <head>
  630. <script src=\"https://www.kryogenix.org/code/browser/sorttable/sorttable.js\"></script>
  631. <style type=\"text/css\">
  632. table {
  633. width: 100%;
  634. }
  635. td {
  636. border: 1px solid black;
  637. }
  638. td.centered {
  639. text-align: center;
  640. }
  641. td.wrong {
  642. background: #ff9a69;
  643. }
  644. td.correct {
  645. background: #d2ffc4;
  646. }
  647. td.nopatches {
  648. background: #d2ffc4;
  649. }
  650. td.somepatches {
  651. background: #ffd870;
  652. }
  653. td.lotsofpatches {
  654. background: #ff9a69;
  655. }
  656. td.good_url {
  657. background: #d2ffc4;
  658. }
  659. td.missing_url {
  660. background: #ffd870;
  661. }
  662. td.invalid_url {
  663. background: #ff9a69;
  664. }
  665. td.version-good {
  666. background: #d2ffc4;
  667. }
  668. td.version-needs-update {
  669. background: #ff9a69;
  670. }
  671. td.version-unknown {
  672. background: #ffd870;
  673. }
  674. td.version-error {
  675. background: #ccc;
  676. }
  677. td.cpe-ok {
  678. background: #d2ffc4;
  679. }
  680. td.cpe-nok {
  681. background: #ff9a69;
  682. }
  683. td.cpe-unknown {
  684. background: #ffd870;
  685. }
  686. td.cve-ok {
  687. background: #d2ffc4;
  688. }
  689. td.cve-nok {
  690. background: #ff9a69;
  691. }
  692. td.cve-unknown {
  693. background: #ffd870;
  694. }
  695. td.cve_ignored {
  696. background: #ccc;
  697. }
  698. </style>
  699. <title>Statistics of Buildroot packages</title>
  700. </head>
  701. <a href=\"#results\">Results</a><br/>
  702. <p id=\"sortable_hint\"></p>
  703. """
  704. html_footer = """
  705. </body>
  706. <script>
  707. if (typeof sorttable === \"object\") {
  708. document.getElementById(\"sortable_hint\").innerHTML =
  709. \"hint: the table can be sorted by clicking the column headers\"
  710. }
  711. </script>
  712. </html>
  713. """
  714. def infra_str(infra_list):
  715. if not infra_list:
  716. return "Unknown"
  717. elif len(infra_list) == 1:
  718. return "<b>%s</b><br/>%s" % (infra_list[0][1], infra_list[0][0])
  719. elif infra_list[0][1] == infra_list[1][1]:
  720. return "<b>%s</b><br/>%s + %s" % \
  721. (infra_list[0][1], infra_list[0][0], infra_list[1][0])
  722. else:
  723. return "<b>%s</b> (%s)<br/><b>%s</b> (%s)" % \
  724. (infra_list[0][1], infra_list[0][0],
  725. infra_list[1][1], infra_list[1][0])
  726. def boolean_str(b):
  727. if b:
  728. return "Yes"
  729. else:
  730. return "No"
  731. def dump_html_pkg(f, pkg):
  732. f.write(" <tr>\n")
  733. f.write(" <td>%s</td>\n" % pkg.path)
  734. # Patch count
  735. td_class = ["centered"]
  736. if pkg.patch_count == 0:
  737. td_class.append("nopatches")
  738. elif pkg.patch_count < 5:
  739. td_class.append("somepatches")
  740. else:
  741. td_class.append("lotsofpatches")
  742. f.write(" <td class=\"%s\">%s</td>\n" %
  743. (" ".join(td_class), str(pkg.patch_count)))
  744. # Infrastructure
  745. infra = infra_str(pkg.infras)
  746. td_class = ["centered"]
  747. if infra == "Unknown":
  748. td_class.append("wrong")
  749. else:
  750. td_class.append("correct")
  751. f.write(" <td class=\"%s\">%s</td>\n" %
  752. (" ".join(td_class), infra_str(pkg.infras)))
  753. # License
  754. td_class = ["centered"]
  755. if pkg.is_status_ok('license'):
  756. td_class.append("correct")
  757. else:
  758. td_class.append("wrong")
  759. f.write(" <td class=\"%s\">%s</td>\n" %
  760. (" ".join(td_class), boolean_str(pkg.is_status_ok('license'))))
  761. # License files
  762. td_class = ["centered"]
  763. if pkg.is_status_ok('license-files'):
  764. td_class.append("correct")
  765. else:
  766. td_class.append("wrong")
  767. f.write(" <td class=\"%s\">%s</td>\n" %
  768. (" ".join(td_class), boolean_str(pkg.is_status_ok('license-files'))))
  769. # Hash
  770. td_class = ["centered"]
  771. if pkg.is_status_ok('hash'):
  772. td_class.append("correct")
  773. else:
  774. td_class.append("wrong")
  775. f.write(" <td class=\"%s\">%s</td>\n" %
  776. (" ".join(td_class), boolean_str(pkg.is_status_ok('hash'))))
  777. # Current version
  778. if len(pkg.current_version) > 20:
  779. current_version = pkg.current_version[:20] + "..."
  780. else:
  781. current_version = pkg.current_version
  782. f.write(" <td class=\"centered\">%s</td>\n" % current_version)
  783. # Latest version
  784. if pkg.latest_version['status'] == RM_API_STATUS_ERROR:
  785. td_class.append("version-error")
  786. if pkg.latest_version['version'] is None:
  787. td_class.append("version-unknown")
  788. elif pkg.latest_version['version'] != pkg.current_version:
  789. td_class.append("version-needs-update")
  790. else:
  791. td_class.append("version-good")
  792. if pkg.latest_version['status'] == RM_API_STATUS_ERROR:
  793. latest_version_text = "<b>Error</b>"
  794. elif pkg.latest_version['status'] == RM_API_STATUS_NOT_FOUND:
  795. latest_version_text = "<b>Not found</b>"
  796. else:
  797. if pkg.latest_version['version'] is None:
  798. latest_version_text = "<b>Found, but no version</b>"
  799. else:
  800. latest_version_text = "<a href=\"https://release-monitoring.org/project/%s\"><b>%s</b></a>" % \
  801. (pkg.latest_version['id'], str(pkg.latest_version['version']))
  802. latest_version_text += "<br/>"
  803. if pkg.latest_version['status'] == RM_API_STATUS_FOUND_BY_DISTRO:
  804. latest_version_text += "found by <a href=\"https://release-monitoring.org/distro/Buildroot/\">distro</a>"
  805. else:
  806. latest_version_text += "found by guess"
  807. f.write(" <td class=\"%s\">%s</td>\n" %
  808. (" ".join(td_class), latest_version_text))
  809. # Warnings
  810. td_class = ["centered"]
  811. if pkg.warnings == 0:
  812. td_class.append("correct")
  813. else:
  814. td_class.append("wrong")
  815. f.write(" <td class=\"%s\">%d</td>\n" %
  816. (" ".join(td_class), pkg.warnings))
  817. # URL status
  818. td_class = ["centered"]
  819. url_str = pkg.status['url'][1]
  820. if pkg.status['url'][0] in ("error", "warning"):
  821. td_class.append("missing_url")
  822. if pkg.status['url'][0] == "error":
  823. td_class.append("invalid_url")
  824. url_str = "<a href=%s>%s</a>" % (pkg.url, pkg.status['url'][1])
  825. else:
  826. td_class.append("good_url")
  827. url_str = "<a href=%s>Link</a>" % pkg.url
  828. f.write(" <td class=\"%s\">%s</td>\n" %
  829. (" ".join(td_class), url_str))
  830. # CVEs
  831. td_class = ["centered"]
  832. if pkg.is_status_ok("cve"):
  833. td_class.append("cve-ok")
  834. elif pkg.is_status_error("cve"):
  835. td_class.append("cve-nok")
  836. elif pkg.is_status_na("cve") and not pkg.is_actual_package:
  837. td_class.append("cve-ok")
  838. else:
  839. td_class.append("cve-unknown")
  840. f.write(" <td class=\"%s\">\n" % " ".join(td_class))
  841. if pkg.is_status_error("cve"):
  842. for cve in pkg.cves:
  843. f.write(" <a href=\"https://security-tracker.debian.org/tracker/%s\">%s<br/>\n" % (cve, cve))
  844. for cve in pkg.unsure_cves:
  845. f.write(" <a href=\"https://security-tracker.debian.org/tracker/%s\">%s <i>(unsure)</i><br/>\n" % (cve, cve))
  846. elif pkg.is_status_na("cve"):
  847. f.write(" %s" % pkg.status['cve'][1])
  848. else:
  849. f.write(" N/A\n")
  850. f.write(" </td>\n")
  851. # CVEs Ignored
  852. td_class = ["centered"]
  853. if pkg.ignored_cves:
  854. td_class.append("cve_ignored")
  855. f.write(" <td class=\"%s\">\n" % " ".join(td_class))
  856. for ignored_cve in pkg.ignored_cves:
  857. f.write(" <a href=\"https://security-tracker.debian.org/tracker/%s\">%s<br/>\n" % (ignored_cve, ignored_cve))
  858. f.write(" </td>\n")
  859. # CPE ID
  860. td_class = ["left"]
  861. if pkg.is_status_ok("cpe"):
  862. td_class.append("cpe-ok")
  863. elif pkg.is_status_error("cpe"):
  864. td_class.append("cpe-nok")
  865. elif pkg.is_status_na("cpe") and not pkg.is_actual_package:
  866. td_class.append("cpe-ok")
  867. else:
  868. td_class.append("cpe-unknown")
  869. f.write(" <td class=\"%s\">\n" % " ".join(td_class))
  870. if pkg.cpeid:
  871. f.write(" <code>%s</code>\n" % pkg.cpeid)
  872. if not pkg.is_status_ok("cpe"):
  873. if pkg.is_actual_package and pkg.current_version:
  874. if pkg.cpeid:
  875. f.write(" <br/>%s <a href=\"https://nvd.nist.gov/products/cpe/search/results?namingFormat=2.3&keyword=%s\">(Search)</a>\n" % # noqa: E501
  876. (pkg.status['cpe'][1], ":".join(pkg.cpeid.split(":")[0:5])))
  877. else:
  878. f.write(" %s <a href=\"https://nvd.nist.gov/products/cpe/search/results?namingFormat=2.3&keyword=%s\">(Search)</a>\n" % # noqa: E501
  879. (pkg.status['cpe'][1], pkg.name))
  880. else:
  881. f.write(" %s\n" % pkg.status['cpe'][1])
  882. f.write(" </td>\n")
  883. f.write(" </tr>\n")
  884. def dump_html_all_pkgs(f, packages):
  885. f.write("""
  886. <table class=\"sortable\">
  887. <tr>
  888. <td>Package</td>
  889. <td class=\"centered\">Patch count</td>
  890. <td class=\"centered\">Infrastructure</td>
  891. <td class=\"centered\">License</td>
  892. <td class=\"centered\">License files</td>
  893. <td class=\"centered\">Hash file</td>
  894. <td class=\"centered\">Current version</td>
  895. <td class=\"centered\">Latest version</td>
  896. <td class=\"centered\">Warnings</td>
  897. <td class=\"centered\">Upstream URL</td>
  898. <td class=\"centered\">CVEs</td>
  899. <td class=\"centered\">CVEs Ignored</td>
  900. <td class=\"centered\">CPE ID</td>
  901. </tr>
  902. """)
  903. for pkg in sorted(packages):
  904. dump_html_pkg(f, pkg)
  905. f.write("</table>")
  906. def dump_html_stats(f, stats):
  907. f.write("<a id=\"results\"></a>\n")
  908. f.write("<table>\n")
  909. infras = [infra[6:] for infra in stats.keys() if infra.startswith("infra-")]
  910. for infra in infras:
  911. f.write(" <tr><td>Packages using the <i>%s</i> infrastructure</td><td>%s</td></tr>\n" %
  912. (infra, stats["infra-%s" % infra]))
  913. f.write(" <tr><td>Packages having license information</td><td>%s</td></tr>\n" %
  914. stats["license"])
  915. f.write(" <tr><td>Packages not having license information</td><td>%s</td></tr>\n" %
  916. stats["no-license"])
  917. f.write(" <tr><td>Packages having license files information</td><td>%s</td></tr>\n" %
  918. stats["license-files"])
  919. f.write(" <tr><td>Packages not having license files information</td><td>%s</td></tr>\n" %
  920. stats["no-license-files"])
  921. f.write(" <tr><td>Packages having a hash file</td><td>%s</td></tr>\n" %
  922. stats["hash"])
  923. f.write(" <tr><td>Packages not having a hash file</td><td>%s</td></tr>\n" %
  924. stats["no-hash"])
  925. f.write(" <tr><td>Total number of patches</td><td>%s</td></tr>\n" %
  926. stats["patches"])
  927. f.write("<tr><td>Packages having a mapping on <i>release-monitoring.org</i></td><td>%s</td></tr>\n" %
  928. stats["rmo-mapping"])
  929. f.write("<tr><td>Packages lacking a mapping on <i>release-monitoring.org</i></td><td>%s</td></tr>\n" %
  930. stats["rmo-no-mapping"])
  931. f.write("<tr><td>Packages that are up-to-date</td><td>%s</td></tr>\n" %
  932. stats["version-uptodate"])
  933. f.write("<tr><td>Packages that are not up-to-date</td><td>%s</td></tr>\n" %
  934. stats["version-not-uptodate"])
  935. f.write("<tr><td>Packages with no known upstream version</td><td>%s</td></tr>\n" %
  936. stats["version-unknown"])
  937. f.write("<tr><td>Packages affected by CVEs</td><td>%s</td></tr>\n" %
  938. stats["pkg-cves"])
  939. f.write("<tr><td>Total number of CVEs affecting all packages</td><td>%s</td></tr>\n" %
  940. stats["total-cves"])
  941. f.write("<tr><td>Packages affected by unsure CVEs</td><td>%s</td></tr>\n" %
  942. stats["pkg-unsure-cves"])
  943. f.write("<tr><td>Total number of unsure CVEs affecting all packages</td><td>%s</td></tr>\n" %
  944. stats["total-unsure-cves"])
  945. f.write("<tr><td>Packages with CPE ID</td><td>%s</td></tr>\n" %
  946. stats["cpe-id"])
  947. f.write("<tr><td>Packages without CPE ID</td><td>%s</td></tr>\n" %
  948. stats["no-cpe-id"])
  949. f.write("</table>\n")
  950. def dump_html_gen_info(f, date, commit):
  951. # Updated on Mon Feb 19 08:12:08 CET 2018, Git commit aa77030b8f5e41f1c53eb1c1ad664b8c814ba032
  952. f.write("<p><i>Updated on %s, git commit %s</i></p>\n" % (str(date), commit))
  953. def dump_html(packages, stats, date, commit, output):
  954. with open(output, 'w') as f:
  955. f.write(html_header)
  956. dump_html_all_pkgs(f, packages)
  957. dump_html_stats(f, stats)
  958. dump_html_gen_info(f, date, commit)
  959. f.write(html_footer)
  960. def dump_json(packages, defconfigs, stats, date, commit, output):
  961. # Format packages as a dictionnary instead of a list
  962. # Exclude local field that does not contains real date
  963. excluded_fields = ['url_worker', 'name']
  964. pkgs = {
  965. pkg.name: {
  966. k: v
  967. for k, v in pkg.__dict__.items()
  968. if k not in excluded_fields
  969. } for pkg in packages
  970. }
  971. defconfigs = {
  972. d.name: {
  973. k: v
  974. for k, v in d.__dict__.items()
  975. } for d in defconfigs
  976. }
  977. # Aggregate infrastructures into a single dict entry
  978. statistics = {
  979. k: v
  980. for k, v in stats.items()
  981. if not k.startswith('infra-')
  982. }
  983. statistics['infra'] = {k[6:]: v for k, v in stats.items() if k.startswith('infra-')}
  984. # The actual structure to dump, add commit and date to it
  985. final = {'packages': pkgs,
  986. 'stats': statistics,
  987. 'defconfigs': defconfigs,
  988. 'package_status_checks': Package.status_checks,
  989. 'commit': commit,
  990. 'date': str(date)}
  991. with open(output, 'w') as f:
  992. json.dump(final, f, indent=2, separators=(',', ': '))
  993. f.write('\n')
  994. def resolvepath(path):
  995. return os.path.abspath(os.path.expanduser(path))
  996. def list_str(values):
  997. return values.split(',')
  998. def parse_args():
  999. parser = argparse.ArgumentParser()
  1000. output = parser.add_argument_group('output', 'Output file(s)')
  1001. output.add_argument('--html', dest='html', type=resolvepath,
  1002. help='HTML output file')
  1003. output.add_argument('--json', dest='json', type=resolvepath,
  1004. help='JSON output file')
  1005. packages = parser.add_mutually_exclusive_group()
  1006. packages.add_argument('-c', dest='configpackages', action='store_true',
  1007. help='Apply to packages enabled in current configuration')
  1008. packages.add_argument('-n', dest='npackages', type=int, action='store',
  1009. help='Number of packages')
  1010. packages.add_argument('-p', dest='packages', action='store',
  1011. help='List of packages (comma separated)')
  1012. parser.add_argument('--nvd-path', dest='nvd_path',
  1013. help='Path to the local NVD database', type=resolvepath)
  1014. parser.add_argument('--disable', type=list_str,
  1015. help='Features to disable, comma-separated (cve, upstream, url, cpe, warning)',
  1016. default=[])
  1017. args = parser.parse_args()
  1018. if not args.html and not args.json:
  1019. parser.error('at least one of --html or --json (or both) is required')
  1020. return args
  1021. def __main__():
  1022. global cvecheck
  1023. args = parse_args()
  1024. if args.nvd_path:
  1025. import cve as cvecheck
  1026. show_info_js = None
  1027. if args.packages:
  1028. package_list = args.packages.split(",")
  1029. elif args.configpackages:
  1030. show_info_js = get_show_info_js()
  1031. package_list = set([v["name"] for v in show_info_js.values() if 'name' in v])
  1032. else:
  1033. package_list = None
  1034. date = datetime.datetime.utcnow()
  1035. commit = subprocess.check_output(['git', '-C', brpath,
  1036. 'rev-parse',
  1037. 'HEAD']).splitlines()[0].decode()
  1038. print("Build package list ...")
  1039. packages = get_pkglist(args.npackages, package_list)
  1040. print("Getting developers ...")
  1041. developers = parse_developers()
  1042. print("Build defconfig list ...")
  1043. defconfigs = get_defconfig_list()
  1044. for d in defconfigs:
  1045. d.set_developers(developers)
  1046. print("Getting package make info ...")
  1047. package_init_make_info()
  1048. print("Getting package details ...")
  1049. for pkg in packages:
  1050. pkg.set_infra(show_info_js)
  1051. pkg.set_license()
  1052. pkg.set_hash_info()
  1053. pkg.set_patch_count()
  1054. if "warnings" not in args.disable:
  1055. pkg.set_check_package_warnings()
  1056. pkg.set_current_version()
  1057. pkg.set_cpeid()
  1058. pkg.set_url()
  1059. pkg.set_ignored_cves()
  1060. pkg.set_developers(developers)
  1061. if "url" not in args.disable:
  1062. print("Checking URL status")
  1063. loop = asyncio.get_event_loop()
  1064. loop.run_until_complete(check_package_urls(packages))
  1065. if "upstream" not in args.disable:
  1066. print("Getting latest versions ...")
  1067. loop = asyncio.get_event_loop()
  1068. loop.run_until_complete(check_package_latest_version(packages))
  1069. if "cve" not in args.disable and args.nvd_path:
  1070. print("Checking packages CVEs")
  1071. check_package_cves(args.nvd_path, packages)
  1072. if "cpe" not in args.disable and args.nvd_path:
  1073. print("Checking packages CPEs")
  1074. check_package_cpes(args.nvd_path, packages)
  1075. print("Calculate stats")
  1076. stats = calculate_stats(packages)
  1077. if args.html:
  1078. print("Write HTML")
  1079. dump_html(packages, stats, date, commit, args.html)
  1080. if args.json:
  1081. print("Write JSON")
  1082. dump_json(packages, defconfigs, stats, date, commit, args.json)
  1083. __main__()