KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17
System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64
User : nobody ( 99)
PHP Version : 5.2.17
Disable Function : NONE
Directory :  /proc/21573/root/usr/lib/python2.4/site-packages/pirut/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/21573/root/usr/lib/python2.4/site-packages/pirut/HalCD.py
# Copyright 2007  Red Hat, Inc.
#
# Jeremy Katz <katzj@redhat.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; version 2 only
#
# 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.

import os, sys

import dbus
import dbus.glib

HALSERVICE = "org.freedesktop.Hal"

class HALManager:
    def __init__(self):
        try:
            self.bus = dbus.SystemBus()
            self.halobj = self.bus.get_object(HALSERVICE,
                                              '/org/freedesktop/Hal/Manager')
            self.hal = dbus.Interface(self.halobj,
                                      'org.freedesktop.Hal.Manager')
        except:
            self.bus = None
            self.halobj = None
            self.hal = None

    def GetDeviceByUDI(self, udi):
        if not self.bus:
            return None
        o = self.bus.get_object(HALSERVICE, udi)
        d = dbus.Interface(o, 'org.freedesktop.Hal.Device')

        return HALDevice(d, o, self.bus)

    def GetBlockDeviceByUDI(self, udi):
        if not self.bus:
            return None
        d = self.GetDeviceByUDI(udi)
        return HALBlockDevice(self, d)

    def GetDevicesByStringMatch(self, property, thestr):
        if self.hal is None:
            return []
        ret = []
        try:
            udis = self.hal.FindDeviceStringMatch(property, thestr)
        except dbus.DBusException:
            udis = []
        for udi in udis:
            ret.append(self.GetDeviceByUDI(udi))
        return ret

    def FindDeviceByCapability(self, cap):
        if self.hal is None:
            return []
        try:
            return self.hal.FindDeviceByCapability('storage.cdrom')
        except dbus.DBusException:
            return []

    def __getattr__(self, attr):
        if self.hal is None:
            return []
        try:
            return getattr(self.hal, attr)
        except dbus.DBusException:
            return []
        
class HALDevice:
    def __init__(self, device, object, bus):
        self.device = device
        self.object = object
        self.bus = bus

    def GetInterface(self, intf):
        i = dbus.Interface(self.object, intf)
        return HALDevice(i, self.object, self.bus)

    def __getitem__(self, item):
        return self.device.GetProperty(item)

    def __getattr__(self, attr):
        return getattr(self.device, attr)

class HALBlockDevice:
    def __init__(self, halmgr, haldev):
        if not haldev["block.device"]:
            raise RuntimeError, "not a block device!"
        self.haldev = haldev

        self.volumedev = None
        self.storagedev = None
        
        for x in halmgr.GetDevicesByStringMatch("block.device",
                                                haldev["block.device"]):
            if x.QueryCapability("volume"):
                self.volumedev = x
                self.volume = x.GetInterface("org.freedesktop.Hal.Device.Volume")
            elif x.QueryCapability("storage"):
                self.storagedev = x
                self.storage = x.GetInterface("org.freedesktop.Hal.Device.Storage")
        
    def mount(self):
        if not self.volume:
            raise RuntimeError, "No volume to mount!"
        return self.volume.Mount("", "", "")

    def umount(self):
        if not self.volume:
            raise RuntimeError, "No volume to mount!"
        return self.volume.Unmount("")

    def eject(self):
        if not self.storage:
            raise RuntimeError, "No device to eject!"
        return self.storage.Eject("")

    def lock(self, reason):
        return self.haldev.Lock(reason)

    def unlock(self):
        return self.haldev.Unlock()

    def __getitem__(self, item):
        if item.startswith("volume."):
            return self.volumedev.GetProperty(item)
        elif item.startswith("storage."):
            return self.storagedev.GetProperty(item)
        return self.haldev.GetProperty(item)

if __name__ == "__main__":
    hal = HALManager()
    udis = hal.FindDeviceByCapability('storage.cdrom')
    for u in udis:
        d = hal.GetDeviceByUDI(u)
        print d.GetProperty('info.udi'), d['info.udi']

        print "------------------------------------------"

        blk = HALBlockDevice(hal, d)
        import pdb; pdb.set_trace()

        sys.exit(0)

        for x in hal.GetDevicesByStringMatch("block.device", d["block.device"]):
            print x, x.GetProperty("info.category")
            if x["block.is_volume"]:
                v = x.GetInterface("org.freedesktop.Hal.Device.Volume")
#                print "volume:", v
                print "interfaces: ", x["info.interfaces"]                
                v.Mount("", "", "")

                if not x["volume.is_mounted"]:
                    continue

                print "contents of mountpoint: ",
                print os.listdir(x["volume.mount_point"])

                v.Unmount("")
            else:
#                print "not a volume"
                print "interfaces:" , x["info.interfaces"]


            print "------------------"
                
                
            

Anon7 - 2021