forked from sopel-irc/sopel-extras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
document.py
64 lines (56 loc) · 2.9 KB
/
document.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
57
58
59
60
61
62
63
64
from willie import coretasks
from willie.module import commands
import os
import subprocess
def configure(config):
"""
| [document] | example | purpose |
| ---------- | ------- | ------- |
| layout | default | The jekyll layout to use for the commands page |
| base_dir | /home/user/willie-website | The location of the jekyll site source |
| plugins_dir | /home/user/willie-website/_plugins | The location of the jekyll plugins directory |
| layouts_dir | /home/user/willie-website/_layouts | The location of the jekyll layouts directory |
| output_dir | /var/www/willie | The location of the jekyll generated site |
| jekyll_location | /opt/jekyll/jekyll | The location of the jekyll executable. Not needed if jekyll is on the user's PATH |
"""
if config.option('Compile command listings to a Jekyll site', False):
config.add_section('document')
config.interactive_add('document', 'layout',
'The jekyll layout to use for the commands page')
config.interactive_add('document', 'base_dir',
'The location of the jekyll site source ')
config.interactive_add('document', 'plugins_dir',
'The location of the jekyll plugins directory')
config.interactive_add('document', 'layouts_dir',
'The location of the jekyll layouts directory')
config.interactive_add('document', 'output_dir',
'The location of the jekyll generated site')
config.interactive_add('document', 'jekyll_location',
"The location of the jekyll executable. Not needed if jekyll is on"
" the user's PATH.")
def setup(bot):
if not bot.config.document.base_dir:
raise ConfigurationError('Must provide Jekyll base_dir')
@commands('document')
def document(bot, trigger):
conf = bot.config.document
layout = conf.layout or 'default'
base_dir = conf.base_dir
output_dir = conf.output_dir or os.path.join(base_dir, '_site')
with open(os.path.join(base_dir, 'modules.md'), 'w') as f:
front_matter = '''---\nlayout: {}\ntitle: {} commands list\n---\n\n'''
f.write(front_matter.format(layout, bot.nick))
f.write('| Command | Purpose | Example |\n')
f.write('| ------- | ------- | ------- |\n')
for command in sorted(bot.doc.iterkeys()):
doc = bot.doc[command]
docstring = doc[0].replace('\n\n', '<br />').replace('\n', ' ')
f.write('| {} | {} | {} |\n'.format(command, docstring, doc[1]))
command = "{} build -s {} -d {}"
command = command.format(conf.jekyll_location or 'jekyll', base_dir,
output_dir)
# We don't give a shit what it says, but it fucking crashes if we don't
# listen. Fucking needy asshole piece of Ruby shit.
data = subprocess.Popen(command.split(' '), stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
bot.say('Finished processing documentation.')