Changeset 8258 in genesis


Ignore:
Timestamp:
Aug 8, 2010, 9:58:32 AM (14 years ago)
Author:
rick
Message:
  • More generic paths
  • Hack to allow easy checking
File:
1 edited

Legend:

Unmodified
Added
Removed
  • nodes/gformat.py

    r8257 r8258  
    1414import yaml
    1515
     16NODE_DIR = os.path.dirname(os.path.realpath(__file__))
    1617__version__ = '$Id$'
    1718
     
    2627
    2728
    28 def print_title():
     29def print_title(nodelist):
    2930  """ Main overview page """
    3031  items = {'root' : os.environ['SCRIPT_NAME'] }
     
    236237def get_yaml(item):
    237238  """ Get configuration yaml for 'item'"""
    238   gfile = item + '/wleiden.yaml'
     239  gfile = NODE_DIR + '/%s/wleiden.yaml' % item
    239240  gfile = 'test.yaml'
    240241
     
    260261 
    261262  # proxyX sorting based on X number
     263  os.chdir(NODE_DIR)
    262264  proxies = sorted(glob.glob("proxy*"),
    263265              key=lambda name: int(''.join([c for c in name if c in string.digits])),
     
    273275def generate_wleiden_yaml(datadump):
    274276  """ Special formatting to ensure it is editable"""
    275   output = "# Genesis config yaml style\n"
     277  output = generate_header("#")
     278  output += "# Genesis config yaml style\n"
    276279  output += "#\n"
    277280  iface_keys = [elem for elem in datadump.keys() if elem.startswith('iface_')]
     
    322325
    323326
    324 #
    325 # Main worker
    326 
    327 # Update repository if requested
    328 form = cgi.FieldStorage()
    329 if form.getvalue("action") == "update":
    330   print "Refresh: 5; url=%s" % os.environ['SCRIPT_NAME']
    331   print "Content-type:text/plain\r\n\r\n",
    332   print "[INFO] Updating subverion, please wait..."
    333   print subprocess.Popen(['svn', 'up', '/home/rvdzwet/wleiden/genesis/nodes'], stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0],
    334   print "[INFO] All done, redirecting in 5 seconds"
    335   sys.exit(0)
    336 
    337 nodelist = glob.glob("CNode*")
    338 
    339 uri = os.environ['PATH_INFO'].strip('/').split('/')
    340 if not uri[0]:
    341   print_title()
    342 elif len(uri) == 1:
    343   print "Content-type:text/plain\r\n\r\n",
    344   print_node(uri[0])
    345 elif len(uri) == 2:
    346   print "Content-type:text/plain\r\n\r\n",
    347   print_config(uri[0], uri[1])
    348 else:
    349   assert False, "Invalid option"
    350 
    351 sys.exit(0)
     327
     328def process_cgi_request():
     329  """ When calling from CGI """
     330  # Update repository if requested
     331  form = cgi.FieldStorage()
     332  if form.getvalue("action") == "update":
     333    print "Refresh: 5; url=%s" % os.environ['SCRIPT_NAME']
     334    print "Content-type:text/plain\r\n\r\n",
     335    print "[INFO] Updating subverion, please wait..."
     336    print subprocess.Popen(['svn', 'up', NODE_DIR], stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0],
     337    print "[INFO] All done, redirecting in 5 seconds"
     338    sys.exit(0)
     339 
     340  os.chdir(NODE_DIR)
     341  nodelist = glob.glob("CNode*")
     342 
     343  uri = os.environ['PATH_INFO'].strip('/').split('/')
     344  if not uri[0]:
     345    print "Content-type:text/html\r\n\r\n",
     346    print_title(nodelist)
     347  elif len(uri) == 1:
     348    print "Content-type:text/plain\r\n\r\n",
     349    print_node(uri[0])
     350  elif len(uri) == 2:
     351    print "Content-type:text/plain\r\n\r\n",
     352    print_config(uri[0], uri[1])
     353  else:
     354    assert False, "Invalid option"
     355
     356# Allow easy hacking using the CLI
     357if not os.environ.has_key('PATH_INFO'):
     358  os.environ['PATH_INFO'] = "/".join(sys.argv[1:])
     359  os.environ['SCRIPT_NAME'] = __file__
     360
     361process_cgi_request()
Note: See TracChangeset for help on using the changeset viewer.