12c80e276f91d0920d4c39e76870745a69e19b4d braney Mon Jan 9 16:47:40 2023 -0800 add support for curated hubs to hubApi diff --git src/hg/lib/hubConnect.c src/hg/lib/hubConnect.c index c7383fa..b3d5891 100644 --- src/hg/lib/hubConnect.c +++ src/hg/lib/hubConnect.c @@ -973,46 +973,74 @@ genome->name = cloneString(buffer); // if our new database is an undecorated db, decorate it if (*newDatabase && sameString(*newDatabase, name)) *newDatabase = cloneString(buffer); } } } } hDisconnectCentral(&conn); return added; } +static char *getCuratedHubPrefix() +/* figure out what sandbox we're in. */ +{ +char *curatedHubPrefix = cfgOption("curatedHubPrefix"); +if (isEmpty(curatedHubPrefix)) + curatedHubPrefix = "public"; -boolean hubConnectIsCurated(char *db) -/* Look in the dbDb table to see if this hub is curated. */ +return curatedHubPrefix; +} + + +boolean hubConnectGetCuratedUrl(char *db, char **hubUrl) +/* Check to see if this db is a curated hub and if so return its hubUrl */ { struct sqlConnection *conn = hConnectCentral(); char query[4096]; sqlSafef(query, sizeof query, "SELECT nibPath from %s where name = '%s' AND nibPath like '%s%%'", dbDbTable(), db, hubCuratedPrefix); char *dir = sqlQuickString(conn, query); boolean ret = !isEmpty(dir); hDisconnectCentral(&conn); +if (hubUrl != NULL) // if user passed in hubUrl, calculate what it should be + { + *hubUrl = NULL; + if (!isEmpty(dir)) // this is a curated hub + { + char *path = dir + sizeof(hubCuratedPrefix) - 1; + char url[4096]; + safef(url, sizeof url, "%s/%s/hub.txt", path, getCuratedHubPrefix()); + *hubUrl = cloneString(url); + } + } + return ret; } +boolean hubConnectIsCurated(char *db) +/* Look in the dbDb table to see if this hub is curated. */ +{ +return hubConnectGetCuratedUrl(db, NULL); +} + char *dbOveride; // communicate with the web front end if we load a hub to support db cgivar. */ static int lookForCuratedHubs(struct cart *cart, char *db, char *curatedHubPrefix) /* Check to see if db is a curated hub which will require the hub to be attached. * The variable curatedHubPrefix has the release to use (alpha, beta, public, or a user name ) */ { struct sqlConnection *conn = hConnectCentral(); char query[4096]; sqlSafef(query, sizeof query, "SELECT nibPath from %s where name = '%s' AND nibPath like '%s%%'", dbDbTable(), db, hubCuratedPrefix); char *dir = cloneString(sqlQuickString(conn, query)); hDisconnectCentral(&conn); if (!isEmpty(dir)) @@ -1037,33 +1065,31 @@ errAbort("Hub error: url %s: error %s.", url, status->errorMessage); else errAbort("Cannot open hub %s.", url); } } return 0; } char *hubConnectLoadHubs(struct cart *cart) /* load the track data hubs. Set a static global to remember them */ { int newCuratedHubId = 0; char *dbSpec = cartOptionalString(cart, "db"); -char *curatedHubPrefix = cfgOption("curatedHubPrefix"); -if (isEmpty(curatedHubPrefix)) - curatedHubPrefix = "public"; +char *curatedHubPrefix = getCuratedHubPrefix(); if (dbSpec != NULL) newCuratedHubId = lookForCuratedHubs(cart, trackHubSkipHubName(dbSpec), curatedHubPrefix); char *newDatabase = checkForNew( cart); newDatabase = asmAliasFind(newDatabase); if (newCuratedHubId) newDatabase = dbOveride; cartSetString(cart, hgHubConnectRemakeTrackHub, "on"); struct hubConnectStatus *hubList = hubConnectStatusListFromCart(cart); char *genarkPrefix = cfgOption("genarkHubPrefix"); if (genarkPrefix && lookForLonelyHubs(cart, hubList, &newDatabase, genarkPrefix)) hubList = hubConnectStatusListFromCart(cart); globalHubList = hubList;