def __init__(self): handlers = [(r"^/ajax/([a-z]*)/(.*)", AjaxHandler), (r"^/substance/(.*)", SimpleHtmlHandlerWithId), (r"^/run/(.*)", RunSparkHandler), (r"^/mzimage/([^/]*)\.png", MZImageHandler), (r"^/mzimage/([^/]*)/([^/]*)\.png", MZImageParamHandler), (r"^/jobs/", SimpleHtmlHandler), (r"^/datasets/", SimpleHtmlHandler), (r"^/fullresults/(.*)", SimpleHtmlHandlerWithId), (r"/", IndexHandler)] settings = dict(static_path=path.join(os.path.dirname(__file__), "static"), debug=True) config_db = dict(host="/var/run/postgresql/", db="ims", user="******", password="") tornado.web.Application.__init__(self, handlers, **settings) # Have one global connection to the blog DB across all handlers self.db = tornpsql.Connection(config_db['host'], config_db['db'], config_db['user'], config_db['password'], 5432) self.conf = SparkConf().setMaster("local[2]").setAppName( "IMS Webserver v0.2").set("spark.ui.showConsoleProgress", "false") self.sc = SparkContext(conf=self.conf) self.status = self.sc.statusTracker() self.max_jobid = self.db.get("SELECT max(id) as maxid FROM jobs").maxid self.max_jobid = int(self.max_jobid) if self.max_jobid != None else 0 self.jobs = {}
def run(self): db = tornpsql.Connection(database='tornpsql') pubsub = db.pubsub() pubsub.subscribe(('example', 'other', 'exit', 'unsub', 'unsuball')) for notify in pubsub.listen(): if notify.channel == 'exit': db.close() break elif notify.channel == 'unsub': pubsub.unsubscribe(('example', )) elif notify.channel == 'unsuball': pubsub.unsubscribe() else: db.query( "insert into notices (channel, payload) values (%s, %s);", notify.channel, notify.payload)
def __init__(self): routes = [ (r"/", handlers.MainHandler), (r"/mpg",handlers.MpgHandler), (r"/mpg-view",handlers.MpgViewHandler), (r"/pi",handlers.PiHandler), (r"/login", handlers.LoginHandler), (r"/logout", handlers.LogoutHandler), (r"/signup", handlers.SignupHandler), (r"/.*", handlers.MainHandler), ] # connects to database self.db = tornpsql.Connection() settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), debug=(os.getenv("DEBUG")=='true'), cookie_secret=os.getenv("COOKIE_SECRET") ) tornado.web.Application.__init__(self, routes, **settings)
def __init__(self, debug=False): """Initializes handlers, including the spark handler, sets up database connection.""" handlers = [ (r"/", misc.IndexHandler), (r"/auth", auth.AuthenticateClient), (r"/feedback-rating", feedback.FeedbackRating), (r"/feedback-comment", feedback.FeedbackComment), # (r"/static/(.*)", tornado.web.StaticFileHandler, {"path": path.join(path.dirname(__file__), "static")}), (r"^/results_table/(.*)", results_table.ResultsTableHandler), (r"^/mzimage2/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)", iso_image_gen.AggIsoImgPngHandler), (r"^/mzimage2/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)", iso_image_gen.IsoImgPngHandler), (r"^/spectrum_line_chart_data/([^/]+)/([^/]+)/([^/]+)/([^/]+)", misc.SpectrumLineChartHandler), (r"^/sf_peak_mzs/([^/]+)/([^/]+)/([^/]+)/([^/]+)", misc.SFPeakMZsHandler), (r"^/min_max_int/([^/]+)/([^/]+)/([^/]+)/([^/]+)", misc.MinMaxIntHandler), ] settings = dict(static_path=path.join(path.dirname(__file__), 'static'), template_path=path.join(path.dirname(__file__), 'html'), cookie_secret='59x6wj71r6462o16PSFsouy5QnaviACW', debug=debug, compress_response=True) config_db = config["db"] tornado.web.Application.__init__(self, handlers, **settings) # Have one global connection to the blog DB across all handlers self.db = tornpsql.Connection(config_db['host'], config_db['database'], config_db['user'], config_db['password'], 5432) # hack needed to overcome sending expensive query every time results table is filtered or sorted self.adducts = [ row['adduct'] for row in self.db.query( 'select distinct(target_add) as adduct from target_decoy_add') ]
def test_connection_from_url(self): "can connect from the os.getenv('DATABASE_URL')" db = tornpsql.Connection() self.assertTrue(db.get("select true as connected").connected)
def test_connection_via_url(self): "can test connect with args" db = tornpsql.Connection(os.getenv("ALTERNATE_DATABASE_URL")) self.assertTrue(db.get("select true as connected").connected)
def test_connection_args(self): "test connect with args" db = tornpsql.Connection("127.0.0.1", "tornpsql", os.getenv("postgres", None)) self.assertTrue(db.get("select true as connected").connected)
def setUpClass(self): try: self.db = tornpsql.Connection(database="tornpsql") except: pass
def __init__(self, *a, **k): Inquiry.__init__(self, *a, **k) self.db = tornpsql.Connection( os.getenv("PSQL", "postgres://peak:@localhost:5432/inquiry"))
def setUpClass(self): PubSubThread() self.db = tornpsql.Connection(database="tornpsql")