7a14294a4cf3e478e7ed6f353af8c482ee6b8934 braney Wed Jan 13 11:36:28 2021 -0800 search only hg/lib for AS files to build the tableDescriptions table. diff --git src/test/buildTableDescriptions.pl src/test/buildTableDescriptions.pl index 3da3d2f..b9b00ad 100755 --- src/test/buildTableDescriptions.pl +++ src/test/buildTableDescriptions.pl @@ -13,30 +13,31 @@ use HgConf; use Getopt::Long; use DBI; use Carp; use strict; # # Default behaviors, changeable by command line args: # my $kentSrc = "/cluster/home/galt/kentclean/src"; # currently does not get checked-in to git: my $gbdDPath = "/cluster/home/galt/kentclean/src/hg/htdocs/goldenPath/gbdDescriptions.html"; my $noLoad = 0; my $verbose = 0; +my $subDir = ""; # Hard-coded behaviors: my $debug = 0; # These are ignored to avoid errors about duplicate table/object definitions. my %autoSqlIgnore = ( "hg/autoSql/tests/input/polyTest.as" => "", "hg/autoSql/tests/input/newTest.as" => "", "hg/autoSql/tests/input/doc.as" => "", "hg/autoSql/tests/input/doc2.as" => "", "hg/autoSql/doc.as" => "", "hg/autoSql/doc2.as" => "", "hg/instinct/instinctMember/members.as" => "", "hg/instinct/bioIntegrator/bioIntDb.as" => "", "hg/lib/bed.as" => "", "hg/lib/ggDbRep.as" => "", "hg/lib/genotype.as" => "", @@ -65,30 +66,31 @@ my $basename = $0; $basename =~ s@.*/@@; # # usage: Print help message and exit, happy or unhappy. # sub usage { print STDERR "Usage: $basename [-kentSrc dir] [-gbdDPath f] [-noLoad] [-help] -kentSrc dir: Use dir as the kent/src checkout. Default: $kentSrc. -gbdDPath f: Use f as the gbdDescriptions.html. Default: $gbdDPath. -db db: Work only on db, not on all active dbs. -hgConf file: Use file instead of ~/.hg.conf. -noLoad: Don't load the database, just create .sql files. + -subDir Grab AS files from this sub directory of kentSrc rather than kentSrc -help: Print this message. "; exit(@_); } # end usage # # getActiveDbs: connect to central db, get list of active dbs # sub getActiveDbs { my $hgConf = shift; confess "Too many arguments" if (defined shift); my $centdb = $hgConf->lookup('central.db'); my $host = $hgConf->lookup('central.host'); my $username = $hgConf->lookup('central.user'); @@ -152,33 +154,34 @@ warn "Case-insensitive duplicate for $db.$t... dropping."; } else { $tableFields{$t} = $fields; $tableNamesInsens{$tableInsens} = 1; } } $dbh->disconnect(); return %tableFields; } # # slurpAutoSql: find all .as files under rootDir, grab contents. # sub slurpAutoSql { my $rootDir = shift; + my $subDir = shift; confess "Too few arguments" if (! defined $rootDir); confess "Too many arguments" if (defined shift); - open(P, "find $rootDir -name '*.as' -print |") || die "Can't open pipe"; + open(P, "find $rootDir/$subDir -name '*.as' -print |") || die "Can't open pipe"; my %tableAS = (); my %objectAS = (); my $gotLeftParen = 0; while (

) { chop; my $filename = $_; my $filetail = $filename; $filetail =~ s/^$kentSrc\///; next if (defined $autoSqlIgnore{$filetail}); open(F, "$filename") || die "Can't open $filename"; my $as = ""; my $table = ""; my $object = ""; my $fields = ""; while () { $as .= $_; @@ -333,61 +336,64 @@ } ########################################################################### # # Parse & process command line args # # GetOptions will put command line args here: use vars qw/ $opt_kentSrc $opt_gbdDPath $opt_noLoad $opt_db $opt_hgConf $opt_help + $opt_subDir $opt_verbose /; my $ok = GetOptions("kentSrc=s", "gbdDPath=s", "noLoad", "db=s", "hgConf=s", "help", + "subDir=s", "verbose"); &usage(1) if (! $ok); &usage(0) if ($opt_help); $kentSrc = $opt_kentSrc if ($opt_kentSrc); $gbdDPath = $opt_gbdDPath if ($opt_gbdDPath); $noLoad = 1 if (defined $opt_noLoad); $verbose = $opt_verbose if (defined $opt_verbose); $verbose = 1 if ($debug); +$subDir = $opt_subDir if ($opt_subDir); # If -hgConf is given, set HGDB_CONF environment variable so our call to # hgsql uses the correct file. if ($opt_hgConf) { if (! -e $opt_hgConf) { die "Error: -hgConf file \"$opt_hgConf\" does not exist.\n"; } $ENV{HGDB_CONF} = $opt_hgConf; } ############################################################################ # MAIN -my %tableAutoSql = slurpAutoSql($kentSrc); +my %tableAutoSql = slurpAutoSql($kentSrc, $subDir); my %fieldsAutoSql = indexAutoSqlByFields(\%tableAutoSql); my %tableAnchors = parseGbdDescriptions($gbdDPath); my $hgConf = HgConf->new($opt_hgConf); my @auxDbs = ('hgFixed', 'proteome'); my @dbs = (defined $opt_db) ? split(',', $opt_db) : (&getActiveDbs($hgConf), @auxDbs); foreach my $db (@dbs) { my $sqlFile = "$db.tableDescriptions.sql"; open(SQL, ">$sqlFile") || die "Can't open $sqlFile for writing"; print SQL "use $db;\n"; print SQL "drop table if exists tableDescriptions;"; open(F, "$kentSrc/hg/lib/tableDescriptions.sql") || die "Can't open $kentSrc/hg/lib/tableDescriptions.sql"; while () { print SQL; @@ -430,30 +436,32 @@ } my $as = $tableAutoSql{$table}; if (defined $as) { if ($tableFields{$table} ne $as->{fields}) { print "$db.$table FIELD MISMATCH:\n"; print "$db.$table table fields: $tableFields{$table}\n"; print "$db.$table autoSql fields: $as->{fields} [$as->{tableName}]\n"; } } else { print "$db.$table: No AutoSql.\n"; } my $anchor = $tableAnchors{$table} || ""; #*** should suggest addition to gbdD of table&.as if not already in there; #*** should complain about gbdD tables not in any active db. my $asd = (defined $as) ? $as->{autoSql} : ""; + # my $asFileName = (defined $as) ? $as->{filename} : "noAs"; $asd =~ s/'/\\'/g; + # print "fileName $asFileName $table\n"; print SQL "INSERT INTO tableDescriptions (tableName, autoSqlDef, gbdAnchor)" . " values ('$table', '$asd', '$anchor');\n"; } # Thanks Jorge for finding that this fixes a problem with myisamchk complaining # that the file was not closed properly: print SQL "FLUSH TABLES tableDescriptions;\n"; close(SQL); if (! $noLoad) { (! system("/cluster/bin/x86_64/hgsql $db < $sqlFile")) || die "hgsql error for $sqlFile"; print "Loaded $db.tableDescriptions.\n"; unlink($sqlFile); } }