1f1ad77303a89026caa686b37d4199a62c94bf43
kent
  Tue Feb 1 12:38:07 2011 -0800
Making it so that track html description is fetched for hgc and hgTrackUi.  To do this had to get a way to fetch a text file from a URL without putting up any warning messages if it was not there, which ended up requiring a new warning handler.
diff --git src/hg/lib/hubConnect.c src/hg/lib/hubConnect.c
index 8cc8ebf..698f643 100644
--- src/hg/lib/hubConnect.c
+++ src/hg/lib/hubConnect.c
@@ -1,28 +1,29 @@
 /* hubConnect - stuff to manage connections to track hubs.  Most of this is mediated through
  * the hubConnect table in the hgCentral database.  Here there are routines to translate between
  * hub symbolic names and hub URLs,  to see if a hub is up or down or sideways (up but badly
  * formatted) etc.  Note that there is no C structure corresponding to a row in the hubConnect 
  * table by design.  We just want field-by-field access to this. */
 
 #include "common.h"
 #include "linefile.h"
 #include "hash.h"
 #include "dystring.h"
 #include "sqlNum.h"
 #include "jksql.h"
 #include "hdb.h"
+#include "net.h"
 #include "trackHub.h"
 #include "hubConnect.h"
 #include "hui.h"
 
 
 boolean isHubTrack(char *trackName)
 /* Return TRUE if it's a hub track. */
 {
 return startsWith(hubTrackPrefix, trackName);
 }
 
 boolean hubConnectTableExists()
 /* Return TRUE if the hubConnect table exists. */
 {
 struct sqlConnection *conn = hConnectCentral();
@@ -143,46 +144,79 @@
 slFreeList(&nameList);
 hDisconnectCentral(&conn);
 slReverse(&hubList);
 return hubList;
 }
 
 int hubIdFromTrackName(char *trackName)
 /* Given something like "hub_123_myWig" return 123 */
 {
 assert(startsWith("hub_", trackName));
 trackName += 4;
 assert(isdigit(trackName[0]));
 return atoi(trackName);
 }
 
-struct trackDb *hubConnectAddHubForTrackAndFindTdb(char *database, 
-	char *trackName, struct trackDb **pTdbList, struct hash *trackHash)
-/* Go find hub for trackName (which will begin with hub_), and load the tracks
- * for it, appending to end of list and adding to trackHash.  Return the
- * trackDb associated with trackName.  */
+char *hubConnectSkipHubPrefix(char *trackName)
+/* Given something like "hub_123_myWig" return myWig.  Don't free this, it's not allocated */
+{
+assert(startsWith("hub_", trackName));
+trackName += 4;
+assert(isdigit(trackName[0]));
+trackName = strchr(trackName, '_');
+assert(trackName != NULL);
+return trackName + 1;
+}
+
+struct trackHub *trackHubFromId(int hubId)
+/* Given a hub ID number, return corresponding trackHub structure. 
+ * ErrAbort if there's a problem. */
 {
-int hubId = hubIdFromTrackName(trackName);
 struct sqlConnection *conn = hConnectCentral();
-struct hubConnectStatus *hubStatus = hubConnectStatusForId(conn, hubId);
+struct hubConnectStatus *status = hubConnectStatusForId(conn, hubId);
 hDisconnectCentral(&conn);
-if (hubStatus == NULL)
+if (status == NULL)
     errAbort("The hubId %d was not found", hubId);
-if (!isEmpty(hubStatus->errorMessage))
-    errAbort("Hub %s at %s has the error: %s", hubStatus->shortLabel, 
-	    hubStatus->hubUrl, hubStatus->errorMessage);
+if (!isEmpty(status->errorMessage))
+    errAbort("Hub %s at %s has the error: %s", status->shortLabel, 
+	    status->hubUrl, status->errorMessage);
 char hubName[16];
 safef(hubName, sizeof(hubName), "hub_%d", hubId);
-struct trackHub *hub = trackHubOpen(hubStatus->hubUrl, hubName);
+struct trackHub *hub = trackHubOpen(status->hubUrl, hubName);
+hubConnectStatusFree(&status);
+return hub;
+}
+
+struct trackDb *hubConnectAddHubForTrackAndFindTdb(char *database, 
+	char *trackName, struct trackDb **pTdbList, struct hash *trackHash)
+/* Go find hub for trackName (which will begin with hub_), and load the tracks
+ * for it, appending to end of list and adding to trackHash.  Return the
+ * trackDb associated with trackName. This will also fill in the html fields,
+ * but just for that track and it's parents. */ 
+{
+int hubId = hubIdFromTrackName(trackName);
+struct trackHub *hub = trackHubFromId(hubId);
 struct trackHubGenome *hubGenome = trackHubFindGenome(hub, database);
 struct trackDb *tdbList = trackHubTracksForGenome(hub, hubGenome);
 tdbList = trackDbLinkUpGenerations(tdbList);
 tdbList = trackDbPolishAfterLinkup(tdbList, database);
 rAddTrackListToHash(trackHash, tdbList, NULL, FALSE);
 if (pTdbList != NULL)
     *pTdbList = slCat(*pTdbList, tdbList);
 struct trackDb *tdb = hashFindVal(trackHash, trackName);
 if (tdb == NULL)
-    errAbort("Can't find track %s in %s", trackName, hubStatus->hubUrl);
+    errAbort("Can't find track %s in %s", trackName, hub->url);
+
+/* Add html for track and parents. */
+struct trackDb *parent;
+for (parent = tdb; parent != NULL; parent = parent->parent)
+    {
+    char *simpleName = hubConnectSkipHubPrefix(tdb->track);
+    char *url = trackHubRelativeUrl(hubGenome->trackDbFile, simpleName);
+    parent->html = netReadTextFileIfExists(url);
+    freez(&url);
+    }
+trackHubClose(&hub);
+
 return tdb;
 }