From ae61c95ee8e4ff85ee6c39f610b670401b6e8d53 Mon Sep 17 00:00:00 2001 From: John Soros Date: Mon, 8 Oct 2012 13:36:14 +0200 Subject: Enable the monitoring of non-mounted disks and partitions in DiskIO --- src/Plugins/Monitors/Disk.hs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/Plugins/Monitors') diff --git a/src/Plugins/Monitors/Disk.hs b/src/Plugins/Monitors/Disk.hs index 554be05..d52dce2 100644 --- a/src/Plugins/Monitors/Disk.hs +++ b/src/Plugins/Monitors/Disk.hs @@ -51,6 +51,20 @@ mountedDevices req = do isReq (d, p) = p `elem` req || drop 5 d `elem` req undev (d, f) = (drop 5 d, f) +availDevices :: [String] -> IO [(DevName, Path)] +availDevices req = do + s <- B.readFile "/proc/diskstats" + parse `fmap` mapM canon (devs s) + where + canon (d, p) = do {d' <- canonicalizePath ("/dev/"++d); return (d', p)} + devs = map (third . B.words) . B.lines + parse = map undev . filter isReq + third (_:_:c:_) = (B.unpack c, B.unpack c) + third _ = ("", "") + isReq (d, p) = p `elem` req || drop 5 d `elem` req + undev (d, f) = (drop 5 d, f) + + diskData :: IO [(DevName, [Float])] diskData = do s <- B.readFile "/proc/diskstats" @@ -109,7 +123,7 @@ runDiskIO' (tmp, xs) = do runDiskIO :: DevDataRef -> [(String, String)] -> [String] -> Monitor String runDiskIO dref disks _ = do - mounted <- io $ mountedDevices (map fst disks) + mounted <- io $ availDevices (map fst disks) dat <- io $ mountedData dref (map fst mounted) strs <- mapM runDiskIO' $ devTemplates disks mounted dat return $ unwords strs @@ -117,7 +131,7 @@ runDiskIO dref disks _ = do startDiskIO :: [(String, String)] -> [String] -> Int -> (String -> IO ()) -> IO () startDiskIO disks args rate cb = do - mounted <- mountedDevices (map fst disks) + mounted <- availDevices (map fst disks) dref <- newIORef (map (\d -> (fst d, repeat 0)) mounted) _ <- mountedData dref (map fst mounted) runM args diskIOConfig (runDiskIO dref disks) rate cb -- cgit v1.2.3 From b683b474fa5b8cbb29704f88f7a43f8084dd8070 Mon Sep 17 00:00:00 2001 From: John Soros Date: Thu, 11 Oct 2012 15:01:10 +0200 Subject: Second try at fixing #73 and #74: enable io monitoring for non-mounted disks --- src/Plugins/Monitors/Disk.hs | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'src/Plugins/Monitors') diff --git a/src/Plugins/Monitors/Disk.hs b/src/Plugins/Monitors/Disk.hs index d52dce2..3c8ea04 100644 --- a/src/Plugins/Monitors/Disk.hs +++ b/src/Plugins/Monitors/Disk.hs @@ -39,31 +39,27 @@ type DevDataRef = IORef [(DevName, [Float])] mountedDevices :: [String] -> IO [(DevName, Path)] mountedDevices req = do - s <- B.readFile "/etc/mtab" - parse `fmap` mapM canon (devs s) + sm <- B.readFile "/etc/mtab" + sd <- B.readFile "/proc/diskstats" + parse `fmap` mapM canon (devs [sm, sd]) where canon (d, p) = do {d' <- canonicalizePath d; return (d', p)} - devs = filter isDev . map (firstTwo . B.words) . B.lines + devs fs = concatMap devs' fs + where + devs' f = case (devsm f) of + [] -> devsd f + d -> d + firstTwo (a:b:_) = (B.unpack a, B.unpack b) + firstTwo _ = ("", "") + third (_:_:c:_) = ("/dev/"++(B.unpack c), B.unpack c) + third _ = ("", "") + devsm = filter isDev . map (firstTwo . B.words) . B.lines + devsd = filter isDev . map (third . B.words) . B.lines parse = map undev . filter isReq - firstTwo (a:b:_) = (B.unpack a, B.unpack b) - firstTwo _ = ("", "") isDev (d, _) = "/dev/" `isPrefixOf` d isReq (d, p) = p `elem` req || drop 5 d `elem` req undev (d, f) = (drop 5 d, f) -availDevices :: [String] -> IO [(DevName, Path)] -availDevices req = do - s <- B.readFile "/proc/diskstats" - parse `fmap` mapM canon (devs s) - where - canon (d, p) = do {d' <- canonicalizePath ("/dev/"++d); return (d', p)} - devs = map (third . B.words) . B.lines - parse = map undev . filter isReq - third (_:_:c:_) = (B.unpack c, B.unpack c) - third _ = ("", "") - isReq (d, p) = p `elem` req || drop 5 d `elem` req - undev (d, f) = (drop 5 d, f) - diskData :: IO [(DevName, [Float])] diskData = do @@ -123,7 +119,7 @@ runDiskIO' (tmp, xs) = do runDiskIO :: DevDataRef -> [(String, String)] -> [String] -> Monitor String runDiskIO dref disks _ = do - mounted <- io $ availDevices (map fst disks) + mounted <- io $ mountedDevices (map fst disks) dat <- io $ mountedData dref (map fst mounted) strs <- mapM runDiskIO' $ devTemplates disks mounted dat return $ unwords strs @@ -131,7 +127,7 @@ runDiskIO dref disks _ = do startDiskIO :: [(String, String)] -> [String] -> Int -> (String -> IO ()) -> IO () startDiskIO disks args rate cb = do - mounted <- availDevices (map fst disks) + mounted <- mountedDevices (map fst disks) dref <- newIORef (map (\d -> (fst d, repeat 0)) mounted) _ <- mountedData dref (map fst mounted) runM args diskIOConfig (runDiskIO dref disks) rate cb -- cgit v1.2.3 From e1a5d4b5f96a421be13935166b566ba061fed806 Mon Sep 17 00:00:00 2001 From: John Soros Date: Thu, 11 Oct 2012 18:15:20 +0200 Subject: Fix for #73: third try: retain old behaviour for diskU, use device for diskIO if device is not mounted --- src/Plugins/Monitors/Disk.hs | 50 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'src/Plugins/Monitors') diff --git a/src/Plugins/Monitors/Disk.hs b/src/Plugins/Monitors/Disk.hs index 3c8ea04..73bd5b7 100644 --- a/src/Plugins/Monitors/Disk.hs +++ b/src/Plugins/Monitors/Disk.hs @@ -39,27 +39,37 @@ type DevDataRef = IORef [(DevName, [Float])] mountedDevices :: [String] -> IO [(DevName, Path)] mountedDevices req = do - sm <- B.readFile "/etc/mtab" - sd <- B.readFile "/proc/diskstats" - parse `fmap` mapM canon (devs [sm, sd]) + s <- B.readFile "/etc/mtab" + parse `fmap` mapM canon (devs s) where canon (d, p) = do {d' <- canonicalizePath d; return (d', p)} - devs fs = concatMap devs' fs - where - devs' f = case (devsm f) of - [] -> devsd f - d -> d - firstTwo (a:b:_) = (B.unpack a, B.unpack b) - firstTwo _ = ("", "") - third (_:_:c:_) = ("/dev/"++(B.unpack c), B.unpack c) - third _ = ("", "") - devsm = filter isDev . map (firstTwo . B.words) . B.lines - devsd = filter isDev . map (third . B.words) . B.lines + devs = filter isDev . map (firstTwo . B.words) . B.lines parse = map undev . filter isReq + firstTwo (a:b:_) = (B.unpack a, B.unpack b) + firstTwo _ = ("", "") isDev (d, _) = "/dev/" `isPrefixOf` d isReq (d, p) = p `elem` req || drop 5 d `elem` req undev (d, f) = (drop 5 d, f) +diskDevices :: [String] -> IO [(DevName, Path)] +diskDevices req = do + s <- B.readFile "/proc/diskstats" + parse `fmap` mapM canon (devs s) + where + canon (d, p) = do {d' <- canonicalizePath (d); return (d', p)} + devs = map (third . B.words) . B.lines + parse = map undev . filter isReq + third (_:_:c:_) = ("/dev/" ++ (B.unpack c), B.unpack c) + third _ = ("", "") + isReq (d, p) = p `elem` req || drop 5 d `elem` req + undev (d, f) = (drop 5 d, f) + +mountedOrDiskDevices :: [String] -> IO [(DevName, Path)] +mountedOrDiskDevices req = do + mnt <- mountedDevices req + case mnt of + [] -> diskDevices req + other -> return other diskData :: IO [(DevName, [Float])] diskData = do @@ -119,17 +129,17 @@ runDiskIO' (tmp, xs) = do runDiskIO :: DevDataRef -> [(String, String)] -> [String] -> Monitor String runDiskIO dref disks _ = do - mounted <- io $ mountedDevices (map fst disks) - dat <- io $ mountedData dref (map fst mounted) - strs <- mapM runDiskIO' $ devTemplates disks mounted dat + dev <- io $ mountedOrDiskDevices (map fst disks) + dat <- io $ mountedData dref (map fst dev) + strs <- mapM runDiskIO' $ devTemplates disks dev dat return $ unwords strs startDiskIO :: [(String, String)] -> [String] -> Int -> (String -> IO ()) -> IO () startDiskIO disks args rate cb = do - mounted <- mountedDevices (map fst disks) - dref <- newIORef (map (\d -> (fst d, repeat 0)) mounted) - _ <- mountedData dref (map fst mounted) + dev <- mountedOrDiskDevices (map fst disks) + dref <- newIORef (map (\d -> (fst d, repeat 0)) dev) + _ <- mountedData dref (map fst dev) runM args diskIOConfig (runDiskIO dref disks) rate cb fsStats :: String -> IO [Integer] -- cgit v1.2.3 From 30902974c1a21990930f302c50e136954aed4c76 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Fri, 12 Oct 2012 05:04:18 +0200 Subject: Additional MPRIS2 arguments --- news.md | 1 + readme.md | 17 +++++++++++++---- src/Plugins/Monitors/Mpris.hs | 7 +++++-- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src/Plugins/Monitors') diff --git a/news.md b/news.md index cc87a72..7ff265b 100644 --- a/news.md +++ b/news.md @@ -22,6 +22,7 @@ _New features_ Trofimovich). - Dependencies on the deprecated dbus-core removed in favour of dbus 0.10 (thanks to Jochen Keil). + - MPris2 now includes genre and composer among its fields. _Bug fixes_ diff --git a/readme.md b/readme.md index 2764478..74438b0 100644 --- a/readme.md +++ b/readme.md @@ -906,13 +906,22 @@ something like: - Default template: ` - ` - Example: - Run Mpris1 "clementine" ["-t", - "<artist> - [<tracknumber>] <title>"] 10 + Run Mpris1 "clementine" ["-t", "<artist> - [<tracknumber>] <title>"] 10 ### `Mpris2 PlayerName Args RefreshRate` -- Just like Mpris1. - Supposed to be used with mediaplayers which support MPRIS v2. +- Aliases to `mpris1` +- Requires [dbus] and [text] packages. + To activate, pass `--flags="with_mpris"` during compilation. +- PlayerName: player supporting MPRIS v2 protocol, in lowercase. +- Args: default monitor arguments. +- Variables that can be used with the `-t`/`--template` argument: + `album`, `artist`, `arturl`, `length`, `title`, + `tracknumber`, `composer`, `genre` +- Default template: `<artist> - <title>` +- Example: + + Run Mpris2 "clementine" ["-t", "<artist> - [<composer>] <title>"] 10 ### `Mail Args Alias` diff --git a/src/Plugins/Monitors/Mpris.hs b/src/Plugins/Monitors/Mpris.hs index b899a16..98b4c0f 100644 --- a/src/Plugins/Monitors/Mpris.hs +++ b/src/Plugins/Monitors/Mpris.hs @@ -66,12 +66,15 @@ instance MprisVersion MprisVersion2 where ["org.mpris.MediaPlayer2.Player", "Metadata"] fieldsList MprisVersion2 = [ "xesam:album", "xesam:artist", "mpris:artUrl" - , "mpris:length", "xesam:title", "xesam:trackNumber" + , "mpris:length", "xesam:title", + "xesam:trackNumber", "xesam:composer", + "xesam:genre" ] mprisConfig :: IO MConfig mprisConfig = mkMConfig "<artist> - <title>" - [ "album", "artist", "arturl", "length" , "title", "tracknumber" + [ "album", "artist", "arturl", "length" + , "title", "tracknumber" , "composer", "genre" ] dbusClient :: DC.Client -- cgit v1.2.3