Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 83 lines (75 sloc) 2.595 kb
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
1 module Main where
2
4cfa22e Changing program layout to a monadic state transformer
der_eq@freenet.de authored
3 import Control.Monad.Error
03de0f6 Adding diff command to HackPort
der_eq@freenet.de authored
4 import Data.Char
cfd83a3 Introducing a local cache to speed things up
der_eq@freenet.de authored
5 import Data.List
e35e41e @kolmodin Make merging respect categories
kolmodin authored
6 import Data.Version
7 import Distribution.Package
8 import Distribution.PackageDescription
9 import System.IO
10 import qualified Data.Map as Map
263875a Less ugly debug method
der_eq@freenet.de authored
11
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
12
4cfa22e Changing program layout to a monadic state transformer
der_eq@freenet.de authored
13 import Action
5078263 @kolmodin Make diffing respect categories
kolmodin authored
14 import qualified Cabal2Ebuild as E
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
15 import Cache
980982a Adding support for different verbosity-levels
der_eq@freenet.de authored
16 import Config
03de0f6 Adding diff command to HackPort
der_eq@freenet.de authored
17 import Diff
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
18 import Error
19 import GenerateEbuild
63b57b8 Adapted HackPort to the new Hackage interface
der_eq@freenet.de authored
20 import Index
78d22a2 @kolmodin Rename overlayonly to status
kolmodin authored
21 import Status
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
22 import Portage
e35e41e @kolmodin Make merging respect categories
kolmodin authored
23 import P2
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
24
829ec47 Combine the list and query commands into one
Duncan Coutts authored
25 list :: String -> HPAction ()
26 list name = do
e35e41e @kolmodin Make merging respect categories
kolmodin authored
27 cache <- readCache =<< getOverlayPath
28 let pkgs | null name = [ pkg | (_,_,pkg) <- cache ]
29 | otherwise = searchIndex matchSubstringCaseInsensitive cache
30 where matchSubstringCaseInsensitive str _ver =
31 lcaseName `isInfixOf` lcase str
32 lcaseName = lcase name
33 lcase = map toLower
34 if null pkgs
35 then throwError (PackageNotFound (Left name))
36 else liftIO . putStr . unlines
37 . map showPackageId
38 . sort
39 $ map package pkgs
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
40
4cfa22e Changing program layout to a monadic state transformer
der_eq@freenet.de authored
41 merge :: PackageIdentifier -> HPAction ()
42 merge pid = do
e35e41e @kolmodin Make merging respect categories
kolmodin authored
43 portdir <- getOverlayPath
44 overlay <- liftIO $ readPortageTree portdir
45 cache <- readCache portdir
46 let (indexTree,clashes) = indexToPortage cache overlay
47 mapM_ (liftIO . putStrLn) clashes
48 whisper $ "Searching for: "++pkgName pid++"-"++showVersion (pkgVersion pid)
49 let pkgs = searchIndex (\name vers -> map toLower name == map toLower (pkgName pid) && vers == showVersion (pkgVersion pid)) cache
50 case pkgs of
51 [] -> throwError (PackageNotFound (Right pid))
52 [pkg] -> do
53 let categories = [ c | P c p <- (Map.keys indexTree), p == pkgName pid]
54 category <- do
55 dpc <- fmap defaultPortageCategory getCfg
56 case categories of
57 ["hackage"] -> return dpc
58 [c] -> return c
59 ebuild <- fixSrc pid (E.cabal2ebuild pkg)
60 liftIO $ do
61 putStrLn $ "Merging " ++ category ++ '/': pkgName pid ++ '-': showVersion (pkgVersion pid)
62 putStrLn $ "Destination: " ++ portdir
63 mergeEbuild portdir category ebuild
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
64
4cfa22e Changing program layout to a monadic state transformer
der_eq@freenet.de authored
65 hpmain :: HPAction ()
66 hpmain = do
e35e41e @kolmodin Make merging respect categories
kolmodin authored
67 mode <- loadConfig
68 requestedUpdate <- fmap refreshCache getCfg
69 when requestedUpdate $
70 case mode of
71 Update -> return ()
72 _ -> updateCache
73 case mode of
74 ShowHelp -> liftIO hackageUsage
75 List pkg -> list pkg
76 Merge pkg -> merge pkg
77 DiffTree mode -> diffAction mode
78 Update -> updateCache
78d22a2 @kolmodin Rename overlayonly to status
kolmodin authored
79 Status -> status
cfd83a3 Introducing a local cache to speed things up
der_eq@freenet.de authored
80
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
81 main :: IO ()
4cfa22e Changing program layout to a monadic state transformer
der_eq@freenet.de authored
82 main = performHPAction hpmain
Something went wrong with that request. Please try again.