#!/usr/bin/env python3
# -*-coding:utf8 -*
"""openedx2zim.

Usage:
  openedx2zim <course_url> <publisher> <email> [--password=<pass>] [--nozim] [--zimpath=<zimpath>] [--nofulltextindex] [--transcode2webm] [--ignore-unsupported-xblocks] [--lang=<lang>]
  openedx2zim (-h | --help)
  openedx2zim --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --password=<pass> you can specify password as arguments or you'll be asked for password
  --nozim       doesn't make zim file, output will be in work/ in normal html
  --zimpath=<zimpath>   Final path of the zim file
  --nofulltextindex        Dont index content
  --transcode2webm  Transcode videos in webm
  --ignore-unsupported-xblocks  Ignore unsupported content (xblock)
  --lang 	Default lang of interface, and lang of zim content (in ISO639-1 : "en", "fr" etc..)

"""

from docopt import docopt
import sys
import os
import logging

from openedxtozim.utils import check_missing_binary,jinja_init
from openedxtozim.connection import Connection
from openedxtozim.mooc import Mooc

def run():
    arguments = docopt(__doc__, version='0.5.1')
    logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

    logging.info("Test (missing) bin")
    check_missing_binary(arguments['--nozim'])
    logging.info("Testing connection")
    c=Connection(arguments["--password"], arguments["<course_url>"], arguments["<email>"])

    jinja_init()

    mooc=Mooc(c,arguments["<course_url>"], arguments["--transcode2webm"], arguments["--ignore-unsupported-xblocks"], arguments["--lang"])
    mooc.parser_json()
    mooc.annexe(c)
    mooc.download(c)
    mooc.render()
    if not arguments['--nozim']:
        mooc.zim(arguments["<publisher>"],arguments["--zimpath"],arguments["--nofulltextindex"])

if __name__ == '__main__':
    run()

