Skip to content

Commit

Permalink
ready to download everything
Browse files Browse the repository at this point in the history
  • Loading branch information
phischu committed Mar 19, 2013
1 parent 583c0bb commit 46158af
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions Master.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import Development.Shake.FilePath
import Development.Shake.Classes

import qualified System.Directory as IO
import qualified Data.Map as M
import Distribution.Text

import Distribution.Hackage.DB (readHackage')

import Paths

newtype Package = Package (Name,Version) deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
type Name = String
Expand All @@ -16,6 +19,7 @@ type Version = String
newtype ExtractedPackage = ExtractedPackage Package deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
newtype PackageArchive = PackageArchive Package deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
newtype PackageList = PackageList [Package] deriving (Show,Typeable,Eq,Hashable,Binary,NFData)
newtype GetPackageList = GetPackageList () deriving (Show,Typeable,Eq,Hashable,Binary,NFData)

instance Rule ExtractedPackage () where
storedValue (ExtractedPackage (Package (name,version))) = do
Expand All @@ -27,8 +31,8 @@ instance Rule PackageArchive () where
exists <- IO.doesFileExist (archiveDirectory package)
if exists then return (Just ()) else return Nothing

instance Rule () PackageList where
storedValue () = return Nothing
instance Rule GetPackageList PackageList where
storedValue (GetPackageList ()) = return Nothing

extractedDirectory :: FilePath
extractedDirectory = "Packages/"
Expand All @@ -40,13 +44,17 @@ packageUrl :: Package -> String
packageUrl (Package (name,version)) = concat ["hackage.haskell.org/packages/archive/",name,"/",version,"/",name,"-",version,".tar.gz"]

main :: IO ()
main = shake shakeOptions {shakeThreads = 4} $ do
main = shakeArgs shakeOptions {shakeThreads = 10} $ do

action (do
PackageList packages <- apply1 ()
PackageList packages <- apply1 (GetPackageList ())
apply (map ExtractedPackage packages) :: Action [()])

rule (\() -> Just (return (PackageList [Package ("aeson-lens","0.1.0.2")])))
rule (\(GetPackageList ()) -> Just (do
need ["00-index.tar"]
hackage <- liftIO (readHackage' "00-index.tar")
let packages = [Package (name,show (disp version))| name <- M.keys hackage, version <- M.keys (hackage M.! name)]
return (PackageList (every 1 packages))))

rule (\(ExtractedPackage package) -> Just $ do
liftIO (IO.createDirectoryIfMissing True extractedDirectory)
Expand All @@ -55,12 +63,18 @@ main = shake shakeOptions {shakeThreads = 4} $ do

rule (\(PackageArchive package) -> Just $ do
liftIO (IO.createDirectoryIfMissing True (takeDirectory (archiveDirectory package)))
system' "wget" ["-O",archiveDirectory package,packageUrl package])
system' "wget" ["-nv","-O",archiveDirectory package,packageUrl package])

return ()
"00-index.tar" *> (\out -> do
system' "wget" ["-nv","hackage.haskell.org/packages/archive/00-index.tar.gz"]
system' "gunzip" ["-f","00-index.tar.gz"])

return ()


every :: Int -> [a] -> [a]
every nth [] = []
every nth xs = head xs : every nth (drop nth xs)



Expand Down

0 comments on commit 46158af

Please sign in to comment.