From 081124150173e5ae3a25cffe2121d4c7d18c4844 Mon Sep 17 00:00:00 2001 From: mfrasca <> Date: Thu, 5 Oct 2006 14:34:44 +0000 Subject: [PATCH] 1293220: better format for action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit finalmente ho deciso di levare la flessibilità e permettere solo mount/umount/eject. questo semplifica molto il file di configurazione, ovviamente. --- examples/pywmhdmon.py | 29 ++++++++++++++++++++++++----- examples/sample.pywmhdmonrc | 10 +++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/examples/pywmhdmon.py b/examples/pywmhdmon.py index eb87123..66ebb25 100755 --- a/examples/pywmhdmon.py +++ b/examples/pywmhdmon.py @@ -250,11 +250,29 @@ class PywmHDMon: elif event['type'] == 'buttonrelease': area = wmdocklib.checkMouseRegion(event['x'],event['y']) if area is not -1: - action = self._pathsToMonitor[area-1+self._skipping][3] - if action: - os.spawnvp(os.P_NOWAIT, action[0], action) + self.toggleMount(area-1+self._skipping) event = wmdocklib.getEvent() + def toggleMount(self, line): + label, path, mode, action = self._pathsToMonitor[line] + if action is None: + return + try: + self.getHdInfo(path) + mounted = True + except NotMounted: + mounted = False + except OSError, e: + return + if mounted: + if action == 'mount': + os.spawnvp(os.P_NOWAIT, 'umount', ['umount', path]) + elif action == 'eject': + os.spawnvp(os.P_WAIT, 'umount', ['umount', path]) + os.spawnvp(os.P_NOWAIT, 'eject', ['eject', path]) + else: + os.spawnvp(os.P_NOWAIT, 'mount', ['mount', path]) + def updateMonitoredPaths(self): index = 0 pageoffset = self._skipping @@ -432,8 +450,9 @@ def main(): label = config.get(labelStr) if not label: break path = config.get(pathStr) - action = config.get(actionStr) - if action: action=eval(action) + action = config.get(actionStr, 'fixed').lower().strip() + if action not in ['mount', 'eject']: + action = None displayMode = config.get(modeStr, defaultMode) if not displayMode in displayModes: sys.stderr.write( diff --git a/examples/sample.pywmhdmonrc b/examples/sample.pywmhdmonrc index 35b39b7..a21246d 100644 --- a/examples/sample.pywmhdmonrc +++ b/examples/sample.pywmhdmonrc @@ -18,27 +18,27 @@ 4.label=cd 4.path=/mnt/cd 4.displaymode=used -4.action=['/home/mario/bin/tmount', '/mnt/cd', 'eject'] +4.action=eject 5.label=jr 5.path=/mnt/jr 5.displaymode=used -5.action=['/home/mario/bin/tmount', '/mnt/jr', 'eject'] +5.action=eject 6.label=sm 6.path=/mnt/sm 6.displaymode=free -6.action=['/home/mario/bin/tmount', '/mnt/sm'] +6.action=mount 7.label=cf 7.path=/mnt/cf 7.displaymode=free -7.action=['/home/mario/bin/tmount', '/mnt/cf'] +7.action=mount 8.label=flo 8.path=/mnt/flo 8.displaymode=free -8.action=['/home/mario/bin/tmount', '/mnt/flo'] +8.action=mount textcolor=light sea green background=black