1 % Copyright (C) 2002-2004 David Roundy 2 % 3 % This program is free software; you can redistribute it and/or modify 4 % it under the terms of the GNU General Public License as published by 5 % the Free Software Foundation; either version 2, or (at your option) 6 % any later version. 7 % 8 % This program is distributed in the hope that it will be useful, 9 % but WITHOUT ANY WARRANTY; without even the implied warranty of 10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 % GNU General Public License for more details. 12 % 13 % You should have received a copy of the GNU General Public License 14 % along with this program; see the file COPYING. If not, write to 15 % the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 % Boston, MA 02110-1301, USA. 17 18 19 \begin{code} 20 module Darcs.Repository.Motd (get_motd, show_motd) where 21 import Control.Monad ( unless ) 22 import Darcs.Flags ( DarcsFlag( Quiet, XMLOutput ) ) 23 import Darcs.External ( fetchFilePS, Cachable(..) ) 24 import Darcs.Global ( darcsdir ) 25 import qualified Data.ByteString as B (null, hPut, empty, ByteString) 26 import Darcs.Utils ( catchall ) 27 import System.IO ( stdout ) 28 \end{code} 29 30 \paragraph{motd}\label{motd} 31 The \verb!_darcs/prefs/motd! file may contain a ``message of the day'' 32 which will be displayed to users who get or pull from the repository without the 33 \verb!--quiet! option. 34 35 \begin{code} 36 -- | Fetch and return the message of the day for a given repository. 37 get_motd :: String -> IO B.ByteString 38 get_motd repo = fetchFilePS (repo++"/"++darcsdir++"/prefs/motd") (MaxAge 600) 39 `catchall` return B.empty 40 41 -- | Display the message of the day for a given repository, 42 -- unless either the 'XMLOutput' or the 'Quiet' flags are passed in 43 show_motd :: [DarcsFlag] -> String -> IO () 44 show_motd opts repo = unless (Quiet `elem` opts || XMLOutput `elem` opts) $ do 45 motd <- get_motd repo 46 unless (B.null motd) 47 $ do B.hPut stdout motd 48 putStrLn "**********************" 49 \end{code}