Changeset 13935 in genesis
- Timestamp:
- Jul 6, 2017, 8:56:40 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/gformat.py
r13930 r13935 1 #!/usr/ bin/envpython1 #!/usr/local/bin/python 2 2 # 3 3 # vim:ts=2:et:sw=2:ai … … 7 7 # 8 8 # Sample apache configuration (mind the AcceptPathInfo!) 9 # ScriptAlias /wleiden/config /usr/local/www/genesis/tools/gformat.py 10 # <Directory /usr/local/www/genesis> 11 # Allow from all 12 # AcceptPathInfo On 13 # </Directory> 14 # 15 # MUCH FASTER WILL IT BE with mod_wsgi, due to caches and avoiding loading all 16 # the heavy template lifting all the time. 17 # 18 # WSGIDaemonProcess gformat threads=25 19 # WSGISocketPrefix run/wsgi 9 # Alias /config /usr/local/www/config 10 # <Directory /usr/local/www/config> 11 # AddHandler cgi-script .py 12 # Require all granted 20 13 # 21 # <Directory /var/www/cgi-bin> 22 # WSGIProcessGroup gformat 14 # RewriteEngine on 15 # RewriteCond %{REQUEST_FILENAME} !-f 16 # RewriteRule ^(.*)$ gformat.py/$1 [L,QSA] 17 # Options +FollowSymlinks +ExecCGI 23 18 # </Directory> 24 # WSGIScriptAlias /hello /var/www/cgi-bin/genesis/tools/gformat.py25 19 # 26 20 # Package dependencies list: … … 99 93 NODE_DIR = os.environ['CONFIGROOT'] 100 94 else: 101 NODE_DIR = os.path.abspath(os.path.dirname( __file__)) + '/../nodes'95 NODE_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) + '/../nodes' 102 96 __version__ = '$Id$' 97 98 CACHE_DIR = os.path.abspath(os.path.dirname(__file__)) 103 99 104 100 files = [ … … 435 431 return "\n".join(files) 436 432 437 def generate_node_overview(host ):433 def generate_node_overview(host, datadump=False): 438 434 """ Print overview of all files available for node """ 439 datadump = get_yaml(host) 435 if not datadump: 436 datadump = get_yaml(host) 440 437 params = { 'host' : host } 441 438 output = "<em><a href='..'>Back to overview</a></em><hr />" … … 443 440 for cf in files: 444 441 params['cf'] = cf 445 output += '<li><a href="%( host)s/%(cf)s">%(cf)s</a></li>\n' % params442 output += '<li><a href="%(cf)s">%(cf)s</a></li>\n' % params 446 443 output += "</ul>" 447 444 … … 459 456 continue 460 457 params = { 'remote': remote, 'remote_ip' : ifacedump['ip'] } 461 output += '<li><a href=" %(remote)s">%(remote)s</a> -- %(remote_ip)s</li>\n' % params458 output += '<li><a href="../%(remote)s">%(remote)s</a> -- %(remote_ip)s</li>\n' % params 462 459 output += "</ul>" 463 460 output += "<h2>MOTD details:</h2><pre>" + generate_motd(datadump) + "</pre>" … … 1489 1486 reload_cache() 1490 1487 else: 1491 base_uri = environ[' PATH_INFO']1492 uri = base_uri.strip('/').split('/') 1488 base_uri = environ['REQUEST_URI'] 1489 uri = base_uri.strip('/').split('/')[1:] 1493 1490 1494 1491 output = "Template Holder" … … 1499 1496 content_type='application/json' 1500 1497 output = make_network_kml.make_nodeplanner_json() 1501 elif not uri [0]:1498 elif not uri: 1502 1499 if is_text_request(environ): 1503 1500 output = '\n'.join(get_hostlist()) … … 1510 1507 else: 1511 1508 content_type = 'text/html' 1512 output = generate_node_overview(uri[0])1509 output = open(os.path.join(CACHE_DIR, uri[0], 'index.html'), 'r').read() 1513 1510 elif len(uri) == 2: 1514 1511 output = generate_config(uri[0], uri[1]) … … 1812 1809 """Hard working sub""" 1813 1810 # Allow easy hacking using the CLI 1814 if not os.environ.has_key(' PATH_INFO'):1811 if not os.environ.has_key('REQUEST_URI'): 1815 1812 if len(sys.argv) < 2: 1816 1813 usage() … … 1869 1866 print generate_config(node, config, datadump) 1870 1867 elif sys.argv[1] == "test-cgi": 1871 os.environ[' PATH_INFO'] = "/".join(sys.argv[2:])1868 os.environ['REQUEST_URI'] = "/".join(['config'] + sys.argv[2:]) 1872 1869 os.environ['SCRIPT_NAME'] = __file__ 1873 1870 response_headers, output = process_cgi_request() … … 1882 1879 os.makedirs(items['wdir']) 1883 1880 datadump = get_yaml(node) 1881 f = open("%(wdir)s/index.html" % items, "w") 1882 f.write(generate_node_overview(items['node'], datadump)) 1883 f.close() 1884 1884 for config in files: 1885 1885 items['config'] = config
Note:
See TracChangeset
for help on using the changeset viewer.