shellmate 0.2.2 → 0.2.3
raw patch · 3 files changed
+71/−28 lines, 3 filesdep +HTTPdep +network-uridep −download-curl
Dependencies added: HTTP, network-uri
Dependencies removed: download-curl
Files
- Control/Shell.hs +1/−0
- Control/Shell/Download.hs +47/−16
- shellmate.cabal +23/−12
Control/Shell.hs view
@@ -128,6 +128,7 @@ -- current name. cpdir :: FilePath -> FilePath -> Shell () cpdir fromdir todir = do+ assert ("`" ++ fromdir ++ "' is not a directory") (isDirectory fromdir) exists <- isDirectory todir if exists then do
Control/Shell/Download.hs view
@@ -1,53 +1,84 @@--- | Shellmate wrapper for @download-curl@.-module Control.Shell.Download (- URI,- fetch, fetchBytes,- fetchFile,- fetchTags, fetchXML, fetchFeed+{-# LANGUAGE OverloadedStrings, CPP #-}+-- | High level functions for downloading files.+module Control.Shell.Download+ ( URI+ , fetch, fetchBytes+ , fetchFile+#if DOWNLOAD_EXTRAS+ , fetchTags, fetchXML, fetchFeed+#endif ) where import Data.ByteString as BS (ByteString, writeFile)-import Network.Curl.Download as C-import Text.HTML.TagSoup (Tag)-import Text.XML.Light.Types (Content)+import Data.String+import Network.HTTP+import qualified Network.URI as U+#if DOWNLOAD_EXTRAS+import Text.Feed.Import (parseFeedString) import Text.Feed.Types (Feed)+import Text.HTML.TagSoup (Tag, parseTags)+import Text.XML.Light (Content, parseXML)+#endif import Control.Shell -- | A Uniform Resource Locator. type URI = String -liftE :: IO (Either String a) -> Shell a+liftE :: Show e => IO (Either e a) -> Shell a liftE m = do res <- liftIO m case res of- Left e -> fail e+ Left e -> fail (show e) Right x -> return x +httpFail :: (Int, Int, Int) -> String -> Shell a+httpFail (a,b,c) reason =+ fail $ "HTTP error " ++ concat [show a, show b, show c] ++ ": " ++ reason++fetchSomething :: (IsString a, HStream a) => URI -> Shell a+fetchSomething uri = do+ u <- assert ("could not parse URI `" ++ uri ++ "'") (U.parseURI uri)+ rsp <- liftE $ simpleHTTP (req u)+ case rspCode rsp of+ (2,_,_) -> return (rspBody rsp)+ code -> httpFail code (rspReason rsp)+ where+ req u = Request {+ rqURI = u,+ rqMethod = GET,+ rqHeaders = [],+ rqBody = ""+ }+ -- | Download content specified by a url using curl, returning the content -- as a strict 'ByteString'. fetchBytes :: URI -> Shell ByteString-fetchBytes = liftE . C.openURI+fetchBytes = fetchSomething -- | Download content specified by a url using curl, returning the content -- as a 'String'. fetch :: URI -> Shell String-fetch = liftE . C.openURIString+fetch = fetchSomething -- | Download content specified by a url using curl, writing the content to -- the file specified by the given 'FilePath'. fetchFile :: FilePath -> URI -> Shell () fetchFile file = fetchBytes >=> liftIO . BS.writeFile file +#if DOWNLOAD_EXTRAS -- | Download the content as for 'fetch', but return it as a list of parsed -- tags using the tagsoup html parser. fetchTags :: URI -> Shell [Tag String]-fetchTags = liftE . C.openAsTags+fetchTags = fmap parseTags . fetch -- | Download the content as for 'fetch', but return it as parsed XML, using -- the xml-light parser. fetchXML :: URI -> Shell [Content]-fetchXML = liftE . C.openAsXML+fetchXML = fmap parseXML . fetch -- | Download the content as for 'fetch', but return it as as parsed RSS or -- Atom content, using the feed library parser. fetchFeed :: URI -> Shell Feed-fetchFeed = liftE . C.openAsFeed+fetchFeed uri = do+ str <- fetch uri+ assert ("could not parse feed from `" ++ uri ++ "'") (parseFeedString str)+#endif
shellmate.cabal view
@@ -1,5 +1,5 @@ name: shellmate-version: 0.2.2+version: 0.2.3 synopsis: Simple interface for shell scripting in Haskell. description: Aims to simplify development of cross-platform shell scripts and similar things. homepage: http://github.com/valderman/shellmate@@ -17,6 +17,10 @@ type: git location: https://github.com/valderman/shellmate.git +flag download-extras+ default: True+ description: Build Control.Shell.Download with extras for parsing downloaded HTML, XML, RSS and Atom feeds.+ library exposed-modules: Control.Shell@@ -26,16 +30,23 @@ Control.Shell.Handle Control.Shell.Internal build-depends:- base >=4.7 && <5,- transformers >=0.3 && <0.5,- download-curl >=0.1 && <0.2,- feed >=0.3 && <0.4,- tagsoup >=0.13 && <0.14,- xml >=1.3 && <1.4,- bytestring >=0.10 && <0.11,- filepath >=1.3 && <1.5,- process >=1.1 && <1.5,- directory >=1.1 && <1.3,- temporary >=1.1 && <1.3+ base >=4.7 && <5,+ transformers >=0.3 && <0.5,+ bytestring >=0.10 && <0.11,+ filepath >=1.3 && <1.5,+ process >=1.1 && <1.5,+ directory >=1.1 && <1.3,+ temporary >=1.1 && <1.3,+ -- for Control.Shell.Download+ HTTP >=4000.2 && <4000.3,+ network-uri >=2.6 && <2.7++ if flag(download-extras)+ build-depends: + feed >=0.3 && <0.4,+ tagsoup >=0.13 && <0.14,+ xml >=1.3 && <1.4+ cpp-options:+ -DDOWNLOAD_EXTRAS=1 ghc-options: -Wall