@@ -0,0 +1,1427 @@
+%22%22%22Prune database and disk of old images.%22%22%22%0A%0Afrom datetime import datetime, timedelta%0Aimport os%0Aimport sys%0Aimport shutil%0Aimport cv2%0A%0Afrom sqlalchemy import create_engine%0Afrom sqlalchemy.orm import sessionmaker%0A%0Afrom coils import Config, string2time, time2fname, time2levels%0A%0ASECONDS = float(sys.argv%5B1%5D)%0A%0A# Load configuration file.%0Aconfig = Config('wabbit.cfg')%0A%0A# Connect to database engine and start a session.%0Aengine = create_engine(%0A    'mysql://%7B%7D:%7B%7D@%7B%7D/%7B%7D'.format(%0A        config%5B'username'%5D, config%5B'password'%5D, %0A        config%5B'host'%5D, config%5B'db_name'%5D))%0Aconn = engine.connect()%0Asession = sessionmaker(bind=engine)()%0A%0A# Compute the oldest timestamp allowed.%0Anow = datetime.now()%0Adelta = timedelta(seconds=SECONDS)%0Athen = now - delta%0A%0A# Remove from database.%0Afrom Image import Image, Base%0ABase.metadata.create_all(engine)%0Asession.query(Image).filter(Image.tstamp%3Cthen).delete()%0Asession.commit()%0A%0A# Delete from disk.%0Alevels = time2levels(then)%0Asaved = os.getcwd()%0Aos.chdir(config%5B'pics_dir'%5D)%0Afor level in levels:%0A    %0A    for entry in os.listdir('.'):%0A        try:%0A            int_entry = int(entry)%0A        except:%0A            continue%0A        if int_entry %3C int(level):%0A            full = os.path.join(os.getcwd(), entry)%0A            print('Erasing %7B%7D'.format(full))%0A            shutil.rmtree(full)%0A%0A    # Skip if not a directory.%0A    if not os.path.isdir(level):%0A        break%0A    os.chdir(level)%0A%0Aos.chdir(saved)%0A%0A

Add pruner.