84a7ed3ad3a03873ecedd6962ddd886f0b4dab89,sbin/db_mgmt_cwe.py,,,#,73

Before Change


// connect to db
db = Configuration.getMongoConnection()
cwedb = db.cwe
info = db.info

// make parser
parser = make_parser()
ch = CWEHandler()
parser.setContentHandler(ch)
// check modification date
try:
    f = Configuration.getFile(cwedict)
except:
    sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(cwedict))
lastmodified = f.headers["last-modified"]
i = info.find_one({"db": "cwe"})
if i is not None:
    if f.headers["last-modified"] == i["last-modified"]:
        print("Not modified")
        sys.exit(0)

// preparing xml by saving in a tempfile and unzipping
tmpdir = tempfile.gettempdir()
tmpfile = tempfile.NamedTemporaryFile()
cwezip = open(tmpfile.name, "wb")
cwezip.write(f.read())
cwezip.close()
with zipfile.ZipFile(tmpfile.name) as z:
    z.extractall(tmpdir)
    z.close()
f = open(os.path.join(tmpdir, "cwec_v2.8.xml"))
// parse xml and store in database
parser.parse(f)
bulk = cwedb.initialize_ordered_bulk_op()
for cwe in progressbar(ch.cwe):
    if args.v:
        print (cwe)
    bulk.find({"id": cwe["id"]}).upsert().update({"$set": {"name": cwe["name"], "id": cwe["id"], "status": cwe["status"], "weaknessabs": cwe["weaknessabs"]}})
bulk.execute()

//update database info after successful program-run
info.update({"db": "cwe"}, {"$set": {"last-modified": lastmodified}}, upsert=True)

After Change


except:
    sys.exit("Cannot open url %s. Bad URL or not connected to the internet?"%(cwedict))
lastmodified = f.headers["last-modified"]
i = dbLayer.getLastModified("cwe")
if i is not None:
    if lastmodified == i:
        print("Not modified")
        sys.exit(0)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 16

Instances


Project Name: cve-search/cve-search
Commit Name: 84a7ed3ad3a03873ecedd6962ddd886f0b4dab89
Time: 2015-10-16
Author: pieterjan.moreels@gmail.com
File Name: sbin/db_mgmt_cwe.py
Class Name:
Method Name:


Project Name: cve-search/cve-search
Commit Name: f59302d0d8aafc18d42d0e56e8c8a1d9b30f5af6
Time: 2015-10-21
Author: pieterjan.moreels@gmail.com
File Name: sbin/db_mgmt_vendorstatements.py
Class Name:
Method Name:


Project Name: cve-search/cve-search
Commit Name: 84a7ed3ad3a03873ecedd6962ddd886f0b4dab89
Time: 2015-10-16
Author: pieterjan.moreels@gmail.com
File Name: sbin/db_mgmt_cwe.py
Class Name:
Method Name:


Project Name: cve-search/cve-search
Commit Name: f59302d0d8aafc18d42d0e56e8c8a1d9b30f5af6
Time: 2015-10-21
Author: pieterjan.moreels@gmail.com
File Name: sbin/db_mgmt_capec.py
Class Name:
Method Name: