blob: d9d52b5db0ddabd0d5045f0f755b5e7c32ab3462 [file] [log] [blame]
Kata7185c62013-04-04 17:31:13 +02001#!/usr/bin/env python
2
3# Make sure this code is in sync with the BTS directory.
4# Fixes may need to be applied to both.
5
6"""Start the process and dump the documentation to the doc dir."""
7
8import subprocess
9import time
10import os
11import sys
12
13import osmopy.obscvty as obscvty
14import osmopy.osmoutil as osmoutil
15
16
17def dump_doc(name, port, filename):
18 vty = obscvty.VTYInteract(name, "127.0.0.1", port)
19 xml = vty.command("show online-help")
20 # Now write everything until the end to the file
21 out = open(filename, 'w')
22 out.write(xml)
23 out.close()
24
25
26"""Dump the config of all the apps.
27
28Returns the number of apps configs could not be dumped for."""
29
30
31def dump_configs(apps, configs):
32 failures = 0
33 successes = 0
34
35 try: # make sure the doc directory exists
36 os.mkdir('doc')
37 except OSError: # it probably does
38 pass
39
40 for app in apps:
41 appname = app[3]
42 print "Starting app for %s" % appname
43 proc = None
44 cmd = [app[1], "-c", configs[appname][0]]
45 try:
46 proc = subprocess.Popen(cmd, stdin=None, stdout=None)
47 except OSError: # Probably a missing binary
48 print >> sys.stderr, "Skipping app %s" % appname
49 failures += 1
50 else:
51 time.sleep(1)
52 try:
53 dump_doc(app[2], app[0], 'doc/%s_vty_reference.xml' % appname)
54 successes += 1
55 except IOError: # Generally a socket issue
56 print >> sys.stderr, "%s: couldn't connect, skipping" % appname
57 failures += 1
58 finally:
59 osmoutil.end_proc(proc)
60
61 return (failures, successes)
62
63
64if __name__ == '__main__':
65 import argparse
66
67 confpath = "."
68 workdir = "."
69
70 parser = argparse.ArgumentParser()
71 parser.add_argument("-p", "--pythonconfpath", dest="p",
72 help="searchpath for config (osmoappdesc)")
73 parser.add_argument("-w", "--workdir", dest="w",
74 help="Working directory to run in")
75 args = parser.parse_args()
76
77 if args.p:
78 confpath = args.p
79
80 if args.w:
81 workdir = args.w
82
Katcd564fc2013-04-06 11:11:49 +020083 osmoappdesc = osmoutil.importappconf_or_quit(
84 confpath, "osmoappdesc", args.p)
Kata7185c62013-04-04 17:31:13 +020085
86 os.chdir(workdir)
87 num_fails, num_sucs = dump_configs(
88 osmoappdesc.apps, osmoappdesc.app_configs)
89 if num_fails > 0:
90 print >> sys.stderr, "Warning: Skipped %s apps" % num_fails
91 if 0 == num_sucs:
92 print >> sys.stderr, "Nothing run, wrong working dir? Set with -w"
93 sys.exit(num_fails)