IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 2, 2009, 12:03:23 PM (17 years ago)
Author:
eugene
Message:

merge from head

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715/DataStoreServer/scripts/dsprodtool

    r24196 r25744  
    1212use PS::IPP::Metadata::Config;
    1313use File::Copy;
     14
     15use Term::ReadKey;
    1416
    1517use PS::IPP::Config qw($PS_EXIT_SUCCESS
     
    3638my $dsroot;
    3739my $dbname;
     40my $dbpass;
    3841
    3942my $add;
     
    7881} else {
    7982    $product = $del;
     83    if (! -t STDIN) {
     84        die "cannot delete product from script\n";
     85    }
     86    print "*** Delete the Data Store Product $product? ***\n";
     87    print "*** to delete $product answer YES, and give password ***\n";
     88    print "*** WARNING this action is permanant *** \n";
     89    print "Delete? (YES/[n]): ";
     90
     91    my $line = ReadLine(0);
     92    chomp $line;
     93    exit 1 if !$line or ($line ne "YES");
     94
     95    print "password: ";
     96    ReadMode('noecho');
     97    $line = ReadLine(0);
     98    ReadMode('normal');
     99    print "\n";
     100    chomp $line;
     101    $dbpass = $line;
    80102}
    81103
     
    93115}
    94116
    95 my $root_index_script = "$dsroot/index.txt";
     117my $root_index_script = "$dsroot/index.txt.template";
    96118if (!stat($root_index_script)) {
    97119    $err .= "Data Store not found at '$dsroot'.\n"
     
    106128    unless defined $dbname;
    107129my $dbuser   = metadataLookupStr($siteConfig, 'DS_DBUSER');
    108 my $dbpass   = metadataLookupStr($siteConfig, 'DS_DBPASSWORD');
     130$dbpass   = metadataLookupStr($siteConfig, 'DS_DBPASSWORD') if !$dbpass;
    109131exit ($PS_EXIT_CONFIG_ERROR) unless defined $dbserver and $dbname and $dbuser and $dbpass;
    110132
    111133my $dsn = "DBI:mysql:host=$dbserver;database=$dbname";
    112 
    113 my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n";
    114 
    115134
    116135my $product_dir = "$dsroot/$product";
     
    118137
    119138if ($del) {
     139    my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n";
    120140    #
    121141    # delete product
     
    129149    }
    130150    my $prod_id = $prod_row->{prod_id};
    131 
    132     # if requested, remove the product directory
    133     if ($remove) {
    134         if (system "rm -r $product_dir") {
    135             die("failed to remove $product_dir");
    136         }
    137     } else  {
    138         # otherwise just zap the index script
    139         unlink("$index_script_name");
    140     }
    141151
    142152
     
    152162    $dbh->do("DELETE from dsProduct where prod_id = $prod_id");
    153163
     164    print "Product $product deleted.\n";
     165
     166    # if requested, remove the product directory
     167    if ($remove) {
     168        print "Removing files from $product.\n";
     169        if (system "rm -r $product_dir") {
     170            die("failed to remove $product_dir");
     171        }
     172    } else  {
     173        # otherwise just zap the index script
     174        unlink("$index_script_name");
     175    }
     176
    154177    exit 0;
    155178
     
    158181    # add a new product
    159182    #
     183    my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n";
     184
    160185    my $stmt = $dbh->prepare("SELECT prod_id FROM dsProduct WHERE prod_name = \'$product\'");
    161186    $stmt->execute();
     
    167192
    168193    # set up the product directory
     194    # if there is an old index file delete it
     195    if (-e $index_script_name ) {
     196        if (!unlink($index_script_name)) {
     197            die("failed trying to remove old $index_script_name");
     198        }
     199    }
    169200    if (! -e $product_dir) {
    170201        $we_created_dir = 1;
     
    172203            die("failed trying to make product directory $product_dir");
    173204        }
    174     }
    175     if (-e $index_script_name ) {
    176         if (!unlink($index_script_name)) {
    177             die("failed trying to remove old $index_script_name");
    178         }
    179     }
     205    } else {
     206        # directory alrady exists make sure that it's empty
     207        my @dirlist = glob("$product_dir/*");
     208        die ("existing product directory $product_dir is not empty") if scalar @dirlist;
     209    }
     210
    180211    if (!copy($root_index_script, $index_script_name)) {
    181212        print STDERR "failed trying to copy($root_index_script, $index_script_name)";
Note: See TracChangeset for help on using the changeset viewer.