|
@ -28,27 +28,14 @@ class Device: |
|
|
udi) |
|
|
udi) |
|
|
deviceProperties = deviceObj.GetAllProperties( |
|
|
deviceProperties = deviceObj.GetAllProperties( |
|
|
dbus_interface = 'org.freedesktop.Hal.Device') |
|
|
dbus_interface = 'org.freedesktop.Hal.Device') |
|
|
self.vendor = deviceProperties['usb_device.vendor'] |
|
|
|
|
|
self.product = deviceProperties['info.product'] |
|
|
|
|
|
self.serialNumber = deviceProperties['usb_device.serial'] |
|
|
|
|
|
|
|
|
if deviceProperties['storage.removable'] != 1: |
|
|
|
|
|
raise Exception, 'Not a removable device' |
|
|
|
|
|
self.vendor = deviceProperties['info.vendor'] |
|
|
|
|
|
self.product = deviceProperties['storage.model'] |
|
|
|
|
|
self.serialNumber = deviceProperties['storage.serial'] |
|
|
if len(self.volumes()) < 1: |
|
|
if len(self.volumes()) < 1: |
|
|
raise Exception, 'Device does not contain any volume' |
|
|
raise Exception, 'Device does not contain any volume' |
|
|
|
|
|
|
|
|
def __isChildOfDevice(self, udi): |
|
|
|
|
|
obj = bus.get_object('org.freedesktop.Hal', udi) |
|
|
|
|
|
properties = obj.GetAllProperties( |
|
|
|
|
|
dbus_interface = 'org.freedesktop.Hal.Device') |
|
|
|
|
|
if not properties.has_key('info.parent'): |
|
|
|
|
|
return False |
|
|
|
|
|
if properties.has_key('info.bus') and properties['info.bus'] == 'usb_device': |
|
|
|
|
|
return False |
|
|
|
|
|
if properties['info.parent'] == self.__udi: |
|
|
|
|
|
return True |
|
|
|
|
|
return self.__isChildOfDevice(properties['info.parent']) |
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self): |
|
|
|
|
|
return "%s %s (%s)" % (self.vendor, self.product, self.serialNumber) |
|
|
|
|
|
|
|
|
|
|
|
def volumes(self): |
|
|
def volumes(self): |
|
|
vols = [] |
|
|
vols = [] |
|
|
for volume in halManager.FindDeviceByCapability('volume'): |
|
|
for volume in halManager.FindDeviceByCapability('volume'): |
|
@ -56,14 +43,17 @@ class Device: |
|
|
volume) |
|
|
volume) |
|
|
deviceProperties = deviceObj.GetAllProperties( |
|
|
deviceProperties = deviceObj.GetAllProperties( |
|
|
dbus_interface = 'org.freedesktop.Hal.Device') |
|
|
dbus_interface = 'org.freedesktop.Hal.Device') |
|
|
if deviceProperties['block.major'] != 8: |
|
|
|
|
|
|
|
|
if deviceProperties['info.parent'] != self.__udi: |
|
|
continue |
|
|
continue |
|
|
if not self.__isChildOfDevice(volume): |
|
|
|
|
|
|
|
|
if deviceProperties['volume.is_partition'] != True: |
|
|
continue |
|
|
continue |
|
|
vols.append({'uuid' : deviceProperties['volume.uuid'], |
|
|
vols.append({'uuid' : deviceProperties['volume.uuid'], |
|
|
'device' : deviceProperties['block.device']}) |
|
|
'device' : deviceProperties['block.device']}) |
|
|
return vols |
|
|
return vols |
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self): |
|
|
|
|
|
return "%s %s (%s)" % (self.vendor, self.product, self.serialNumber) |
|
|
|
|
|
|
|
|
def listOptions(question, options, autodetect = True): |
|
|
def listOptions(question, options, autodetect = True): |
|
|
if autodetect == True and len(options) == 1: |
|
|
if autodetect == True and len(options) == 1: |
|
|
print question |
|
|
print question |
|
@ -151,7 +141,7 @@ def addUser(options): |
|
|
def addDevice(options): |
|
|
def addDevice(options): |
|
|
devices = [] |
|
|
devices = [] |
|
|
|
|
|
|
|
|
for udi in halManager.FindDeviceStringMatch('info.bus', 'usb_device'): |
|
|
|
|
|
|
|
|
for udi in halManager.FindDeviceByCapability('storage'): |
|
|
try: |
|
|
try: |
|
|
if options['verbose']: |
|
|
if options['verbose']: |
|
|
print 'Inspecting %s' % udi |
|
|
print 'Inspecting %s' % udi |
|
|