#!/usr/bin/env python
import sys;sys.path.append('./')
import scenethecizer
import lm_util
from commands import getoutput as shell_exec

google_fonts_url="https://github.com/google/fonts/archive/master.zip"


def download_google_fonts():
    tmp_dir="/tmp/font_download/"
    sys.stderr.write("Downloading fonts. This might take a while.\n...\n")
    cmd="mkdir -p "+tmp_dir+" && cd "+tmp_dir+" && wget -c "+google_fonts_url+" && unzip *.zip && echo 'SUCCESS'"
    print cmd
    print repr(shell_exec(cmd))

def list_fonts():
    fontnames=list(set([fnt.split(":")[1].strip() for fnt in shell_exec('fc-list').split("\n")]))
    print("\n".join(fontnames))
    print("\nTotal fonts available: %d"%len(fontnames))

def main():
    switches = {"quantum": "textlines", "letter_height": 30, 'plot_page': True, "max_pages_count": 0,
                "img_path_expr": "/tmp/example_ds/{}_{}.png","mode":"handwriting"}
    switches, help_str = lm_util.get_arg_switches(switches, argv=None)
    mode=switches['mode']
    del switches['mode']
    if mode == "handwriting":
        scenethecizer.demo_handwriting(**switches)
    elif mode == "printed":
        scenethecizer.demo_ocr(**switches)
    elif mode == "listfonts":
        list_fonts()
    else:
        print("Mode "+mode+" unrecognized aborting.")
    sys.exit()

if __name__=="__main__":
    sys.path.append('./')
    print sys.path
    main()