IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10531


Ignore:
Timestamp:
Dec 7, 2006, 12:47:12 PM (20 years ago)
Author:
Paul Price
Message:

Adding function to go from absolute to relative path.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-Config/lib/PS/IPP/Config.pm

    r10467 r10531  
    11# Copyright (c) 2006  Paul Price, Joshua Hoblitt
    22#
    3 # $Id: Config.pm,v 1.11 2006-12-05 03:15:03 price Exp $
     3# $Id: Config.pm,v 1.12 2006-12-07 22:47:12 price Exp $
    44
    55package PS::IPP::Config;
     
    9797    my $name = shift;           # datapath name
    9898
    99     my $path_list = _mdLookupMD($self->{_ipprc}, 'DATAPATH'); # List of cameras
    100     my $pathname = _mdLookupStr($path_list, $name); # Filename of camera configuration
     99    my $path_list = _mdLookupMD($self->{_ipprc}, 'DATAPATH'); # List of paths
     100    my $pathname = _mdLookupStr($path_list, $name); # Path of interest
    101101    croak "Unable to find camera configuration file $pathname\n" if not defined $pathname;
    102102
     
    104104}
    105105
    106 sub convert_filename
     106sub convert_filename_absolute
    107107{
    108108    my $self = shift;           # Configuration object
     
    123123    }
    124124
    125     # if we have a relative path in the end, prepend WORKDIR
    126     unless ($name =~ m|^/|) {
    127         my $workdir = $self->workdir();
    128         if (defined $workdir) {
    129             $name = File::Spec->rel2abs( $name, $workdir );
    130         }
     125    $name =~ s|/{2,}|/|g;               # Remove double slashes
     126
     127    return $name;
     128}
     129
     130sub convert_filename_relative
     131{
     132    my $self = shift;           # Configuration object
     133    my $name = shift;           # raw name
     134
     135    $name =~ s|/{2,}|/|g;               # Remove double slashes
     136
     137    my $path_list = _mdLookupMD($self->{_ipprc}, 'DATAPATH'); # List of paths
     138    my $best_path;
     139    my $best_name;
     140    my $best_score = length $name;
     141    foreach my $path_item (@$path_list) {
     142        my $path_name = $path_item->{name}; # Name of the path
     143        my $path = $path_item->{value}; # The path
     144        if ($path !~ m|/$|) {
     145            $path .= '/';
     146        }
     147        my ($rest) = $name =~ m|^$path(.*)|; # Rest of the string
     148        next if not defined $rest;
     149        my $score = length $rest;
     150        if ($score < $best_score) {
     151            $best_path = $path;
     152            $best_score = $score;
     153            $best_name = $path_name;
     154        }
     155    }
     156    if ($best_score < length $name) {
     157        $name =~ s|^$best_path|path://$best_name/|;
     158    } else {
     159        # Worst case scenario: can't find anything, so put in the absolute path
     160        $name = 'file://' . $name;
    131161    }
    132162
Note: See TracChangeset for help on using the changeset viewer.