Commit 800ec48a authored by Alexandre Dulaunoy's avatar Alexandre Dulaunoy
Browse files

-l option added to limit the number of elements (default: unlimited)

parent 255d21e1
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -24,9 +24,9 @@ db = Configuration.getMongoConnection()
collection = db.cves


def dumpallcveid():
def dumpallcveid(limit=False):
    cveid = []
    for x in collection.find({}).sort('_id', 1):
    for x in collection.find({}).sort('_id', 1).limit(limit):
        cveid.append(x['id'])
    return cveid

@@ -34,6 +34,7 @@ argParser = argparse.ArgumentParser(description='Dump database in JSON format')
argParser.add_argument('-r', default=False, action='store_true', help='Include ranking value')
argParser.add_argument('-v', default=False, action='store_true', help='Include vfeed map')
argParser.add_argument('-c', default=False, action='store_true', help='Include CAPEC information')
argParser.add_argument('-l', default=False, type=int, help='Limit output to n elements (default: unlimited)')
args = argParser.parse_args()

rankinglookup = args.r
@@ -42,6 +43,6 @@ capeclookup = args.c

l = cves.last(rankinglookup=rankinglookup, vfeedlookup=vfeedlookup, capeclookup=capeclookup)

for cveid in dumpallcveid():
for cveid in dumpallcveid(limit=args.l):
    item = l.getcve(cveid=cveid)
    print (json.dumps(item, sort_keys=True, default=json_util.default))