Skip to content

Commit 3f066f7

Browse files
committed
(re)added all samples to docs script
1 parent 591322e commit 3f066f7

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

docs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ADD_CUSTOM_TARGET(generate_doc_sources
1515
--log error
1616
--log oneline
1717
--define "\"${DEFINEARG}\""
18-
-- --script scripts/python/docs.py --input docs --format rst --output ext/docs
18+
-- --script scripts/python/docs.py --input docs --output ext/docs
1919
WORKING_DIRECTORY ${BUILD_ROOT_FOLDER}
2020
DEPENDS nscp ${ALL_MODULE_NAMES} copy_files
2121
COMMENT "Generate RST documentation source")

ext/docs

scripts/python/docs.py

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,41 @@
223223
{% endfor %}
224224
"""
225225

226+
227+
samples_template = u""".. default-domain:: nscp
228+
229+
.. default-domain:: nscp
230+
231+
===========
232+
All samples
233+
===========
234+
235+
A collection of all sample commands
236+
237+
{% for mk,module in plugins|dictsort -%}
238+
{% set vars = {'found': False} -%}
239+
{% for qk,query in module.queries|dictsort -%}
240+
{% if query.sample -%}
241+
{% if vars.update({'found': True}) -%}{%- endif %}
242+
{%- endif %}
243+
{%- endfor %}
244+
{% if vars.found -%}
245+
{{mk|rst_heading('=')}}
246+
247+
{% for qk,query in module.queries|dictsort -%}
248+
{% if query.sample -%}
249+
{{qk|rst_heading}}
250+
251+
{{query.info.description|firstline}}
252+
253+
.. include:: ../samples/{{query.sample}}
254+
255+
{% endif %}
256+
{%- endfor %}
257+
{%- endif %}
258+
{%- endfor %}
259+
"""
260+
226261
def split_argllist(name, desc):
227262
extdata = {}
228263
spos = desc.find('\n\n')
@@ -298,7 +333,6 @@ def append_plugin(self, info):
298333
else:
299334
namespace = 'misc'
300335

301-
print "%s == %s"%(name, namespace)
302336
if not name in self.plugins:
303337
self.plugins[name] = plugin_container(info, namespace)
304338

@@ -590,6 +624,18 @@ def fetch_command(self, command, cinfo):
590624
def generate_rst(self, input_dir, output_dir):
591625
root = self.get_info()
592626
i = 0
627+
628+
env = Environment(extensions=["jinja2.ext.do",])
629+
env.filters['firstline'] = first_line
630+
env.filters['rst_link'] = make_rst_link
631+
env.filters['rst_table'] = render_rst_table
632+
env.filters['rst_csvtable'] = render_rst_csv_table
633+
env.filters['rst_heading'] = render_rst_heading
634+
env.filters['extract_value'] = extract_value
635+
env.filters['block_pad'] = block_pad
636+
env.filters['common_head'] = calculate_common_head
637+
env.filters['as_text'] = as_text
638+
593639
for (module,minfo) in root.plugins.iteritems():
594640
out_base_path = '%s/reference/'%output_dir
595641
sample_base_path = '%s/samples/'%output_dir
@@ -625,31 +671,25 @@ def generate_rst(self, input_dir, output_dir):
625671
i=i+1
626672
log_debug('Processing module: %d of %d [%s]'%(i, len(root.plugins), module))
627673

628-
env = Environment(extensions=["jinja2.ext.do",])
629-
env.filters['firstline'] = first_line
630-
env.filters['rst_link'] = make_rst_link
631-
env.filters['rst_table'] = render_rst_table
632-
env.filters['rst_csvtable'] = render_rst_csv_table
633-
env.filters['rst_heading'] = render_rst_heading
634-
env.filters['extract_value'] = extract_value
635-
env.filters['block_pad'] = block_pad
636-
env.filters['common_head'] = calculate_common_head
637-
env.filters['as_text'] = as_text
638-
639674
template = env.from_string(module_template)
640675
render_template(hash, template, '%s/%s.rst'%(out_base_path, module))
641676

677+
log_debug('%s/samples/index.rst'%output_dir)
678+
hash = root.get_hash()
679+
template = env.from_string(samples_template)
680+
render_template(hash, template, '%s/samples/index.rst'%output_dir)
681+
642682
def main(self, args):
643683
parser = OptionParser(prog="")
644684
parser.add_option("-o", "--output", help="write report to FILE(s)")
645685
parser.add_option("-i", "--input", help="Reference folder")
646686
(options, args) = parser.parse_args(args=args)
647-
648687
self.generate_rst(options.input, options.output)
649688

650689
def __main__(args):
651690
global helper
652691
helper.main(args);
692+
return 0
653693

654694
def init(plugin_id, plugin_alias, script_alias):
655695
global helper

0 commit comments

Comments
 (0)