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.""" |
| 7 | |
| 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() |
| 24 | |
| 25 | |
| 26 | """Dump the config of all the apps. |
| 27 | |
| 28 | Returns the number of apps configs could not be dumped for.""" |
| 29 | |
| 30 | |
| 31 | def 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 | |
| 64 | if __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 | |
Kat | cd564fc | 2013-04-06 11:11:49 +0200 | [diff] [blame] | 83 | osmoappdesc = osmoutil.importappconf_or_quit( |
| 84 | confpath, "osmoappdesc", args.p) |
Kat | a7185c6 | 2013-04-04 17:31:13 +0200 | [diff] [blame] | 85 | |
| 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) |