#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import syd
import click

# -----------------------------------------------------------------------------
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@click.command(context_settings=CONTEXT_SETTINGS)
@click.option('--db', default='',
              help='DB filename (SYD_DB_FILENAME environment variable is used if no filename)')
def syd_info(db):
    '''
    Print information about a syd db
    '''

    # open the db
    db_filename = syd.get_db_filename(db)
    db = syd.open_db(db_filename)

    # print file and folder
    print("Database: {}".format(db.absolute_filename))
    print("Image folder: {}".format(db.absolute_data_folder))

    # print tables and columns
    for table_name in db.tables:
        s = table_name+' '+str(len(db[table_name]))+' '
        for col in db[table_name].table.columns:
            c = str(col)[len(table_name)+1:]
            s = s+' '+c
        print(s)

# -----------------------------------------------------------------------------
if __name__ == '__main__':
    syd_info()

