aboutsummaryrefslogtreecommitdiff
path: root/tprint
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-03-01 10:11:47 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2016-03-01 10:11:47 +0100
commit0ae7acc6217b1a06c8a1628c7a6dc2487ab55736 (patch)
tree152aaadce2404819a1e96975d9f4a2f3d5d2fe15 /tprint
parentc2153f196c64593a252bc0fbbc3d503628fe896f (diff)
downloadthermoprint-0ae7acc6217b1a06c8a1628c7a6dc2487ab55736.tar
thermoprint-0ae7acc6217b1a06c8a1628c7a6dc2487ab55736.tar.gz
thermoprint-0ae7acc6217b1a06c8a1628c7a6dc2487ab55736.tar.bz2
thermoprint-0ae7acc6217b1a06c8a1628c7a6dc2487ab55736.tar.xz
thermoprint-0ae7acc6217b1a06c8a1628c7a6dc2487ab55736.zip
jobs
Diffstat (limited to 'tprint')
-rw-r--r--tprint/src/Main.hs26
1 files changed, 25 insertions, 1 deletions
diff --git a/tprint/src/Main.hs b/tprint/src/Main.hs
index a937181..dcdeb4f 100644
--- a/tprint/src/Main.hs
+++ b/tprint/src/Main.hs
@@ -9,8 +9,11 @@ import Data.Text (Text)
9import qualified Data.Text as T 9import qualified Data.Text as T
10import qualified Data.ByteString.Lazy.Char8 as Lazy (ByteString) 10import qualified Data.ByteString.Lazy.Char8 as Lazy (ByteString)
11import qualified Data.ByteString.Lazy.Char8 as LCBS 11import qualified Data.ByteString.Lazy.Char8 as LCBS
12import Data.Time
12 13
13import Control.Monad 14import Data.Foldable
15import Data.List
16import Data.Monoid
14 17
15import Control.Monad 18import Control.Monad
16 19
@@ -36,6 +39,7 @@ withOutput TPrint{..} a
36 | otherwise = a stdout 39 | otherwise = a stdout
37 40
38tprint :: TPrint -> Client IO -> Handle -> IO () 41tprint :: TPrint -> Client IO -> Handle -> IO ()
42
39tprint TPrint{ operation = Printers, ..} Client{..} out = printers >>= format 43tprint TPrint{ operation = Printers, ..} Client{..} out = printers >>= format
40 where format ps 44 where format ps
41 | (Human, _) <- output = mapM_ (\(PrinterId n, st) -> hPutStrLn out $ show n ++ "\t" ++ humanStatus st) $ Map.toAscList ps 45 | (Human, _) <- output = mapM_ (\(PrinterId n, st) -> hPutStrLn out $ show n ++ "\t" ++ humanStatus st) $ Map.toAscList ps
@@ -43,4 +47,24 @@ tprint TPrint{ operation = Printers, ..} Client{..} out = printers >>= format
43 | otherwise = hPutStrLn out . dumpStr $ Map.toAscList ps 47 | otherwise = hPutStrLn out . dumpStr $ Map.toAscList ps
44 humanStatus (Busy (JobId n)) = "busy printing job #" ++ show n 48 humanStatus (Busy (JobId n)) = "busy printing job #" ++ show n
45 humanStatus (Available) = "available" 49 humanStatus (Available) = "available"
50
51tprint TPrint{ operation = Jobs{..}, ..} Client{..} out = jobs printer jobRange timeRange >>= format
52 where format js
53 | (Human, _) <- output = mapM_ (\((JobId n), created, status) -> hPutStrLn out $ show n ++ "\t" ++ formatTime defaultTimeLocale "%Y-%m-%d %H:%M:%S %Z" created ++ "\t" ++ humanStatus status printer) . sortBy jSort $ toList js
54 | (JSON, _) <- output = LCBS.hPutStrLn out $ encodePretty js
55 | otherwise = hPutStrLn out . dumpStr $ toList js
56 jSort (id, time, status) (id', time', status') = queueSort status status' <> compare time' time <> compare id id'
57 where
58 compare' :: Ord a => a -> a -> Ordering
59 compare'
60 | (Queued _) <- status = compare
61 | otherwise = flip compare
62 humanStatus (Queued (PrinterId n)) Nothing = "queued at printer #" ++ show n
63 humanStatus (Queued _) _ = "queued"
64 humanStatus (Printing (PrinterId n)) Nothing = "printing on printer #" ++ show n
65 humanStatus (Printing _) _ = "printing"
66 humanStatus (Done) _ = "finished successfully"
67 humanStatus (Failed err) _ = "failed: " ++ show err
68
69
46tprint _ _ _ = undefined 70tprint _ _ _ = undefined