This repository has been archived by the owner on Jul 20, 2018. It is now read-only.
forked from ogom/python-mcider
/
main.py
56 lines (49 loc) · 1.62 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
""" mcider - main
Copyright(c) 2012 ogom
Mcider is to convert markdown into slideshow.
"""
import os
import webbrowser
from cli_helper import parser
import converter
import util
def main():
""" entry points """
args = parser.parse_args()
# path of the output file
output_path = os.path.abspath(os.path.dirname(args.file.name))
output_file = os.path.join(output_path, os.path.splitext(os.path.basename(args.file.name))[0] + '.html')
if args.output:
output_path = os.path.abspath(os.path.dirname(args.output.name))
output_file = os.path.abspath(args.output.name)
# slide options
opts = {
'themes': args.themes,
'theme': args.theme,
'contents': args.file.read().decode('utf-8'),
'extensions': args.extensions,
'clean': args.clean
}
# custom themes or default themes
if opts['themes'] is None or not os.path.isdir(opts['themes']):
opts['themes'] = os.path.abspath(os.path.join(os.path.dirname(__file__), 'themes'))
try:
# slide maker
slide = converter.Slide(opts)
html = slide.maker(output_path)
util.fs_writer(output_file, html)
if args.browser:
url = 'file://' + output_file
if slide.options['theme'] == 'io2012':
url += '?presentme='
url += 'true' if args.presenter else 'false'
webbrowser.open_new_tab(url)
except KeyError as e:
print "KeyError: %s" % e
else:
print "Output file is %s" % output_file
finally:
print 'Mcider is finished!'
if __name__ == '__main__':
main()