aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaarten Vanraes <alien@mageia.org>2016-08-06 14:41:21 +0200
committerMaarten Vanraes <alien@mageia.org>2016-08-07 17:13:14 +0200
commit94eea704c4dff3b37e0a6852dab06081b403b05c (patch)
treef1a87d2b6d34b58537c5b39684e1b7a872e09758
parent9fd53f54fa7ff9cdf7f8525a46eddbabd80c5b10 (diff)
downloadmanatools-94eea704c4dff3b37e0a6852dab06081b403b05c.tar
manatools-94eea704c4dff3b37e0a6852dab06081b403b05c.tar.gz
manatools-94eea704c4dff3b37e0a6852dab06081b403b05c.tar.bz2
manatools-94eea704c4dff3b37e0a6852dab06081b403b05c.tar.xz
manatools-94eea704c4dff3b37e0a6852dab06081b403b05c.zip
Part: allow to change label depending on purpose
-rw-r--r--lib/ManaTools/Shared/disk_backend/Part.pm5
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm3
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm10
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm1
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin/Loop.pm1
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin/Mount.pm12
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm10
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin/Swap.pm10
-rw-r--r--lib/ManaTools/Shared/disk_backend/PurposeLabelRole.pm90
9 files changed, 142 insertions, 0 deletions
diff --git a/lib/ManaTools/Shared/disk_backend/Part.pm b/lib/ManaTools/Shared/disk_backend/Part.pm
index a2455d0f..ec016cc7 100644
--- a/lib/ManaTools/Shared/disk_backend/Part.pm
+++ b/lib/ManaTools/Shared/disk_backend/Part.pm
@@ -595,6 +595,11 @@ sub diff {
sub label {
my $self = shift;
+ my $proplabel = '';
+ $proplabel = $self->prop('label') if $self->has_prop('label');
+
+ return $proplabel if $proplabel ne '';
+
return $self->type;
}
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm
index 0683f669..ecf6dd03 100644
--- a/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm
+++ b/lib/ManaTools/Shared/disk_backend/Plugin/Btrfs.pm
@@ -196,6 +196,8 @@ use Moose;
extends 'ManaTools::Shared::disk_backend::Part';
+with 'ManaTools::Shared::disk_backend::PurposeLabelRole';
+
use MooseX::ClassAttribute;
class_has '+type' => (
@@ -229,6 +231,7 @@ extends 'ManaTools::Shared::disk_backend::Part';
use MooseX::ClassAttribute;
with 'ManaTools::Shared::disk_backend::Mountable';
+with 'ManaTools::Shared::disk_backend::PurposeLabelRole';
sub _get_mount_source {
my $self = shift;
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm
index 6f58d1d7..75bcd1f9 100644
--- a/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm
+++ b/lib/ManaTools/Shared/disk_backend/Plugin/Disk.pm
@@ -151,6 +151,7 @@ extends 'ManaTools::Shared::disk_backend::Part';
use MooseX::ClassAttribute;
with 'ManaTools::Shared::disk_backend::BlockDevice';
+with 'ManaTools::Shared::disk_backend::PurposeLabelRole';
class_has '+type' => (
default => 'Disk'
@@ -207,4 +208,13 @@ class_has '+restrictions' => (
}
);
+override('label', sub {
+ my $self = shift;
+ my $label = super;
+ return $label if $label ne $self->type();
+
+ # get the name from the devicepath
+ return $self->devicepath() =~ s'^.+/''r;
+});
+
1;
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm
index 84f8aca4..1f004d73 100644
--- a/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm
+++ b/lib/ManaTools/Shared/disk_backend/Plugin/Extfs.pm
@@ -180,6 +180,7 @@ extends 'ManaTools::Shared::disk_backend::Part';
use MooseX::ClassAttribute;
with 'ManaTools::Shared::disk_backend::Mountable';
+with 'ManaTools::Shared::disk_backend::PurposeLabelRole';
sub _get_mount_source {
my $self = shift;
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Loop.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Loop.pm
index 10e37fc0..2e7b7a5c 100644
--- a/lib/ManaTools/Shared/disk_backend/Plugin/Loop.pm
+++ b/lib/ManaTools/Shared/disk_backend/Plugin/Loop.pm
@@ -186,6 +186,7 @@ use Moose;
extends 'ManaTools::Shared::disk_backend::Part';
with 'ManaTools::Shared::disk_backend::BlockDevice';
+with 'ManaTools::Shared::disk_backend::PurposeLabelRole';
use MooseX::ClassAttribute;
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Mount.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Mount.pm
index 635fc505..1ff2b5d1 100644
--- a/lib/ManaTools/Shared/disk_backend/Plugin/Mount.pm
+++ b/lib/ManaTools/Shared/disk_backend/Plugin/Mount.pm
@@ -463,6 +463,8 @@ use Moose;
extends 'ManaTools::Shared::disk_backend::Part';
+with 'ManaTools::Shared::disk_backend::PurposeLabelRole';
+
use MooseX::ClassAttribute;
class_has '+type' => (
@@ -526,6 +528,14 @@ override('_reverse_tag', sub {
return super;
});
+around('purpose_label', sub {
+ my $orig = shift;
+ my $self = shift;
+ my $partstate = shift;
+
+ return $self->path()
+});
+
package ManaTools::Shared::disk_backend::Part::UnknownBlockDevice;
use Moose;
@@ -535,6 +545,7 @@ extends 'ManaTools::Shared::disk_backend::Part';
use MooseX::ClassAttribute;
with 'ManaTools::Shared::disk_backend::BlockDevice';
+with 'ManaTools::Shared::disk_backend::PurposeLabelRole';
class_has '+type' => (
default => 'UnknownBlockDevice'
@@ -567,6 +578,7 @@ use MooseX::ClassAttribute;
with 'ManaTools::Shared::disk_backend::FileSystem';
with 'ManaTools::Shared::disk_backend::Mountable';
+with 'ManaTools::Shared::disk_backend::PurposeLabelRole';
class_has '+type' => (
default => 'UnknownFS'
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm
index e9a67ab8..534beda0 100644
--- a/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm
+++ b/lib/ManaTools/Shared/disk_backend/Plugin/Partition.pm
@@ -245,6 +245,7 @@ use Moose;
extends 'ManaTools::Shared::disk_backend::Part';
with 'ManaTools::Shared::disk_backend::BlockDevice';
+with 'ManaTools::Shared::disk_backend::PurposeLabelRole';
use MooseX::ClassAttribute;
@@ -305,4 +306,13 @@ class_has '+restrictions' => (
}
);
+override('label', sub {
+ my $self = shift;
+ my $label = super;
+ return $label if $label ne $self->type();
+
+ # get the name from the devicepath
+ return $self->devicepath() =~ s'^.+/''r;
+});
+
1;
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/Swap.pm b/lib/ManaTools/Shared/disk_backend/Plugin/Swap.pm
index 3a96036f..fc3e51cb 100644
--- a/lib/ManaTools/Shared/disk_backend/Plugin/Swap.pm
+++ b/lib/ManaTools/Shared/disk_backend/Plugin/Swap.pm
@@ -164,6 +164,8 @@ use Moose;
extends 'ManaTools::Shared::disk_backend::Part';
+with 'ManaTools::Shared::disk_backend::PurposeLabelRole';
+
use MooseX::ClassAttribute;
class_has '+type' => (
@@ -219,4 +221,12 @@ class_has '+restrictions' => (
}
);
+around('purpose_label', sub {
+ my $orig = shift;
+ my $self = shift;
+ my $partstate = shift;
+
+ return 'SWAP';
+});
+
1;
diff --git a/lib/ManaTools/Shared/disk_backend/PurposeLabelRole.pm b/lib/ManaTools/Shared/disk_backend/PurposeLabelRole.pm
new file mode 100644
index 00000000..bf7db326
--- /dev/null
+++ b/lib/ManaTools/Shared/disk_backend/PurposeLabelRole.pm
@@ -0,0 +1,90 @@
+# vim: set et ts=4 sw=4:
+package ManaTools::Shared::disk_backend::PurposeLabelRole;
+
+#============================================================= -*-perl-*-
+
+=head1 NAME
+
+ ManaTools::Shared::disk_backend::PurposeLabelRole - a PurposeLabelRole Moose Role
+
+=head1 SYNOPSIS
+ package Foo;
+
+ with 'ManaTools::Shared::disk_backend::PurposeLabelRole';
+
+ 1;
+
+ ...
+
+ my $f = Foo->new();
+ $f->prop('dev', 'maj:min');
+ $f->sync_majorminor();
+ my $major = $f->major();
+ my $minor = $f->minor();
+
+
+=head1 DESCRIPTION
+
+ This Role is an collection of PurposeLabelRole in the backend to manadisk
+
+=head1 SUPPORT
+
+ You can find documentation for this Role with the perldoc command:
+
+ perldoc ManaTools::Shared::disk_backend::PurposeLabelRole
+
+
+=head1 AUTHOR
+
+ Maarten Vanraes <alien@rmail.be>
+
+=head1 COPYRIGHT and LICENSE
+
+Copyright (c) 2015 Maarten Vanraes <alien@rmail.be>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2, as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+=head1 METHODS
+
+=cut
+
+use Moose::Role;
+
+#=============================================================
+
+=head2 purpose_label
+
+=head3 DESCRIPTION
+
+ this method finds in descendants the label denoting the purpose
+
+=cut
+
+#=============================================================
+sub purpose_label {
+ my $self = shift;
+ my $partstate = shift;
+ # finding a purpose label if one has overridden the purpose_label or has a PurposeLabelRole child
+ my @labels = ();
+ my @children = $self->children($partstate);
+ for my $child (@children) {
+ my $label = $child->purpose_label($partstate) if ($child->does('ManaTools::Shared::disk_backend::PurposeLabelRole'));
+ push @labels, $label if defined($label);
+ }
+ return undef if scalar(@labels) == 0;
+ @labels = sort @labels;
+ return $labels[0];
+}
+
+1;