Пример #1
0
def setup_directory_category_cache():
    cache = {}
    sql = 'SELECT category_id, directory_id FROM category_directory ORDER BY directory_id'
    result = Directory._connection.queryAll(sql)
    for (cid, did) in result:
        append_value_to_cache(cache, did, cid)
    return cache
Пример #2
0
def populate_host_asn_cache(cache, host):
    if not host.asn_clients: return cache
    if host.asn is not None:
        append_value_to_cache(cache, host.asn, host.id)

    for peer_asn in list(host.peer_asns):
        append_value_to_cache(cache, peer_asn.asn, host.id)
    return cache
Пример #3
0
 def _fill_file_details_cache():
     sql = 'SELECT id, directory_id, filename, timestamp from file_detail ORDER BY directory_id, filename, -timestamp'
     result = FileDetail._connection.queryAll(sql)
     cache = dict()
     for (id, directory_id, filename, timestamp) in result:
         k = (directory_id, filename)
         v = dict(file_detail_id=id, timestamp=timestamp)
         append_value_to_cache(cache, k, v)
     Directory.file_details_cache = cache
Пример #4
0
def file_details_cache():
    # cache{directoryname}{filename}[{details}]
    cache = {}
    # materialize this select to avoid making hundreds of thousands of queries
    for d in list(Directory.select()):
        if len(d.fileDetails) > 0:
            cache[d.name] = {}
            for fd in list(d.fileDetails):
                details = dict(timestamp=fd.timestamp, sha1=fd.sha1, md5=fd.md5, sha256=fd.sha256, sha512=fd.sha512, size=fd.size)
                append_value_to_cache(cache[d.name], fd.filename, details)
    return cache
Пример #5
0
def populate_netblock_cache(cache, host):
    if host.is_active() and len(host.netblocks) > 0:
        for n in list(host.netblocks):
            try:
                ip = IP(n.netblock)
                ips = [ip]
            except ValueError:
                # probably a string
                ips = name_to_ips(n.netblock)

            for ip in ips:
                append_value_to_cache(cache, ip, host.id)
    return cache
Пример #6
0
def add_host_to_cache(cache, hostid, value):
    append_value_to_cache(cache, hostid, value)