lookyloo/tools/rebuild_caches.py

41 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2022-12-07 19:38:20 +01:00
import csv
import argparse
import logging
2021-09-07 12:59:31 +02:00
from lookyloo.lookyloo import Indexing, Lookyloo
2022-12-07 19:38:20 +01:00
from lookyloo.helpers import get_captures_dir
logging.basicConfig(format='%(asctime)s %(name)s %(levelname)s:%(message)s',
level=logging.INFO)
def main():
parser = argparse.ArgumentParser(description='Rebuild the redis cache.')
parser.add_argument('--rebuild_pickles', default=False, action='store_true', help='Delete and rebuild the pickles. Count 20s/pickle, it can take a very long time.')
args = parser.parse_args()
lookyloo = Lookyloo()
if args.rebuild_pickles:
lookyloo.rebuild_all()
else:
lookyloo.rebuild_cache()
indexing = Indexing()
indexing.clear_indexes()
2022-12-07 19:38:20 +01:00
# Initialize lookup_dirs key
for index in get_captures_dir().rglob('index'):
with index.open('r') as _f:
recent_uuids = {uuid: str(index.parent / dirname) for uuid, dirname in csv.reader(_f) if (index.parent / dirname).exists()}
if recent_uuids:
lookyloo.redis.hset('lookup_dirs', mapping=recent_uuids)
# This call will rebuild all the caches as needed.
lookyloo.sorted_capture_cache()
if __name__ == '__main__':
main()