Skip to content

Instantly share code, notes, and snippets.

@ttimasdf
Last active December 18, 2017 02:04
Show Gist options
  • Save ttimasdf/a2f34aee0c4179a9d8257fc68c7136d5 to your computer and use it in GitHub Desktop.
Save ttimasdf/a2f34aee0c4179a9d8257fc68c7136d5 to your computer and use it in GitHub Desktop.
My cve-search patch
diff --git a/sbin/db_mgmt_cpe_dictionary.py b/sbin/db_mgmt_cpe_dictionary.py
index 4c904cf..37cd9c8 100755
--- a/sbin/db_mgmt_cpe_dictionary.py
+++ b/sbin/db_mgmt_cpe_dictionary.py
@@ -31,6 +31,7 @@ from lib.ProgressBar import progressbar
from lib.Toolkit import toStringFormattedCPE
from lib.Config import Configuration
import lib.DatabaseLayer as db
+from time import time
class CPEHandler(ContentHandler):
def __init__(self):
@@ -76,6 +77,7 @@ ch = CPEHandler()
parser.setContentHandler(ch)
# check modification date
try:
+ print("Start getting feed data...", flush=True)
(f, r) = Configuration.getFeedData('cpe')
except:
sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(Configuration.getFeedURL("cpe")))
@@ -86,7 +88,9 @@ if i is not None:
print("Not modified")
sys.exit(0)
# parse xml and store in database
+start = time()
parser.parse(f)
+print("Parse succedded with {:.2f} seconds".format(time() - start))
cpeList=[]
for x in progressbar(ch.cpe):
x['id']= toStringFormattedCPE(x['name'])
@@ -94,7 +98,10 @@ for x in progressbar(ch.cpe):
x['cpe_2_2'] = x.pop('name')
if not x['references']: x.pop('references')
cpeList.append(x)
+ print(len(cpeList), "out of", len(ch.cpe), end='\r')
+print("\nstart db bulk update", flush=True)
db.bulkUpdate("cpe", cpeList)
#update database info after successful program-run
+print("start col update", flush=True)
db.setColUpdate('cpe', last_modified)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment