blob: d71edc823ef9c79b66edec9898be6c8c5b49041f [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."""
Max2f266e02018-01-03 17:35:59 +01007from __future__ import print_function
Kata7185c62013-04-04 17:31:13 +02008import 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()
Max2f266e02018-01-03 17:35:59 +010024 print('generated %r' % filename)
Kata7185c62013-04-04 17:31:13 +020025
26
27"""Dump the config of all the apps.
28
29Returns the number of apps configs could not be dumped for."""
30
31
Neels Hofmeyr8e4806c2017-09-18 16:01:44 +020032def dump_configs(apps, configs, confpath):
Kata7185c62013-04-04 17:31:13 +020033 failures = 0
34 successes = 0
35
36 try: # make sure the doc directory exists
37 os.mkdir('doc')
38 except OSError: # it probably does
39 pass
40
41 for app in apps:
42 appname = app[3]
Max2f266e02018-01-03 17:35:59 +010043 print("Starting app for %s" % appname)
Kata7185c62013-04-04 17:31:13 +020044 proc = None
Neels Hofmeyr8e4806c2017-09-18 16:01:44 +020045 cmd = [app[1], "-c", os.path.join(confpath, configs[appname][0])]
Max2f266e02018-01-03 17:35:59 +010046 print('cd', os.path.abspath(os.path.curdir), ';', ' '.join(cmd))
Kata7185c62013-04-04 17:31:13 +020047 try:
48 proc = subprocess.Popen(cmd, stdin=None, stdout=None)
Neels Hofmeyra784f242017-09-18 16:02:55 +020049 except OSError as e: # Probably a missing binary
Max2f266e02018-01-03 17:35:59 +010050 print(e, file=sys.stderr)
51 print("Skipping app %s" % appname, file=sys.stderr)
Kata7185c62013-04-04 17:31:13 +020052 failures += 1
53 else:
Kata7185c62013-04-04 17:31:13 +020054 try:
55 dump_doc(app[2], app[0], 'doc/%s_vty_reference.xml' % appname)
56 successes += 1
57 except IOError: # Generally a socket issue
Max2f266e02018-01-03 17:35:59 +010058 print("%s: couldn't connect, skipping" % appname, file=sys.stderr)
Kata7185c62013-04-04 17:31:13 +020059 failures += 1
60 finally:
61 osmoutil.end_proc(proc)
62
63 return (failures, successes)
64
65
66if __name__ == '__main__':
67 import argparse
68
69 confpath = "."
70 workdir = "."
71
72 parser = argparse.ArgumentParser()
73 parser.add_argument("-p", "--pythonconfpath", dest="p",
74 help="searchpath for config (osmoappdesc)")
75 parser.add_argument("-w", "--workdir", dest="w",
76 help="Working directory to run in")
77 args = parser.parse_args()
78
79 if args.p:
80 confpath = args.p
81
82 if args.w:
83 workdir = args.w
84
Katcd564fc2013-04-06 11:11:49 +020085 osmoappdesc = osmoutil.importappconf_or_quit(
86 confpath, "osmoappdesc", args.p)
Kata7185c62013-04-04 17:31:13 +020087
Neels Hofmeyr8e4806c2017-09-18 16:01:44 +020088 confpath = os.path.relpath(confpath, workdir)
Kata7185c62013-04-04 17:31:13 +020089 os.chdir(workdir)
90 num_fails, num_sucs = dump_configs(
Neels Hofmeyr8e4806c2017-09-18 16:01:44 +020091 osmoappdesc.apps, osmoappdesc.app_configs, confpath)
Kata7185c62013-04-04 17:31:13 +020092 if num_fails > 0:
Max2f266e02018-01-03 17:35:59 +010093 print("Warning: Skipped %s apps" % num_fails, file=sys.stderr)
Kata7185c62013-04-04 17:31:13 +020094 if 0 == num_sucs:
Max2f266e02018-01-03 17:35:59 +010095 print("Nothing run, wrong working dir? Set with -w", file=sys.stderr)
Kata7185c62013-04-04 17:31:13 +020096 sys.exit(num_fails)