Skip to content
Newer
Older
100644 116 lines (109 sloc) 3.64 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
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
5 import Data.Maybe
cfd83a3 Introducing a local cache to speed things up
der_eq@freenet.de authored
6 import Data.List
e35e41e @kolmodin Make merging respect categories
kolmodin authored
7 import Data.Version
8 import Distribution.Package
9 import Distribution.PackageDescription
87d875b @kolmodin Wall police
kolmodin authored
10 (packageDescription, finalizePackageDescription, package)
e35e41e @kolmodin Make merging respect categories
kolmodin authored
11 import System.IO
f0097c0 Finalise the package description so we don't loos info
Duncan Coutts authored
12 import System.Info (os, arch)
e35e41e @kolmodin Make merging respect categories
kolmodin authored
13 import qualified Data.Map as Map
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
14 import Text.ParserCombinators.Parsec
263875a Less ugly debug method
der_eq@freenet.de authored
15
4cfa22e Changing program layout to a monadic state transformer
der_eq@freenet.de authored
16 import Action
5078263 @kolmodin Make diffing respect categories
kolmodin authored
17 import qualified Cabal2Ebuild as E
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
18 import Cache
980982a Adding support for different verbosity-levels
der_eq@freenet.de authored
19 import Config
03de0f6 Adding diff command to HackPort
der_eq@freenet.de authored
20 import Diff
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
21 import Error
22 import GenerateEbuild
63b57b8 Adapted HackPort to the new Hackage interface
der_eq@freenet.de authored
23 import Index
78d22a2 @kolmodin Rename overlayonly to status
kolmodin authored
24 import Status
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
25 import Package
47991e5 @kolmodin Add stub for supporting overlays defined in paludis
kolmodin authored
26 import Overlays
e35e41e @kolmodin Make merging respect categories
kolmodin authored
27 import P2
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
28
829ec47 Combine the list and query commands into one
Duncan Coutts authored
29 list :: String -> HPAction ()
30 list name = do
e35e41e @kolmodin Make merging respect categories
kolmodin authored
31 cache <- readCache =<< getOverlayPath
32 let pkgs | null name = [ pkg | (_,_,pkg) <- cache ]
33 | otherwise = searchIndex matchSubstringCaseInsensitive cache
34 where matchSubstringCaseInsensitive str _ver =
35 lcaseName `isInfixOf` lcase str
36 lcaseName = lcase name
37 lcase = map toLower
38 if null pkgs
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
39 then throwError (PackageNotFound name)
e35e41e @kolmodin Make merging respect categories
kolmodin authored
40 else liftIO . putStr . unlines
41 . map showPackageId
42 . sort
f0097c0 Finalise the package description so we don't loos info
Duncan Coutts authored
43 $ map (package.packageDescription) pkgs
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
44
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
45 merge :: String -> HPAction ()
46 merge pstr = do
47 (m_category, pname, m_version) <- case parsePVC of
48 Right v -> return v
49 Left err -> throwError (ArgumentError ("Could not parse [category/]package[-version]: " ++ show err))
e35e41e @kolmodin Make merging respect categories
kolmodin authored
50 portdir <- getOverlayPath
51 overlay <- liftIO $ readPortageTree portdir
52 cache <- readCache portdir
53 let (indexTree,clashes) = indexToPortage cache overlay
54 mapM_ (liftIO . putStrLn) clashes
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
55 whisper $ "Searching for: "++ pstr
56 let pkgs =
57 Map.elems
58 . Map.filterWithKey (\(P _ pname') _ -> map toLower pname' == map toLower pname)
59 $ indexTree
60 return ()
61 pkg <- case pkgs of
62 [] -> throwError (PackageNotFound pname)
63 [xs] -> case m_version of
64 Nothing -> return (maximum xs) -- highest version
65 Just v -> do
66 let ebuilds = filter (\e -> eVersion e == v) xs
67 case ebuilds of
68 [] -> throwError (PackageNotFound (pname ++ '-':show v))
69 [e] -> return e
87d875b @kolmodin Wall police
kolmodin authored
70 _ -> fail "the impossible happened"
71 _ -> fail "the impossible happened"
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
72 category <- do
73 case m_category of
74 Just cat -> return cat
75 Nothing -> do
76 case pCategory (ePackage pkg) of
77 "hackage" -> return "dev-haskell"
78 c -> return c
f0097c0 Finalise the package description so we don't loos info
Duncan Coutts authored
79 let Just genericDesc = ePkgDesc pkg
80 Right (desc, _) = finalizePackageDescription [] Nothing os arch
81 ("ghc", Version [6,8,2] []) genericDesc
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
82 ebuild <- fixSrc (package desc) (E.cabal2ebuild desc)
83 liftIO $ do
a40ff6e Fixed displaying error while merging
der_eq@freenet.de authored
84 putStrLn $ "Merging " ++ category ++ '/': pname ++ "-" ++ showVersion (pkgVersion (package desc))
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
85 putStrLn $ "Destination: " ++ portdir
86 mergeEbuild portdir category ebuild
87 where
88 parsePVC = parse readPVC "" pstr
89 readPVC = do
90 mc <- option Nothing $ try $ do
91 c <- readCat
92 char '/'
93 return (Just c)
94 (p, mv) <- readPkgAndVer
95 eof
96 return (mc, p, mv)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
97
4cfa22e Changing program layout to a monadic state transformer
der_eq@freenet.de authored
98 hpmain :: HPAction ()
99 hpmain = do
e35e41e @kolmodin Make merging respect categories
kolmodin authored
100 mode <- loadConfig
101 requestedUpdate <- fmap refreshCache getCfg
102 when requestedUpdate $
103 case mode of
104 Update -> return ()
105 _ -> updateCache
106 case mode of
107 ShowHelp -> liftIO hackageUsage
108 List pkg -> list pkg
109 Merge pkg -> merge pkg
87d875b @kolmodin Wall police
kolmodin authored
110 DiffTree dtmode -> diffAction dtmode
e35e41e @kolmodin Make merging respect categories
kolmodin authored
111 Update -> updateCache
78d22a2 @kolmodin Rename overlayonly to status
kolmodin authored
112 Status -> status
cfd83a3 Introducing a local cache to speed things up
der_eq@freenet.de authored
113
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
114 main :: IO ()
4cfa22e Changing program layout to a monadic state transformer
der_eq@freenet.de authored
115 main = performHPAction hpmain
Something went wrong with that request. Please try again.