diff options
author | nic80 <joe_c_moi@yahoo.fr> | 2020-05-30 14:15:26 +0200 |
---|---|---|
committer | Nicolas Lécureuil <neoclust@mageia.org> | 2020-06-02 10:55:39 +0200 |
commit | ea3b78d47a1b4a6f5d7419fd414edbe59ad35bca (patch) | |
tree | 22f8746929b88c4467b1ffad16c66a208d38e08c /lib | |
parent | d4a0a65eb198dab6b88e954b2a998482b80aa512 (diff) | |
download | draksnapshot-ea3b78d47a1b4a6f5d7419fd414edbe59ad35bca.tar draksnapshot-ea3b78d47a1b4a6f5d7419fd414edbe59ad35bca.tar.gz draksnapshot-ea3b78d47a1b4a6f5d7419fd414edbe59ad35bca.tar.bz2 draksnapshot-ea3b78d47a1b4a6f5d7419fd414edbe59ad35bca.tar.xz draksnapshot-ea3b78d47a1b4a6f5d7419fd414edbe59ad35bca.zip |
Get a working interface
Diffstat (limited to 'lib')
-rw-r--r--[-rwxr-xr-x] | lib/MDV/Snapshot/Hal.pm | 89 |
1 files changed, 77 insertions, 12 deletions
diff --git a/lib/MDV/Snapshot/Hal.pm b/lib/MDV/Snapshot/Hal.pm index 18736ae..51208c6 100755..100644 --- a/lib/MDV/Snapshot/Hal.pm +++ b/lib/MDV/Snapshot/Hal.pm @@ -32,9 +32,17 @@ use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw($hal_dn $hal_manager $manager_path find_removable_volumes get_system_bus is_proper_device); -our $hal_dn = 'org.freedesktop.Hal'; -our $hal_manager = "$hal_dn.Manager"; -our $manager_path = '/org/freedesktop/Hal/Manager'; +our $hal_dn = 'org.freedesktop.UDisks2'; +our $hal_manager = 'org.freedesktop.DBus.ObjectManager'; +our $manager_path = '/org/freedesktop/UDisks2'; +our $dbus_object_manager ='org.freedesktop.DBus.ObjectManager'; +our $block_devices='org.freedesktop.UDisks2.Block'; +our $path_to_drives='/org/freedesktop/UDisks2/drives'; +our $path_to_drive_prop='org.freedesktop.UDisks2.Drive'; +our $path_to_block_devices='/org/freedesktop/UDisks2/block_devices'; +our $path_to_block_prop_part='org.freedesktop.UDisks2.Partition'; +our $path_to_block_prop_file='org.freedesktop.UDisks2.Filesystem'; +our $path_to_block_prop_block='org.freedesktop.UDisks2.Block'; sub get_system_bus() { eval { dbus_object::system_bus() }; @@ -43,19 +51,76 @@ sub get_system_bus() { sub is_proper_device { my ($device, $o_is_first_check) = @_; # perl_checker: $device = Net::DBus::RemoteObject->new - my $device_name = $device->QueryCapability('block') && $device->GetProperty('block.device'); - return if !$device_name; - my $bool = $device->QueryCapability('volume') && !$device->GetProperty('volume.is_disc') && - $device->GetProperty('volume.is_mounted'); - return $o_is_first_check ? $bool && $device_name && cat_('/media/.hal-mtab') =~ m!^$device_name\s!sg : $bool; + #my $device_name = $device->QueryCapability('block') && $device->GetProperty('block.device'); + #return if !$device_name; + my $bool=0; + my @is_mounted; + if ( grep /^*[0-9]$/, $device ) { + + my ($dbus) = Net::DBus->system; + my $service = $dbus->get_service($hal_dn); + my $block_device_properties_object= $service->get_object($device,'org.freedesktop.DBus.Properties'); + my $is_read_only=$block_device_properties_object->Get($path_to_block_prop_block,"ReadOnly"); + print("Read only status of $device is :$is_read_only \n"); + if ( $is_read_only = "false") { # device is not readonly + my $is_zero_size=$block_device_properties_object->Get($path_to_block_prop_block,"Size"); + print("Size of $device is : $is_zero_size \n"); + if ( $is_zero_size > 0){ + @is_mounted=$block_device_properties_object->Get($path_to_block_prop_file,"MountPoints"); + if (@is_mounted != []){ + print("Block Device $device is proper for backups \n"); + $bool = 1; } + else + { + print("Block Device $device is NOT proper for backups \n"); + $bool = 0;} + } + } + } + + #return $o_is_first_check ? $bool && $device_name && cat_('/media/.hal-mtab') =~ m!^$device_name\s!sg : $bool; + #print("Value returned by is_proper_device: $bool \n"); + return $bool && @is_mounted; } sub find_removable_volumes { + #my ($dbus) = Net::DBus->system; my ($dbus) = @_; # perl_checker: $dbus = Net::DBus->new - my $hal = $dbus->get_service($hal_dn); # perl_checker: $dbus = Net::DBus->new - my $manager = $hal->get_object($manager_path, $hal_manager); # perl_checker: $manager = Net::DBus::RemoteObject + my $service = $dbus->get_service($hal_dn); # perl_checker: $dbus = Net::DBus->new + my $manager = $service->get_object($manager_path,$hal_manager); # perl_checker: $manager = Net::DBus::RemoteObject + my @eligible_drives;#To fill a list of drive that have the property MediaRemovable + my @eligible_block_devices; + my @drives= (grep /\/org\/freedesktop\/UDisks2\/drives\//,%{$manager->GetManagedObjects}); # To get only the list of present drives on computer whatever they are + my @block_devices=(grep /\/org\/freedesktop\/UDisks2\/block_devices\//,%{$manager->GetManagedObjects}); # To get the block_devices list on system to check against the drives + for(my $k=0;$k < scalar @drives;$k= $k+1){ + print ("Drive: @drives[$k]\n"); + } - grep { is_proper_device($_, 1) } map { $hal->get_object($_, "$hal_dn.Device") } @{$manager->GetAllDevices}; -} + for(my $i=0;$i < scalar @block_devices;$i= $i+1){ + print ("block_device: @block_devices[$i]\n"); + } + for (my $i=0;$i < scalar @drives;$i= $i+1){ + my $drives_properties_object= $service->get_object(@drives[$i],'org.freedesktop.DBus.Properties'); + my $is_removable=$drives_properties_object->Get($path_to_drive_prop,"MediaRemovable");# testing is drive is removable + if ($is_removable) { + push(@eligible_drives,@drives[$i]); # drive is removable; adding it to list to test block_device against + print("Removable device: @drives[$i] added \n"); + } + for (my $j=0;$j < scalar @block_devices;$j= $j+1){ + my $block_device_properties_object= $service->get_object(@block_devices[$j],'org.freedesktop.DBus.Properties'); + my $get_drive_from_block_device=$block_device_properties_object->Get($path_to_block_prop_block,"Drive"); + if (grep /^$get_drive_from_block_device$/,@eligible_drives) { + print("testing:@block_devices[$j], from $get_drive_from_block_device\n"); + push(@eligible_block_devices,@block_devices[$j]); + is_proper_device(@block_devices[$j], 1); + } + } + } + #grep { is_proper_device($_, 1) } map { $service->get_object($_, "$block_devices") } @eligible_block_devices; + #grep { is_proper_device($_, 1) } map { $service->get_object($_, "$block_devices") } @{$manager->GetManagedObjects}; + } + +#my $dbus_test=get_system_bus; +#$dbus_test.find_removable_volumes; 1; |