IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29615


Ignore:
Timestamp:
Oct 29, 2010, 3:33:10 PM (16 years ago)
Author:
watersc1
Message:

tool to convert a nebulous disk filename into an ext_id

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/neb-reverse

    r28118 r29615  
    1010my ($db_host, $db_name, $db_user, $db_pw); # Database details
    1111my @files;                                 # Files of interest
     12my $old = 0;
     13@files = @ARGV;
     14foreach my $file (@files) {
     15    my (@neb_path) = split /\//, $file;
     16    my $neb_key = $neb_path[-1];
     17    # Remove ins_id
     18    $neb_key =~ s/^\d+\.//;
     19    # Convert colons to slashes.
     20    $neb_key =~ s%:%/%g;
     21    print "$neb_key\n";
     22}
    1223
    13 GetOptions(
    14     'dbhost=s' => \$db_host, # Database host name
    15     'dbname=s' => \$db_name, # Database name
    16     'dbuser=s' => \$db_user, # Database user
    17     'dbpass=s' => \$db_pw, # Database p/w
    18     'file=s' => \@files,  # Files of interest
    19     ) or die "Unable to parse arguments.\n";
    20 die "Unknown option: @ARGV\n" if @ARGV;
    21 die "Required options: --dbhost --dbname --dbuser --dbpass --file\n"
    22     unless defined $db_host
    23     and defined $db_name
    24     and defined $db_user
    25     and defined $db_pw
    26     and scalar @files > 0;
    27 
    28 
     24# There's no reason to prod the database to get something that is originally created by messing with the key name.
     25if ($old) {
     26    GetOptions(
     27        'dbhost=s' => \$db_host, # Database host name
     28        'dbname=s' => \$db_name, # Database name
     29        'dbuser=s' => \$db_user, # Database user
     30        'dbpass=s' => \$db_pw, # Database p/w
     31        'file=s' => \@files,  # Files of interest
     32        ) or die "Unable to parse arguments.\n";
     33    die "Unknown option: @ARGV\n" if @ARGV;
     34    die "Required options: --dbhost --dbname --dbuser --dbpass --file\n"
     35        unless defined $db_host
     36        and defined $db_name
     37        and defined $db_user
     38        and defined $db_pw
     39        and scalar @files > 0;
     40   
     41   
    2942# Database connection
    30 my $db = DBI->connect( "DBI:mysql:database=$db_name;host=$db_host;mysql_socket=" . DB_SOCKET(),
    31                        $db_user,
    32                        $db_pw,
    33                        { RaiseError => 1, AutoCommit => 1 }
    34                        ) or die "Unable to connect to database: $DBI::errstr";
    35 
    36 foreach my $file (@files) {
    37     my $sql = "SELECT CONCAT('neb://any/', ext_id) FROM storage_object JOIN instance USING(so_id) WHERE uri = 'file://$file'";
    38     my $results = $db->selectcol_arrayref( $sql ) or die "Unable to execute SQL: $DBI::errstr";
    39     print "$$results[0]\n";
     43    my $db = DBI->connect( "DBI:mysql:database=$db_name;host=$db_host;mysql_socket=" . DB_SOCKET(),
     44                           $db_user,
     45                           $db_pw,
     46                           { RaiseError => 1, AutoCommit => 1 }
     47        ) or die "Unable to connect to database: $DBI::errstr";
     48   
     49    foreach my $file (@files) {
     50        my $sql = "SELECT CONCAT('neb://any/', ext_id) FROM storage_object JOIN instance USING(so_id) WHERE uri = 'file://$file'";
     51        my $results = $db->selectcol_arrayref( $sql ) or die "Unable to execute SQL: $DBI::errstr";
     52        print "$$results[0]\n";
     53    }
    4054}
Note: See TracChangeset for help on using the changeset viewer.