Permalink
Browse files

Added support for overlay-guessing

  • Loading branch information...
1 parent 29a2daa commit 54702b5dfdc04334abbd705af0b84251e2567e52 der_eq@freenet.de committed Sep 21, 2005
Showing with 53 additions and 5 deletions.
  1. +36 −0 HackPort/Bash.hs
  2. +8 −0 HackPort/Error.hs
  3. +8 −4 HackPort/Main.hs
  4. +1 −1 HackPort/hackport.cabal
View
@@ -0,0 +1,36 @@
+module Bash where
+
+import Control.Exception
+import System.Process
+import System.Directory
+import System.IO
+import System.Exit
+import Error
+
+getOverlay :: IO String
+getOverlay = do
+ overlays <- getOverlays
+ case overlays of
+ [] -> throwDyn NoOverlay
+ [x] -> return x
+ mul -> throwDyn $ MultipleOverlays mul
+
+getOverlays :: IO [String]
+getOverlays = runBash "source /etc/make.conf;echo -n $PORTDIR_OVERLAY" >>= (return.words)
+
+runBash ::
+ String -> -- ^ The command line
+ IO String -- ^ The command-line's output
+runBash command = do
+ mpath <- findExecutable "bash"
+ bash <- maybe (throwDyn BashNotFound) return mpath
+ (inp,outp,err,pid) <- runInteractiveProcess bash ["-c",command] Nothing Nothing
+ hClose inp
+ result <- hGetContents outp
+ errors <- hGetContents err
+ length result `seq` hClose outp
+ length errors `seq` hClose err
+ exitCode <- waitForProcess pid
+ case exitCode of
+ ExitFailure err -> throwDyn $ BashError errors
+ ExitSuccess -> return result
View
@@ -16,6 +16,10 @@ data HackPortError
| NoCabalFound String
| ExtractionFailed String String Int
| CabalParseFailed String String
+ | BashNotFound
+ | BashError String
+ | NoOverlay
+ | MultipleOverlays [String]
deriving (Typeable)
type HackPortResult a = Either
@@ -33,3 +37,7 @@ hackPortShowError server package err = case err of
NoCabalFound tarball -> "Tarball '"++tarball++"' doesn't contain a cabal file"
ExtractionFailed tarball file code -> "Extracting '"++file++"' from '"++tarball++"' failed with '"++show code++"'"
CabalParseFailed file reason -> "Error while parsing cabal file '"++file++"': "++reason
+ BashNotFound -> "The 'bash' executable was not found. It is required to figure out your portage-overlay. If you don't want to install bash, use '-p path-to-overlay'"
+ BashError str -> "Error while guessing your portage-overlay. Either set PORTDIR_OVERLAY in /etc/make.conf or use '-p path-to-overlay'.\nThe error was: \""++str++"\""
+ MultipleOverlays overlays -> "You have the following overlays available: '"++unwords overlays++"'. Please choose one by using '-p path-to-overlay'"
+ NoOverlay -> "You don't have PORTDIR_OVERLAY set in '/etc/make.conf'. Please set it or use '-p path-to-overlay'"
View
@@ -11,6 +11,7 @@ import Error
import Query
import GenerateEbuild
import Cabal2Ebuild
+import Bash
data HackPortOptions
= TarCommand String
@@ -28,7 +29,7 @@ data OperationMode
data Config = Config
{ tarCommand ::String
- , portageTree ::String
+ , portageTree ::Maybe String
, portageCategory ::String
, server ::String
, tmp ::String
@@ -38,7 +39,7 @@ data Config = Config
defaultConfig :: Config
defaultConfig = Config
{ tarCommand = "/bin/tar"
- , portageTree = "/usr/portage"
+ , portageTree = Nothing
, portageCategory = "dev-haskell"
, server = "http://hackage.haskell.org/ModHackage/Hackage.hs?action=xmlrpc"
, tmp = "/tmp"
@@ -58,7 +59,7 @@ optionsToConfig :: Config -> [HackPortOptions] -> Config
optionsToConfig cfg [] = cfg
optionsToConfig cfg (x:xs) = optionsToConfig (case x of
TarCommand str -> cfg { tarCommand = str }
- PortageTree str -> cfg { portageTree = str }
+ PortageTree str -> cfg { portageTree = Just str }
Category str -> cfg { portageCategory = str }
Server str -> cfg { server = str }
TempDir str -> cfg { tmp = str }
@@ -90,11 +91,14 @@ query cfg name = do
merge :: Config -> String -> String -> IO ()
merge cfg name vers = do
+ portTree <- case portageTree cfg of
+ Nothing -> getOverlay
+ Just tree -> return tree
case parseVersion' vers of
Nothing -> putStr ("Error: couldn't parse version number '"++vers++"'\n")
Just realvers -> do
ebuild <- hackage2ebuild (tarCommand cfg) (server cfg) (tmp cfg) (verify cfg) (PackageIdentifier {pkgName=name,pkgVersion=realvers})
- mergeEbuild (portageTree cfg) (portageCategory cfg) ebuild
+ mergeEbuild portTree (portageCategory cfg) ebuild
main :: IO ()
main = do
@@ -2,7 +2,7 @@ Name: HackPort
Version: 0.1
License: GPL
Author: Henning Günther
-Build-Depends: base, network, HTTP, Cabal, hackage-client
+Build-Depends: base, network, HTTP, Cabal, hackage-client, GnuPG
Synopsis: Hackage and Portage integration tool
Executable: hackport

0 comments on commit 54702b5

Please sign in to comment.