From 451a12d1d4019e5f0708a63311f290786eb43cbc Mon Sep 17 00:00:00 2001 From: icoz Date: Tue, 5 Feb 2013 17:57:47 +0400 Subject: [PATCH] add some stuff --- udisks/device.py | 57 +++++++++++++++++++++++++++++++++++++----------- udisks/main.py | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 13 deletions(-) create mode 100755 udisks/main.py diff --git a/udisks/device.py b/udisks/device.py index db4d49b..d29bd8e 100644 --- a/udisks/device.py +++ b/udisks/device.py @@ -19,6 +19,17 @@ from interface import Interface from interface import DEVICE_IFACE from exceptions import * +from collections import namedtuple + +# InfoDevice = namedtuple("InfoDevice", "DeviceFile DeviceSize +# DeviceIsRemovable DeviceIsMounted DeviceIsMediaAvailable +# DeviceMountPaths DeviceMountedByUid") +InfoDevice = namedtuple("InfoDevice", "devfile size isRemovable isMounted isMediaAvailable mountPaths mountedByUid") +# InfoPartition = namedtuple("InfoPartition", "PartitionScheme +# PartitionNumber PartitionType PartitionLabel PartitionUuid +# PartitionFlags PartitionSize") +InfoPartition = namedtuple("InfoPartition", "scheme number type label uuid flags size") + class Device(Interface): @@ -29,7 +40,7 @@ def __init__(self, object_path): def _exec_func(self, func, args=()): try: return func(*args) - except dbus.exceptions.DBusException, e: + except dbus.exceptions.DBusException as e: e_name = e.get_dbus_name() if e_name == "org.freedesktop.PolicyKit.Error.NotAuthorized": raise NotAuthorized(str(e)) @@ -94,7 +105,7 @@ def LuksUnlock(self, passphrase, options=''): def LuksLock(self, options=''): raise NotImplementedError - def LuksChangePassphrase(self, current_passphrase, new_passphrase): + def LuksChangePassphrase(self, current_passphrase, new_passphrase): raise NotImplementedError def LinuxMdAddComponent(self, component, options=''): @@ -104,7 +115,7 @@ def LinuxMdRemoveComponent(self, component, options=''): raise NotImplementedError def LinuxMdStop(self, options=''): - raise NotImplementedError + raise NotImplementedError def LinuxLvm2LVStop(self, options=''): raise NotImplementedError @@ -281,7 +292,7 @@ def DeviceIsLinuxDmmp(self): @property def DeviceSize(self): - return long(self._get_property("DeviceSize")) + return int(self._get_property("DeviceSize")) @property def DeviceBlockSize(self): @@ -388,11 +399,11 @@ def PartitionNumber(self): @property def PartitionOffset(self): - return long(self._get_property("PartitionOffset")) + return int(self._get_property("PartitionOffset")) @property def PartitionSize(self): - return long(self._get_property("PartitionSize")) + return int(self._get_property("PartitionSize")) @property def PartitionTableScheme(self): @@ -436,7 +447,7 @@ def DriveConnectionInterface(self): @property def DriveConnectionSpeed(self): - return long(self._get_property("DriveConnectionSpeed")) + return int(self._get_property("DriveConnectionSpeed")) @property def DriveMediaCompatibility(self): @@ -507,7 +518,7 @@ def DriveAtaSmartIsAvailable(self): @property def DriveAtaSmartTimeCollected(self): - return long(self._get_property("DriveAtaSmartTimeCollected")) + return int(self._get_property("DriveAtaSmartTimeCollected")) @property def DriveAtaSmartStatus(self): @@ -602,7 +613,7 @@ def LinuxMdSyncPercentage(self): @property def LinuxMdSyncSpeed(self): - return long(self._get_property("LinuxMdSyncSpeed")) + return int(self._get_property("LinuxMdSyncSpeed")) @property def LinuxLvm2PVUuid(self): @@ -622,19 +633,19 @@ def LinuxLvm2PVGroupUuid(self): @property def LinuxLvm2PVGroupSize(self): - return long(self._get_property("LinuxLvm2PVGroupSize")) + return int(self._get_property("LinuxLvm2PVGroupSize")) @property def LinuxLvm2PVGroupUnallocatedSize(self): - return long(self._get_property("LinuxLvm2PVGroupUnallocatedSize")) + return int(self._get_property("LinuxLvm2PVGroupUnallocatedSize")) @property def LinuxLvm2PVGroupSequenceNumber(self): - return long(self._get_property("LinuxLvm2PVGroupSequenceNumber")) + return int(self._get_property("LinuxLvm2PVGroupSequenceNumber")) @property def LinuxLvm2PVGroupExtentSize(self): - return long(self._get_property("LinuxLvm2PVGroupExtentSize")) + return int(self._get_property("LinuxLvm2PVGroupExtentSize")) @property def LinuxLvm2PVGroupPhysicalVolumes(self): @@ -682,3 +693,23 @@ def LinuxDmmpSlaves(self): def LinuxDmmpParameters(self): return str(self._get_property("LinuxDmmpParameters")) + def GetInfoPartition(self): + scheme = self.PartitionScheme + number = self.PartitionNumber + ptype = self.PartitionType + label = self.PartitionLabel + uuid = self.PartitionUuid + flags = self.PartitionFlags + size = self.PartitionSize + return InfoPartition(scheme, number, ptype, label, uuid, flags, size) + + def GetInfoDevice(self): + + devfile = self.DeviceFile + size = self.DeviceSize + isRemovable = self.DeviceIsRemovable + isMounted = self.DeviceIsMounted + isMediaAvailable = self.DeviceIsMediaAvailable + mountPaths = self.DeviceMountPaths + mountedByUid = self.DeviceMountedByUid + return InfoDevice(devfile, size, isRemovable, isMounted, isMediaAvailable, mountPaths, mountedByUid) diff --git a/udisks/main.py b/udisks/main.py new file mode 100755 index 0000000..7f41f3f --- /dev/null +++ b/udisks/main.py @@ -0,0 +1,48 @@ +#!/usr/bin/python +# coding: utf-8 +# Copyright (C) 2011 Lucas Alvares Gomes +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# 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, see . + +import udisks + + +def main(): + ud = udisks.UDisks() + print("EnumerateAdapters") + for adp in ud.EnumerateAdapters(): + print(adp.NativePath) + print("EnumerateExpanders") + for adp in ud.EnumerateExpanders(): + print(adp.NativePath) + print("EnumeratePorts") + for adp in ud.EnumeratePorts(): + print(adp.NativePath) + + # print("EnumerateDeviceFiles") + # for dev in ud.EnumerateDeviceFiles(): + # print(dev) + print("EnumerateDevices") + for dev in ud.EnumerateDevices(): + # print(dev.NativePath) + # print(dev.DriveModel, dev.DriveRotationRate) + # print(dev.DeviceFile, dev.IdLabel, dev.PartitionType, dev.PartitionUuid, dev.DeviceIsRemovable, dev.DeviceIsPartition, dev.DeviceIsMounted) + # print(dev.DeviceFile) + print(dev.GetInfoDevice()) + if dev.DeviceIsPartition: + print(dev.GetInfoPartition()) + + +if __name__ == '__main__': + main()