Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 44 additions & 13 deletions udisks/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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))
Expand Down Expand Up @@ -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=''):
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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)
48 changes: 48 additions & 0 deletions udisks/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/python
# coding: utf-8
# Copyright (C) 2011 Lucas Alvares Gomes <lucasagomes@gmail.com>
#
# 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 <http://www.gnu.org/licenses/>.

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()