# devilry.github.com.

from os import system, chdir, getcwd
from os.path import join
from shutil import rmtree, copytree
from tempfile import mkdtemp

from common import get_docs_buildhtml_dir, depends, Command

depends(Command('docs'),
        Command('docs_js'))


repo_rw_url = '[email protected]:devilry/devilry-django.git'
version = 'dev'
indir = get_docs_buildhtml_dir()

try:
    tempdir = mkdtemp()
    print 'Created temp dir', tempdir

    print 'Checking out devilry repo to tempdir.'
    chdir(tempdir)
    system("git clone --branch gh-pages {0} devilry".format(repo_rw_url))

    repocheckoutdir = join(tempdir, 'devilry')
    chdir(repocheckoutdir)
    system("git reset --hard")
    system("git clean -df")
    system("ls")
    system("pwd")
parser = DevilryAdmArgumentParser()
parser.add_argument('-b', '--openbrowser', action='store_true',
                    help='Open the docs in your default browser after building.')
parser.add_argument('--completionlist', action='store_true',
                   help='Print completionlist for bash completion.')
args = parser.parse_args()

if args.completionlist:
    print "--openbrowser"
    exit(0)

os.chdir(get_docsdir())
call(['make', 'html'])


indexpath = join(get_docs_buildhtml_dir(), 'index.html')

print '********************************************************************'
print 'HTML documentation for python code built successfully. View it here:'
print
print '   ', indexpath
print
print 'Use devilryadmin.py docs_upload_to_website to upload them to'
print 'the website if you have push permission on devilry/devilry-django/'
print '********************************************************************'

if args.openbrowser:
    print 'Opening in browser'
    webbrowser.open_new_tab('file:///' + indexpath)
#
# After running this script, you must manually commit and push
# devilry.github.com.

from os import system, chdir, getcwd
from os.path import join
from shutil import rmtree, copytree
from tempfile import mkdtemp

from common import get_docs_buildhtml_dir, depends, Command

depends(Command('docs'), Command('docs_js'))

repo_rw_url = '[email protected]:devilry/devilry-django.git'
version = 'dev'
indir = get_docs_buildhtml_dir()

try:
    tempdir = mkdtemp()
    print 'Created temp dir', tempdir

    print 'Checking out devilry repo to tempdir.'
    chdir(tempdir)
    system("git clone --branch gh-pages {0} devilry".format(repo_rw_url))

    repocheckoutdir = join(tempdir, 'devilry')
    chdir(repocheckoutdir)
    system("git reset --hard")
    system("git clean -df")
    system("ls")
    system("pwd")