Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
#!/usr/bin/python#by BC_Programming import dbusimport gobjectimport timeimport subprocess print "BASeCamp 'USBSounds' Simple USB Volume notification sound."#playsound merely shells out to mplayer. I would have preferred an integrated solution but... meh.def playsound(soundfile): subprocess.call(["mplayer", "hardwareinsert.wav"], stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w')) class DeviceAddedListener: def __init__(self): #get the system bus... self.bus = dbus.SystemBus() #get the manager self.hal_manager_obj = self.bus.get_object( 'org.freedesktop.Hal', '/org/freedesktop/Hal/Manager') #get the interface for the manager self.hal_manager = dbus.Interface(self.hal_manager_obj,'org.freedesktop.Hal.Manager') #connect to the appropriate signals. self.hal_manager.connect_to_signal('DeviceAdded', self._filteradd) self.hal_manager.connect_to_signal("DeviceRemoved",self._filterremove)#note: I couldn't get DeviceRemoval sounds to work since it doesn't let you #inspect whether the removed device is a volume via "QueryCapability"... since it's gone. def _filteradd(self, udi): device_obj = self.bus.get_object ('org.freedesktop.Hal', udi) device = dbus.Interface(device_obj, 'org.freedesktop.Hal.Device') #if it is a volume, call the do_add function... if device.QueryCapability("volume"): return self.do_add(device) def _filterremove(self,udi): try: #device_obj = self.bus.get_object('org.freedesktop.Hal',udi) #device = dbus.Interface(device_obj,'org.freedesktop.Hal.Device') #if device.QueryCapability("volume"): # return self.do_remove(device) except: return #unused.... def do_remove(self,volume): playsound("hardwareremove.wav") #displays some info about the added device to the console (maybe future changes can pop stuff like volume label, device file, size, etc into a Notification box?) def do_add(self, volume): device_file = volume.GetProperty("block.device") label = volume.GetProperty("volume.label") fstype = volume.GetProperty("volume.fstype") mounted = volume.GetProperty("volume.is_mounted") mount_point = volume.GetProperty("volume.mount_point") try: size = volume.GetProperty("volume.size") except: size = 0 print "New storage device detected:" print " device_file: %s" % device_file print " label: %s" % label print " fstype: %s" % fstype if mounted: print " mount_point: %s" % mount_point else: print " not mounted" print " size: %s (%.2fGB)" % (size, float(size) / 1024**3) #and play a sound. playsound("hardwareinsert.wav")#main loop...if __name__ == '__main__': from dbus.mainloop.glib import DBusGMainLoop DBusGMainLoop(set_as_default=True) loop = gobject.MainLoop() print "in __main__..." DeviceAddedListener() loop.run()
Why do you need a sound for that?
So that I know the drive was detected.
Can't you just look?If I recall correctly, the default behavior for Linux Mint is to auto-mount usb drives and show an icon on the desktop.
It's pretty cool that you wrote an entire script for that. I still think Firefox is the best browser, though.
What does firefox have to do with any of this?
At least it's not "or alternatively you could just install Windows, which plays the USB-add sound".
the Apache/MySQL/PHP stack is a lot easier to install & administer via on Linux, and it is the primary role of the laptop.
Nothing. Just trolling!
Is it running a website?
the Apache/MySQL/PHP stack is a lot easier to install & administer via on Linux
much easier to edit a file in var/www than have to download it, edit it, and then upload it back to my web host, then test it.
TL;DR databases are a pain
I guess I'm just too lazy to come up with these elements all on my own
Using code that is already publically and freely available for use doesn't make you lazy, it makes you efficient. Or so my lecturer says.
No. it's lazy. But that's good. As Larry Wall notes, Sloth is one of the hallmarks of a good programmer.
No, it's not. No need to re-invent the wheel when it comes to programming.
String FormatTimeSpan(TimeSpan formatthis){ return String.Format("{0:00}:{1:00}",formatthis.TotalHours,formatthis.Minutes);}