#!/usr/bin/env python3

import argparse
import sys


sys.path.insert(0, "/home/steveha/devel/py-yuna-db/src")

import yuna


_PROGRAM_DESCRIPTION = """
yuna_repack -- repack a Yuna file to minimum size

This program makes a copy of a Yuna database file, packed for
minimum size and maximum efficiency.  Since a Yuna database file
is really an LMDB database file, this works for any LMDB
database file.

Note that on Linux, sometimes ls will report a Yuna (LMDB) file as
having the maximum size specified when the database file was created.
For example, if you set the maximum size to 1 terabyte, ls may display
the file size as 1 terabyte.  Repacking the file fixes this.
""".strip()


parser = argparse.ArgumentParser(
    description=_PROGRAM_DESCRIPTION,
    formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument('fname', type=str, help='Filename of Yuna DB file to repack')

if len(sys.argv) < 2:
    sys.argv.append("--help")
args = parser.parse_args()

with yuna.YunaReadOnly(args.fname, None, None) as db:
    db.close()
    db.repack()
