304a53cda44a5731304b57ef46d4b6d228649f97 angie Tue Sep 25 11:56:02 2012 -0700 hgTables schema page was using hub (sub)trackDb's without ->html;refactored html-fetching code out of hubConnectAddHubForTrackAndFindTdb and into new hubConnectAddDescription. Also fixed the code to work for subtracks (instead of assigning tdb->html to parents, if tdb->html is empty, recurse up parents until we find a non-empty ->html and assign that to tdb). diff --git src/hg/lib/hubConnect.c src/hg/lib/hubConnect.c index 1ecf76b..ab4bd1c 100644 --- src/hg/lib/hubConnect.c +++ src/hg/lib/hubConnect.c @@ -286,67 +286,97 @@ { /* save away the next pointer becuase we may detach this node and * add it to its supertrack parent */ next = tdb->next; if (tdb->parent != NULL && sameString(trackName, tdb->parent->track)) { /* found a supertrack with the right name, add this child */ p = tdb->parent; slAddHead(&p->subtracks, tdb); } } return p; } +static void addOneDescription(char *trackDbFile, struct trackDb *tdb) +/* Fetch tdb->track's html description and store in tdb->html. */ +{ +char *simpleName = hubConnectSkipHubPrefix(tdb->track); +char *url = trackHubRelativeUrl(trackDbFile, simpleName); +char buffer[10*1024]; +safef(buffer, sizeof buffer, "%s.html", url); +tdb->html = netReadTextFileIfExists(buffer); +freez(&url); +} + +static void addDescription(char *trackDbFile, struct trackDb *tdb) +/* Fetch tdb->track's html description (or nearest ancestor's non-empty description) + * and store in tdb->html. */ +{ +addOneDescription(trackDbFile, tdb); +if (isEmpty(tdb->html)) + { + struct trackDb *parent; + for (parent = tdb->parent; isEmpty(tdb->html) && parent != NULL; parent = parent->parent) + { + addOneDescription(trackDbFile, parent); + if (isNotEmpty(parent->html)) + tdb->html = cloneString(parent->html); + } + } +} + +void hubConnectAddDescription(char *database, struct trackDb *tdb) +/* Fetch tdb->track's html description (or nearest ancestor's non-empty description) + * and store in tdb->html. */ +{ +unsigned hubId = hubIdFromTrackName(tdb->track); +struct trackHub *hub = trackHubFromId(hubId); +struct trackHubGenome *hubGenome = trackHubFindGenome(hub, database); +addDescription(hubGenome->trackDbFile, tdb); +} + 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. */ { unsigned 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) // superTracks aren't in the hash... look in tdbList tdb = findSuperTrack(tdbList, trackName); if (tdb == NULL) errAbort("Can't find track %s in %s", trackName, hub->url); /* Add html for track and parents. */ /* Note: this does NOT add the HTML for supertrack kids */ struct trackDb *parent; for (parent = tdb; parent != NULL; parent = parent->parent) - { - char *simpleName = hubConnectSkipHubPrefix(tdb->track); - char *url = trackHubRelativeUrl(hubGenome->trackDbFile, simpleName); - char buffer[10*1024]; - safef(buffer, sizeof buffer, "%s.html", url); - - parent->html = netReadTextFileIfExists(buffer); - freez(&url); - } + addDescription(hubGenome->trackDbFile, parent); trackHubClose(&hub); return tdb; } static char *getDbList(struct trackHub *tHub, int *pCount) /* calculate dbList for hubStatus table from trackHub */ { struct hashEl *hel; struct dyString *dy = newDyString(1024); struct hashCookie cookie = hashFirst(tHub->genomeHash); int dbCount = 0; while ((hel = hashNext(&cookie)) != NULL) { dbCount++;