""" Proof of concept to access results """ import cherrypy, os class TestingRegions: """ Default request handler class. """ RootDir = os.path.join('/var/www/html/csep/data/us/usc') def index(self, **args): # CherryPy will call this method for the root URI ("/") and send # its return value to the client. Because this is tutorial # lesson number 01, we'll just send something really simple. if len(args) and 'all' not in args.values(): for key, value in args.iteritems(): #return "%s = %s" %(key, value) groups = os.listdir(os.path.join(TestingRegions.RootDir, value)) return "%s contains groups: %s" %(value, groups) else: all_dirs = os.listdir(TestingRegions.RootDir) return "Available regions: %s" %all_dirs # if region_id == 'all': # return all_regions # # elif region_id in all_regions: # # List region forecasts groups # groups = os.listdir(os.path.join(TestingRegions.RootDir, # region_id)) # return "%s contains groups: %s" %(region_id, # groups) # Expose the index method through the web. CherryPy will never # publish methods that don't have the exposed attribute set to True. index.exposed = True # Testing locally: tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf') if __name__ == '__main__': # CherryPy always starts with app.root when trying to map request URIs # to objects, so we need to mount a request handler root. A request # to '/' will be mapped to HelloWorld().index(). cherrypy.quickstart(TestingRegions()) #, config=tutconf) else: # This branch is for the test suite; you can ignore it. cherrypy.tree.mount(TestingRegions(), config=tutconf)