from monitor import config import turbogears as tg import urllib def plc_myops_uri(): return "https://" + config.MONITOR_HOSTNAME def plc_mail_uri(ticketid): return config.RT_WEB_SERVER + "/Ticket/Display.html?id=" + str(ticketid) def plc_node_uri(hostname): return "https://" + config.PLC_WWW_HOSTNAME + "/db/nodes/index.php?pattern=" + str(hostname) def plc_node_uri_id(node_id): return "https://" + config.PLC_WWW_HOSTNAME + "/db/nodes/index.php?id=" + str(node_id) def plc_site_uri(loginbase): return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/index.php?pattern=" + str(loginbase) def plc_site_uri_id(site_id): return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/index.php?id=" + str(site_id) def plc_pcu_uri_id(pcu_id): return "https://" + config.PLC_WWW_HOSTNAME + "/db/sites/pcu.php?id=" + str(pcu_id) def query_to_path(**kwargs): args = [] tgpath = "" tgparams = kwargs if tgparams: for key, value in tgparams.iteritems(): if value is None: continue if isinstance(value, (list, tuple)): pairs = [(key, v) for v in value] else: pairs = [(key, value)] for k, v in pairs: if v is None: continue if isinstance(v, unicode): v = v.encode('utf8') args.append((k, str(v))) if args: query_string = urllib.urlencode(args, True) if '?' in tgpath: tgpath += '&' + query_string else: tgpath += '?' + query_string return tgpath def link(base, **kwargs): if config.embedded: str = "?query=" + base + query_to_path(**kwargs) else: str = tg.url(base, **kwargs) #print "CREATED %s" % str return str