#!/usr/bin/python

import sys
import getopt

from mnemosyne import get_conf
from mnemosyne.muse import Muse

if __name__ == '__main__':
    shortopts = 'fh'
    longopts = ['force', 'help']

    try:
        opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
    except getopt.GetoptError, e:
        print >>sys.stderr, 'error: %s' % e
        sys.exit(1)

    force=False
    for opt, arg in opts:
        if opt in ('--force', '-f'):
            force = True
        if opt in ('--help', '-h'):
            print "usage: mnemosyne [--force] [configfile]"
            sys.exit(0)

    try:
        config = args[0]
    except IndexError:
        config = get_conf('config.py')

    try:
        muse = Muse(config, force)
        muse.sing()
    except RuntimeError, e:
        print >>sys.stderr, e
        sys.exit(1)
