packages feed

eternal (empty) → 0.0.1

raw patch · 13 files changed

+218/−0 lines, 13 filesdep +basedep +bytestringdep +conduitsetup-changed

Dependencies added: base, bytestring, conduit, directory, filepath, fsharp, http-conduit, http-types, network, process, regex-compat, transformers, utf8-string

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright 2014 Heather Cynede++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:++1. Redistributions of source code must retain the above copyright+   notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright+   notice, this list of conditions and the following disclaimer in the+   documentation and/or other materials provided with the distribution.++3. Neither the name of the author nor the names of his contributors+   may be used to endorse or promote products derived from this software+   without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ eternal.cabal view
@@ -0,0 +1,48 @@+name:       eternal
+category:   Control
+version:    0.0.1
+author:        Heather Cynede
+maintainer:    Heather Cynede <Cynede@Gentoo.org>
+license: BSD3
+license-file: LICENSE
+synopsis: everything breaking the Fairbairn threshold
+description:
+  Everything breaking the Fairbairn threshold
+  but in the same time usable in other projects
+
+build-type: Simple
+cabal-version: >= 1.6
+
+library
+  Hs-Source-Dirs: src
+
+  exposed-modules:
+    Control.Eternal
+    
+    Control.Eternal.Syntax
+    Control.Eternal.System
+    Control.Eternal.Algorithms
+    
+    Control.Eternal.Syntax.Operators
+    Control.Eternal.Syntax.Logic
+    
+    Control.Eternal.System.FileSystem
+    Control.Eternal.System.Exec
+    Control.Eternal.System.HTTP
+    
+    Control.Eternal.Algorithms.NaturalSort
+
+  Build-Depends:  
+    base >= 4.3 && < 5
+    , fsharp
+    , directory
+    , filepath
+    , regex-compat
+    , process
+    , network
+    , http-types
+    , conduit
+    , http-conduit
+    , transformers
+    , utf8-string
+    , bytestring
+ src/Control/Eternal.hs view
@@ -0,0 +1,9 @@+module Control.Eternal
+  ( module Control.Eternal.Syntax
+  , module Control.Eternal.System
+  , module Control.Eternal.Algorithms
+  ) where
+
+import Control.Eternal.Syntax
+import Control.Eternal.System
+import Control.Eternal.Algorithms
+ src/Control/Eternal/Algorithms.hs view
@@ -0,0 +1,5 @@+module Control.Eternal.Algorithms
+  ( module Control.Eternal.Algorithms.NaturalSort
+  ) where
+
+import Control.Eternal.Algorithms.NaturalSort
+ src/Control/Eternal/Algorithms/NaturalSort.hs view
@@ -0,0 +1,29 @@+module Control.Eternal.Algorithms.NaturalSort
+  ( nSort
+  ) where
+
+import Data.List
+import Data.Char
+
+nSort   ::  [String] -> [String]
+nSort s =   if all allFloat s then    
+                let { readFloat = read :: String -> Float } 
+                in  (map show . sortBy compare . map readFloat) s
+            else    
+                sortBy natComp s
+    where allFloat  =   all (\x -> isDigit x || '.' == 'x')
+
+natComp                                 ::  String -> String -> Ordering
+natComp [] []                           =   EQ
+natComp [] _                            =   LT
+natComp _ []                            =   GT
+natComp xxs@(x:xs) yys@(y:ys)
+    | noDigit x && noDigit y && x == y  =   natComp xs ys
+    | noDigit x || noDigit y            =   compare x y
+    | nx == ny                          =   natComp rx ry
+    | otherwise                         =   compare nx ny
+    where   (nx,rx)     =   getNumber xxs
+            (ny,ry)     =   getNumber yys
+            noDigit     =   not . isDigit
+            getNumber s =   let { digits = takeWhile isDigit s }
+                            in (read digits :: Integer, drop (length digits) s)
+ src/Control/Eternal/Syntax.hs view
@@ -0,0 +1,7 @@+module Control.Eternal.Syntax
+  ( module Control.Eternal.Syntax.Operators
+  , module Control.Eternal.Syntax.Logic
+  ) where
+
+import Control.Eternal.Syntax.Operators
+import Control.Eternal.Syntax.Logic
+ src/Control/Eternal/Syntax/Logic.hs view
@@ -0,0 +1,8 @@+module Control.Eternal.Syntax.Logic
+  ( ifSo
+  ) where
+
+import Control.Monad (when)
+
+ifSo :: IO () -> Bool -> IO ()
+ifSo = flip when
+ src/Control/Eternal/Syntax/Operators.hs view
@@ -0,0 +1,7 @@+module Control.Eternal.Syntax.Operators
+  ( (<|)
+  , (|>)
+  ) where
+
+import Control.FSharp.Syntax.Operators
+        {- probably maybe they will be even here... -}
+ src/Control/Eternal/System.hs view
@@ -0,0 +1,9 @@+module Control.Eternal.System
+  ( module Control.Eternal.System.FileSystem
+  , module Control.Eternal.System.Exec
+  , module Control.Eternal.System.HTTP
+  ) where
+
+import Control.Eternal.System.FileSystem
+import Control.Eternal.System.Exec
+import Control.Eternal.System.HTTP
+ src/Control/Eternal/System/Exec.hs view
@@ -0,0 +1,15 @@+module Control.Eternal.System.Exec
+  ( exec,
+    exc,
+  ) where
+
+import System.Directory (setCurrentDirectory)
+import System.Process (runCommand, waitForProcess)
+
+exec :: [Char] -> IO()
+exec args = do
+    pid <- runCommand args
+    waitForProcess pid >> return ()
+
+exc :: [Char] -> [Char] -> IO()
+exc path args = setCurrentDirectory path >> exec args
+ src/Control/Eternal/System/FileSystem.hs view
@@ -0,0 +1,19 @@+module Control.Eternal.System.FileSystem
+  ( copyDir
+  ) where
+
+import System.Directory(createDirectory, getDirectoryContents, doesDirectoryExist, copyFile)
+import Control.Monad(forM_)
+
+import System.FilePath((</>))
+
+copyDir ::  FilePath -> FilePath -> IO ()
+copyDir src dst = do
+    createDirectory dst
+    content <- getDirectoryContents src
+    let xs = filter (`notElem` [".", ".."]) content
+    forM_ xs $ \name -> let srcPath = src </> name
+                            dstPath = dst </> name
+        in doesDirectoryExist srcPath >>= \dirExist ->
+            if dirExist then copyDir srcPath dstPath
+                        else copyFile srcPath dstPath
+ src/Control/Eternal/System/HTTP.hs view
@@ -0,0 +1,30 @@+module Control.Eternal.System.HTTP
+  ( getHTTP
+  , download
+  ) where
+
+import Network.Socket (withSocketsDo)
+import Network.HTTP.Conduit
+
+import Data.Conduit.Binary (sinkFile)
+import Network.HTTP.Types
+
+import qualified Data.Conduit as C
+import qualified Data.ByteString.Lazy as L
+import qualified Codec.Binary.UTF8.String as S
+
+import Control.Monad.IO.Class (liftIO)
+
+getHTTP :: [Char] -> IO String
+getHTTP url = withSocketsDo
+    $ simpleHttp url
+        >>= \bs -> return $ S.decode $ L.unpack bs
+
+download :: String -> String -> IO()
+download url filename = withSocketsDo $ do
+    irequest <- liftIO $ parseUrl url
+    withManager $ \manager -> do
+        let request = irequest
+             { method = methodGet }
+        response <- http request manager
+        responseBody response C.$$+- sinkFile filename