Changeset 8258 in genesis
- Timestamp:
- Aug 8, 2010, 9:58:32 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
nodes/gformat.py
r8257 r8258 14 14 import yaml 15 15 16 NODE_DIR = os.path.dirname(os.path.realpath(__file__)) 16 17 __version__ = '$Id$' 17 18 … … 26 27 27 28 28 def print_title( ):29 def print_title(nodelist): 29 30 """ Main overview page """ 30 31 items = {'root' : os.environ['SCRIPT_NAME'] } … … 236 237 def get_yaml(item): 237 238 """ Get configuration yaml for 'item'""" 238 gfile = item + '/wleiden.yaml'239 gfile = NODE_DIR + '/%s/wleiden.yaml' % item 239 240 gfile = 'test.yaml' 240 241 … … 260 261 261 262 # proxyX sorting based on X number 263 os.chdir(NODE_DIR) 262 264 proxies = sorted(glob.glob("proxy*"), 263 265 key=lambda name: int(''.join([c for c in name if c in string.digits])), … … 273 275 def generate_wleiden_yaml(datadump): 274 276 """ 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" 276 279 output += "#\n" 277 280 iface_keys = [elem for elem in datadump.keys() if elem.startswith('iface_')] … … 322 325 323 326 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 328 def 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 357 if not os.environ.has_key('PATH_INFO'): 358 os.environ['PATH_INFO'] = "/".join(sys.argv[1:]) 359 os.environ['SCRIPT_NAME'] = __file__ 360 361 process_cgi_request()
Note:
See TracChangeset
for help on using the changeset viewer.