Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 137 lines (128 sloc) 4.731 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
ffabce4 Update to Cabal-1.4 api
Duncan Coutts authored
9 import Distribution.Compiler (CompilerId(..), CompilerFlavor(GHC))
10 import Distribution.PackageDescription.Configuration
11 ( finalizePackageDescription, flattenPackageDescription )
12 import Distribution.Simple.PackageIndex (PackageIndex)
13 import Distribution.Text (display)
e35e41e @kolmodin Make merging respect categories
kolmodin authored
14 import System.IO
ffabce4 Update to Cabal-1.4 api
Duncan Coutts authored
15 import Distribution.System (buildOS, buildArch)
e35e41e @kolmodin Make merging respect categories
kolmodin authored
16 import qualified Data.Map as Map
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
17 import Text.ParserCombinators.Parsec
263875a Less ugly debug method
der_eq@freenet.de authored
18
4cfa22e Changing program layout to a monadic state transformer
der_eq@freenet.de authored
19 import Action
5078263 @kolmodin Make diffing respect categories
kolmodin authored
20 import qualified Cabal2Ebuild as E
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
21 import Cache
980982a Adding support for different verbosity-levels
der_eq@freenet.de authored
22 import Config
03de0f6 Adding diff command to HackPort
der_eq@freenet.de authored
23 import Diff
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
24 import Error
25 import GenerateEbuild
63b57b8 Adapted HackPort to the new Hackage interface
der_eq@freenet.de authored
26 import Index
78d22a2 @kolmodin Rename overlayonly to status
kolmodin authored
27 import Status
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
28 import Package
47991e5 @kolmodin Add stub for supporting overlays defined in paludis
kolmodin authored
29 import Overlays
e35e41e @kolmodin Make merging respect categories
kolmodin authored
30 import P2
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
31
32a344c @trofi hackport-cabal2ebuild.patch
trofi authored
32 import qualified Distribution.PackageDescription as Cabal
33 import Distribution.Verbosity (normal)
34 import Cabal2Ebuild
35
829ec47 Combine the list and query commands into one
Duncan Coutts authored
36 list :: String -> HPAction ()
37 list name = do
66099b9 @kolmodin Make 'hackport list' 40x faster
kolmodin authored
38 index <- readCache =<< getOverlayPath
39 let index' | null name = index
40 | otherwise = filterIndexByPV matchSubstringCaseInsensitive index
41c22ea @kolmodin -Wall police
kolmodin authored
41 pkgs = [ pkg ++ "-" ++ ver | (pkg,ver,_) <- index']
e35e41e @kolmodin Make merging respect categories
kolmodin authored
42 if null pkgs
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
43 then throwError (PackageNotFound name)
66099b9 @kolmodin Make 'hackport list' 40x faster
kolmodin authored
44 else liftIO . putStr . unlines . sort $ pkgs
45 where
46 matchSubstringCaseInsensitive pName _pVver =
47 map toLower name `isInfixOf` map toLower pName
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
48
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
49 merge :: String -> HPAction ()
50 merge pstr = do
51 (m_category, pname, m_version) <- case parsePVC of
52 Right v -> return v
53 Left err -> throwError (ArgumentError ("Could not parse [category/]package[-version]: " ++ show err))
e35e41e @kolmodin Make merging respect categories
kolmodin authored
54 portdir <- getOverlayPath
55 overlay <- liftIO $ readPortageTree portdir
56 cache <- readCache portdir
57 let (indexTree,clashes) = indexToPortage cache overlay
58 mapM_ (liftIO . putStrLn) clashes
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
59 whisper $ "Searching for: "++ pstr
60 let pkgs =
61 Map.elems
62 . Map.filterWithKey (\(P _ pname') _ -> map toLower pname' == map toLower pname)
63 $ indexTree
64 return ()
65 pkg <- case pkgs of
66 [] -> throwError (PackageNotFound pname)
67 [xs] -> case m_version of
68 Nothing -> return (maximum xs) -- highest version
69 Just v -> do
70 let ebuilds = filter (\e -> eVersion e == v) xs
71 case ebuilds of
72 [] -> throwError (PackageNotFound (pname ++ '-':show v))
73 [e] -> return e
87d875b @kolmodin Wall police
kolmodin authored
74 _ -> fail "the impossible happened"
75 _ -> fail "the impossible happened"
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
76 category <- do
77 case m_category of
78 Just cat -> return cat
79 Nothing -> do
80 case pCategory (ePackage pkg) of
81 "hackage" -> return "dev-haskell"
82 c -> return c
f0097c0 Finalise the package description so we don't loos info
Duncan Coutts authored
83 let Just genericDesc = ePkgDesc pkg
ffabce4 Update to Cabal-1.4 api
Duncan Coutts authored
84 Right (desc, _) = finalizePackageDescription []
85 (Nothing :: Maybe (PackageIndex PackageIdentifier))
86 buildOS buildArch
87 (CompilerId GHC (Version [6,8,2] []))
88 [] genericDesc
89 ebuild <- fixSrc (packageId desc) (E.cabal2ebuild desc)
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
90 liftIO $ do
ffabce4 Update to Cabal-1.4 api
Duncan Coutts authored
91 putStrLn $ "Merging " ++ category ++ '/': pname ++ "-" ++ display (pkgVersion (packageId desc))
7d1091e @kolmodin Change parameter to merge and remove --portage-category
kolmodin authored
92 putStrLn $ "Destination: " ++ portdir
93 mergeEbuild portdir category ebuild
94 where
95 parsePVC = parse readPVC "" pstr
96 readPVC = do
97 mc <- option Nothing $ try $ do
98 c <- readCat
99 char '/'
100 return (Just c)
101 (p, mv) <- readPkgAndVer
102 eof
103 return (mc, p, mv)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
104
32a344c @trofi hackport-cabal2ebuild.patch
trofi authored
105 makeEbuild :: String -> HPAction ()
106 makeEbuild cabalFileName = liftIO $ do
107 pkg <- Cabal.readPackageDescription normal cabalFileName
ffabce4 Update to Cabal-1.4 api
Duncan Coutts authored
108 let ebuild = cabal2ebuild (flattenPackageDescription pkg)
32a344c @trofi hackport-cabal2ebuild.patch
trofi authored
109 let ebuildFileName = name ebuild ++ "-" ++ version ebuild ++ ".ebuild"
110 writeFile ebuildFileName (showEBuild ebuild)
111
4cfa22e Changing program layout to a monadic state transformer
der_eq@freenet.de authored
112 hpmain :: HPAction ()
113 hpmain = do
e35e41e @kolmodin Make merging respect categories
kolmodin authored
114 mode <- loadConfig
115 requestedUpdate <- fmap refreshCache getCfg
116 when requestedUpdate $
117 case mode of
118 Update -> return ()
119 _ -> updateCache
120 case mode of
121 ShowHelp -> liftIO hackageUsage
122 List pkg -> list pkg
123 Merge pkg -> merge pkg
87d875b @kolmodin Wall police
kolmodin authored
124 DiffTree dtmode -> diffAction dtmode
e35e41e @kolmodin Make merging respect categories
kolmodin authored
125 Update -> updateCache
b701c1f @kolmodin Add feature 'status toportage'
kolmodin authored
126 Status action -> statusAction action
32a344c @trofi hackport-cabal2ebuild.patch
trofi authored
127 MakeEbuild cabalFileName -> makeEbuild cabalFileName
cfd83a3 Introducing a local cache to speed things up
der_eq@freenet.de authored
128
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
129 main :: IO ()
fd1cadd @kolmodin Allow caller to handle errors
kolmodin authored
130 main = do
131 res <- performHPAction hpmain
132 case res of
133 Right _ -> return ()
134 Left err -> do
135 hPutStrLn stderr "An error occurred. To get more info run with --verbosity=debug"
136 hPutStrLn stderr (hackPortShowError err)
Something went wrong with that request. Please try again.