Commit 73391fe9 authored by Leigh Stoller's avatar Leigh Stoller

Add some object methods specific to dealing with datasets.

parent 6f7dfcfd
#!/usr/bin/perl -wT
#
# Copyright (c) 2009-2018 University of Utah and the Flux Group.
# Copyright (c) 2009-2019 University of Utah and the Flux Group.
#
# {{{GENIPUBLIC-LICENSE
#
......@@ -341,6 +341,15 @@ sub GenerateImage($$$$)
}
return Generate($authority, "image", $pid . "//" . $os);
}
sub GenerateDataset($$$$$)
{
my ($domain,$type,$pid,$name,$vers) = @_;
my $authority = "${domain}:${pid}";
if (defined($vers)) {
$name .= "//" . $vers;
}
return Generate($authority, $type, $name);
}
#
# OO implementation, tired of typing same stuff all the time
......@@ -372,6 +381,7 @@ sub new($$)
$self->{'project'} = $project;
$self->{'group'} = $group;
$self->{'IMAGEPARSE'} = undef;
$self->{'DATASETPARSE'} = undef;
bless($self, $class);
return $self;
......@@ -421,7 +431,44 @@ sub imagefield($$)
sub osname($) { return $_[0]->imagefield("osname"); }
sub ospid($) { return $_[0]->imagefield("ospid"); }
sub osvers($) { return $_[0]->imagefield("osvers"); }
sub IsImage($) { return $_[0]->type() =~ /^image$/i ? 1 : 0; }
sub IsImage($)
{
my ($self) = @_;
# Make sure we have parsed it.
return 0
if (!defined($self->ospid()));
return $_[0]->type() =~ /^image$/i ? 1 : 0; }
#
# Datasets do not put the project in the id like images.
#
sub datasetfield($$)
{
my ($self, $field) = @_;
if (!defined($self->{'DATASETPARSE'})) {
my ($authority,$type,$id) = Parse($self->urn());
return undef
if ($type !~ /^(lt|st|im)dataset$/);
my ($name,undef,$vers) = ($id =~ m{([^/]+)(//(\d+))?});
return undef if (!defined($name));
$self->{'DATASETPARSE'} = {
"name" => $name,
"vers" => $vers,
};
}
return $self->{'DATASETPARSE'}->{$field};
}
sub dsetname($) { return $_[0]->datasetfield("name"); }
sub dsetpid($) { return $_[0]->project(); }
sub dsetgid($) { return $_[0]->group(); }
sub dsetvers($) { return $_[0]->datasetfield("vers"); }
sub IsDataset($){ return $_[0]->type() =~ /^(lt|st|im)?dataset$/i ? 1 : 0; }
sub IsIMDataset($){ return $_[0]->type() =~ /^(im)?dataset$/i ? 1 : 0; }
#
# Stringify for text context.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment