Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 1 | #!/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.""" |
Max | 2f266e0 | 2018-01-03 17:35:59 +0100 | [diff] [blame] | 7 | from __future__ import print_function |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 8 | import subprocess |
| 9 | import time |
| 10 | import os |
| 11 | import sys |
| 12 | |
| 13 | import osmopy.obscvty as obscvty |
| 14 | import osmopy.osmoutil as osmoutil |
| 15 | |
| 16 | |
| 17 | def 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() |
Max | 2f266e0 | 2018-01-03 17:35:59 +0100 | [diff] [blame] | 24 | print('generated %r' % filename) |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 25 | |
| 26 | |
| 27 | """Dump the config of all the apps. |
| 28 | |
| 29 | Returns the number of apps configs could not be dumped for.""" |
| 30 | |
| 31 | |
Neels Hofmeyr | 8e4806c | 2017-09-18 16:01:44 +0200 | [diff] [blame] | 32 | def dump_configs(apps, configs, confpath): |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 33 | 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] |
Max | 2f266e0 | 2018-01-03 17:35:59 +0100 | [diff] [blame] | 43 | print("Starting app for %s" % appname) |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 44 | proc = None |
Neels Hofmeyr | 8e4806c | 2017-09-18 16:01:44 +0200 | [diff] [blame] | 45 | cmd = [app[1], "-c", os.path.join(confpath, configs[appname][0])] |
Max | 2f266e0 | 2018-01-03 17:35:59 +0100 | [diff] [blame] | 46 | print('cd', os.path.abspath(os.path.curdir), ';', ' '.join(cmd)) |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 47 | try: |
| 48 | proc = subprocess.Popen(cmd, stdin=None, stdout=None) |
Neels Hofmeyr | a784f24 | 2017-09-18 16:02:55 +0200 | [diff] [blame] | 49 | except OSError as e: # Probably a missing binary |
Max | 2f266e0 | 2018-01-03 17:35:59 +0100 | [diff] [blame] | 50 | print(e, file=sys.stderr) |
| 51 | print("Skipping app %s" % appname, file=sys.stderr) |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 52 | failures += 1 |
| 53 | else: |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 54 | try: |
| 55 | dump_doc(app[2], app[0], 'doc/%s_vty_reference.xml' % appname) |
| 56 | successes += 1 |
| 57 | except IOError: # Generally a socket issue |
Max | 2f266e0 | 2018-01-03 17:35:59 +0100 | [diff] [blame] | 58 | print("%s: couldn't connect, skipping" % appname, file=sys.stderr) |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 59 | failures += 1 |
| 60 | finally: |
| 61 | osmoutil.end_proc(proc) |
| 62 | |
| 63 | return (failures, successes) |
| 64 | |
| 65 | |
| 66 | if __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 | |
Kat | cd564fc | 2013-04-06 11:11:49 +0200 | [diff] [blame] | 85 | osmoappdesc = osmoutil.importappconf_or_quit( |
| 86 | confpath, "osmoappdesc", args.p) |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 87 | |
Neels Hofmeyr | 8e4806c | 2017-09-18 16:01:44 +0200 | [diff] [blame] | 88 | confpath = os.path.relpath(confpath, workdir) |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 89 | os.chdir(workdir) |
| 90 | num_fails, num_sucs = dump_configs( |
Neels Hofmeyr | 8e4806c | 2017-09-18 16:01:44 +0200 | [diff] [blame] | 91 | osmoappdesc.apps, osmoappdesc.app_configs, confpath) |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 92 | if num_fails > 0: |
Max | 2f266e0 | 2018-01-03 17:35:59 +0100 | [diff] [blame] | 93 | print("Warning: Skipped %s apps" % num_fails, file=sys.stderr) |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 94 | if 0 == num_sucs: |
Max | 2f266e0 | 2018-01-03 17:35:59 +0100 | [diff] [blame] | 95 | print("Nothing run, wrong working dir? Set with -w", file=sys.stderr) |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 96 | sys.exit(num_fails) |