IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 19, 2010, 3:59:49 PM (16 years ago)
Author:
rhenders
Message:

Made script smarter: now can find relevant .sql file for given table

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/scripts/pspsSchema2xml.pl

    r27363 r27364  
    4242$writer->startTag('tableDescriptions', "type" => "$type");
    4343
    44 if ($type eq "IN") {createInit($schemaPath);}
    45 elsif ($type eq "DT") {createDetections($schemaPath);}
    46 elsif ($type eq "OB") {createDiffs($schemaPath);}
    47 elsif ($type eq "ST") {createStacks($schemaPath);}
     44if ($type eq "IN") {createInit();}
     45elsif ($type eq "DT") {createDetections();}
     46elsif ($type eq "OB") {createDiffs();}
     47elsif ($type eq "ST") {createStacks();}
    4848
    4949# finish up XML
     
    5454######################################################################################3
    5555
     56# finds the schema file containing this table description
     57sub findSchemaFile {
     58    my ($tableName) = @_;
     59
     60    opendir(DIR, $schemaPath) or print "Cannot open '$schemaPath'\n" and return "";
     61    my @files= readdir(DIR);
     62    closedir(DIR);
     63
     64    foreach my $f (@files) {
     65
     66        if ($f =~ m/.*\.sql$/) {
     67            #print "....$f\n";
     68
     69            open FILE, "<$schemaPath/$f" or next;
     70
     71            while (<FILE>) {
     72                if ($_ =~ m/.*CREATE TABLE.*$tableName/) {
     73
     74                    close (FILE);
     75                    return "$schemaPath/$f";
     76                }
     77            }
     78
     79            close (FILE);
     80
     81        }
     82    }
     83
     84    print "Could not find table '$tableName'\n";
     85    return "";
     86}
    5687
    5788# creates detections tables
    5889sub createInit {
    59     my ($schemaPath) = @_;
    60 
    61     parseTable("$schemaPath/PanSTARRS.Tables.Common.sql", "dbo.Filter");
    62     parseTable("$schemaPath/PanSTARRS.Tables.Common.sql", "dbo.FitModel");
    63     parseTable("$schemaPath/PanSTARRS.Tables.Common.sql", "dbo.PhotozRecipe");
    64     parseTable("$schemaPath/PanSTARRS.Tables.Common.sql", "dbo.Survey");
    65     parseTable("$schemaPath/PanSTARRS.Tables.Common.sql", "dbo.CameraConfig");
    66     parseTable("$schemaPath/PanSTARRS.Tables.Common.sql", "dbo.PhotoCal");
    67     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.SkyCell");
    68     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.ProjectionCell");
    69     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.Region");
    70     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.StackType");
     90
     91    parseTable("Filter");
     92    parseTable("FitModel");
     93    parseTable("PhotozRecipe");
     94    parseTable("Survey");
     95    parseTable("CameraConfig");
     96    parseTable("PhotoCal");
     97    parseTable("SkyCell");
     98    parseTable("ProjectionCell");
     99    parseTable("Region");
     100    parseTable("StackType");
    71101}
    72102
    73103# creates init batch tables
    74104sub createDetections {
    75     my ($schemaPath) = @_;
    76 
    77     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.FrameMeta");
    78     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.ImageMeta");
    79     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.Detection");
    80     parseTable("$schemaPath/PanSTARRS.Tables.LoadMerge.sql", "dbo.SkinnyObject");
    81     parseTable("$schemaPath/PanSTARRS.Tables.Common.sql", "dbo.ObjectCalColor");
     105
     106    parseTable("FrameMeta");
     107    parseTable("ImageMeta");
     108    parseTable("Detection");
     109    parseTable("SkinnyObject");
     110    parseTable("ObjectCalColor");
    82111}
    83112
    84113# creates diff batch tables
    85114sub createDiffs {
    86     my ($schemaPath) = @_;
    87 
    88     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.StackMeta");
    89     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.StackToImage");
    90     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.StackLowSigDelta");
    91     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.StackHighSigDelta");
     115
     116    parseTable("StackMeta");
     117    parseTable("StackToImage");
     118    parseTable("StackLowSigDelta");
     119    parseTable("StackHighSigDelta");
    92120}
    93121
    94122# creates stack batch tables
    95123sub createStacks {
    96     my ($schemaPath) = @_;
    97 
    98     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.StackMeta");
    99     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.StackDetection");
    100     parseTable("$schemaPath/PanSTARRS.Tables.LoadMerge.sql", "dbo.SkinnyObject");
    101     parseTable("$schemaPath/PanSTARRS.Tables.Slice.sql", "dbo.StackOrphan");
    102     parseTable("$schemaPath/PanSTARRS.Tables.Common.sql", "dbo.ObjectCalColor");
     124
     125    parseTable("StackMeta");
     126    parseTable("StackDetection");
     127    parseTable("SkinnyObject");
     128    parseTable("StackOrphan");
     129    parseTable("ObjectCalColor");
    103130}
    104131
     
    106133# parses out a table
    107134sub parseTable {
    108     my ($schemaPath, $tableName, $newName) = @_;
     135    my ($tableName, $newName) = @_;
     136
     137    my $path =  findSchemaFile($tableName);
     138
     139    if ($path eq "") {return;}
    109140
    110141    # sort out table name, either same as in schema or as defined
    111142    my $tableNameOut;
    112143    if ($newName) { $tableNameOut = $newName;}
    113     elsif($tableName =~ m/dbo\.(.*)/) {$tableNameOut = $1}
     144    else {$tableNameOut = $tableName}
    114145
    115146    $writer->startTag('table', "name" => $tableNameOut);
    116    
    117     open (SCHEMA, $schemaPath);
     147
     148    open (SCHEMA, $path);
    118149
    119150    my $reading = 0;
     
    124155        chomp;
    125156
    126         if ($_ =~ m/.*CREATE TABLE\s+([a-zA-Z0-9.]+)\s*\(/i) {
     157        if ($_ =~ m/.*CREATE TABLE\s+dbo\.([a-zA-Z0-9.]+)\s*\(/i) {
    127158
    128159            $table = $1;
     
    130161            if ($table eq $tableName) {
    131162
    132                 my $tableNameOut;
    133                 if ($tableName =~ m/dbo\.(.*)/) {$tableNameOut = $1}
    134163                $reading = 1;
    135164                $found = 1;
Note: See TracChangeset for help on using the changeset viewer.