Exemplo n.º 1
0
def main(args=sys.argv[1:]):
    """
    main :)
    @param args: the args used for the parser, just useful for testing
    """
    parser = argparse.ArgumentParser(description='Tool MainExecutable')
    parser.add_argument('-d', '--database', type=str, metavar='"Connection String"', required=True)
    parser.add_argument('-c', '--config', type=str, metavar='"Config Path"', default='configfile.xml')
    parser.add_argument('--debug', action='store_true')

    args = parser.parse_args(args)

    database.DATABASE_STRING = args.database
    database_logging.start_logging_process()
    database_logging.configure_logger()

    loop = asyncio.get_event_loop()
    loop.call_soon(run, args.config)
    loop.run_forever()

    return 0
Exemplo n.º 2
0
def run(folder, interval):
    """
    @param folder: The Folder that should be Scanned
    @param interval: The interval in which it should be scanned, None if only once, else the time in seconds
    """

    database_logging.configure_logger()
    logging.info('Scanner started with: folder=%s, interval=%s' % (folder, interval))

    folder = Path(folder.path)

    dir_queue = Queue()
    init(workers=40, queue=dir_queue)

    while True:
        start = datetime.now()
        if dir_queue.empty():  # Only add the Root folder if the Queue is empty.
            dir_queue.put(folder)
        dir_queue.join()
        logging.debug('Scanner round Completed in %s' % (datetime.now() - start))
        if interval is None:
            break  # This is used for debugging
        time.sleep(interval)