Skip to content

Commit

Permalink
Wall police
Browse files Browse the repository at this point in the history
  • Loading branch information
kolmodin committed Mar 15, 2008
1 parent f5d6f88 commit 87d875b
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 74 deletions.
6 changes: 5 additions & 1 deletion AnsiColor.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
module AnsiColor module AnsiColor
where where


-- import Portage.Config.Type
import Data.List import Data.List


data Color = Black data Color = Black
Expand All @@ -23,20 +22,25 @@ data Color = Black
| Default | Default
deriving Enum deriving Enum


esc :: [String] -> String
esc [] = "" esc [] = ""
esc xs = "\ESC[" ++ (concat . intersperse ";" $ xs) ++ "m" esc xs = "\ESC[" ++ (concat . intersperse ";" $ xs) ++ "m"


col :: Color -> Bool -> Color -> [String]
col fg bf bg = show (fromEnum fg + 30) : bf' [show (fromEnum bg + 40)] col fg bf bg = show (fromEnum fg + 30) : bf' [show (fromEnum bg + 40)]
where bf' | bf = ("01" :) where bf' | bf = ("01" :)
| otherwise = id | otherwise = id


inColor :: Color -> Bool -> Color -> String -> String
inColor c bf bg txt = esc (col c bf bg) ++ txt ++ esc ["00"] inColor c bf bg txt = esc (col c bf bg) ++ txt ++ esc ["00"]


bold, italic, underline, inverse :: String -> String
bold = ansi "1" "22" bold = ansi "1" "22"
italic = ansi "3" "23" italic = ansi "3" "23"
underline = ansi "4" "24" underline = ansi "4" "24"
inverse = ansi "7" "27" inverse = ansi "7" "27"


ansi :: String -> String -> String -> String
ansi on off txt = esc [on] ++ txt ++ esc [off] ansi on off txt = esc [on] ++ txt ++ esc [off]


{- {-
Expand Down
5 changes: 2 additions & 3 deletions Bash.hs
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,5 @@
module Bash where module Bash where


import Control.Monad.Trans
import Control.Monad.Error import Control.Monad.Error
import System.Process import System.Process
import System.Directory import System.Directory
Expand Down Expand Up @@ -71,5 +70,5 @@ runBash command = do
length errors `seq` liftIO (hClose err) length errors `seq` liftIO (hClose err)
exitCode <- liftIO $ waitForProcess pid exitCode <- liftIO $ waitForProcess pid
case exitCode of case exitCode of
ExitFailure err -> throwError $ BashError errors ExitFailure _ -> throwError $ BashError errors
ExitSuccess -> return result ExitSuccess -> return result
5 changes: 3 additions & 2 deletions BlingBling.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import System.IO
-- what nobody needs but everyone wants... -- what nobody needs but everyone wants...


-- FIXME: do something more fun here -- FIXME: do something more fun here
forMbling :: [a] -> (a -> IO b) -> IO [b]
forMbling lst f = do forMbling lst f = do
init <- hGetBuffering stdout origBuffering <- hGetBuffering stdout
hSetBuffering stdout NoBuffering hSetBuffering stdout NoBuffering
xs <- mapM (\x -> putStr "." >> f x) lst xs <- mapM (\x -> putStr "." >> f x) lst
putStrLn "" putStrLn ""
hSetBuffering stdout init hSetBuffering stdout origBuffering
return xs return xs
58 changes: 34 additions & 24 deletions Cabal2Ebuild.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ module Cabal2Ebuild
,showEBuild) where ,showEBuild) where


import qualified Distribution.PackageDescription as Cabal import qualified Distribution.PackageDescription as Cabal
(PackageDescription(..), (PackageDescription(..))
readPackageDescription)
import qualified Distribution.Package as Cabal (PackageIdentifier(..)) import qualified Distribution.Package as Cabal (PackageIdentifier(..))
import qualified Distribution.Version as Cabal (showVersion, Dependency(..), import qualified Distribution.Version as Cabal (showVersion, Dependency(..),
VersionRange(..)) VersionRange(..))
import qualified Distribution.License as Cabal (License(..)) import qualified Distribution.License as Cabal (License(..))
--import qualified Distribution.Compiler as Cabal (CompilerFlavor(..)) --import qualified Distribution.Compiler as Cabal (CompilerFlavor(..))


import Data.Char (toLower,isUpper) import Data.Char (toLower,isUpper)
import Data.Maybe (catMaybes)
import Text.Regex


data EBuild = EBuild { data EBuild = EBuild {
name :: String, name :: String,
Expand Down Expand Up @@ -68,6 +65,7 @@ data Dependency = AnyVersionOf Package
| DependEither Dependency Dependency -- depend || depend | DependEither Dependency Dependency -- depend || depend
| DependIfUse UseFlag Dependency -- use? ( depend ) | DependIfUse UseFlag Dependency -- use? ( depend )


ebuildTemplate :: EBuild
ebuildTemplate = EBuild { ebuildTemplate = EBuild {
name = "foobar", name = "foobar",
version = "0.1", version = "0.1",
Expand Down Expand Up @@ -105,6 +103,7 @@ cabal2ebuild pkg = ebuildTemplate {
} where } where
cabalPkgName = Cabal.pkgName (Cabal.package pkg) cabalPkgName = Cabal.pkgName (Cabal.package pkg)


defaultDepGHC :: Dependency
defaultDepGHC = OrLaterVersionOf "6.6.1" "dev-lang/ghc" defaultDepGHC = OrLaterVersionOf "6.6.1" "dev-lang/ghc"


-- map the cabal license type to the gentoo license string format -- map the cabal license type to the gentoo license string format
Expand All @@ -117,6 +116,7 @@ convertLicense Cabal.PublicDomain = "public-domain"
convertLicense Cabal.AllRightsReserved = "" convertLicense Cabal.AllRightsReserved = ""
convertLicense _ = "" convertLicense _ = ""


licenseComment :: Cabal.License -> String
licenseComment Cabal.AllRightsReserved = licenseComment Cabal.AllRightsReserved =
"Note: packages without a license cannot be included in portage" "Note: packages without a license cannot be included in portage"
licenseComment Cabal.OtherLicense = licenseComment Cabal.OtherLicense =
Expand All @@ -127,15 +127,15 @@ convertDependencies :: [Cabal.Dependency] -> [Dependency]
convertDependencies = concatMap convertDependency convertDependencies = concatMap convertDependency


convertDependency :: Cabal.Dependency -> [Dependency] convertDependency :: Cabal.Dependency -> [Dependency]
convertDependency (Cabal.Dependency name _) convertDependency (Cabal.Dependency pname _)
| name `elem` coreLibs = [] -- no explicit dep on core libs | pname `elem` coreLibs = [] -- no explicit dep on core libs
convertDependency (Cabal.Dependency name versionRange) convertDependency (Cabal.Dependency pname versionRange)
= case versionRange of = case versionRange of
(Cabal.IntersectVersionRanges v1 v2) -> [convert v1, convert v2] (Cabal.IntersectVersionRanges v1 v2) -> [convert v1, convert v2]
v -> [convert v] v -> [convert v]


where where
ebuildName = "dev-haskell/" ++ map toLower name ebuildName = "dev-haskell/" ++ map toLower pname


convert :: Cabal.VersionRange -> Dependency convert :: Cabal.VersionRange -> Dependency
convert Cabal.AnyVersion = AnyVersionOf ebuildName convert Cabal.AnyVersion = AnyVersionOf ebuildName
Expand All @@ -149,6 +149,7 @@ convertDependency (Cabal.Dependency name versionRange)
convert (Cabal.UnionVersionRanges r1 r2) convert (Cabal.UnionVersionRanges r1 r2)
= DependEither (convert r1) (convert r2) = DependEither (convert r1) (convert r2)


coreLibs :: [String]
coreLibs = coreLibs =
["array" ["array"
,"base" ,"base"
Expand Down Expand Up @@ -200,32 +201,41 @@ showEBuild ebuild =
ss "DEPEND=". quote' (sepBy "\n\t\t" $ map showDepend $ depend ebuild). nl. ss "DEPEND=". quote' (sepBy "\n\t\t" $ map showDepend $ depend ebuild). nl.
(case my_pn ebuild of (case my_pn ebuild of
Nothing -> id Nothing -> id
Just pn -> nl. ss "S=". quote ("${WORKDIR}/${MY_P}"). nl) Just _ -> nl. ss "S=". quote ("${WORKDIR}/${MY_P}"). nl)
$ [] $ []
where replaceVars = replaceCommonVars (name ebuild) (my_pn ebuild) (version ebuild) where replaceVars = replaceCommonVars (name ebuild) (my_pn ebuild) (version ebuild)


showDepend (AnyVersionOf package) = package showDepend :: Dependency -> Package
showDepend (ThisVersionOf version package) = "~" ++ package ++ "-" ++ version showDepend (AnyVersionOf p) = p
showDepend (LaterVersionOf version package) = ">" ++ package ++ "-" ++ version showDepend (ThisVersionOf v p) = "~" ++ p ++ "-" ++ v
showDepend (EarlierVersionOf version package) = "<" ++ package ++ "-" ++ version showDepend (LaterVersionOf v p) = ">" ++ p ++ "-" ++ v
showDepend (OrLaterVersionOf version package) = ">=" ++ package ++ "-" ++ version showDepend (EarlierVersionOf v p) = "<" ++ p ++ "-" ++ v
showDepend (OrEarlierVersionOf version package) = "<=" ++ package ++ "-" ++ version showDepend (OrLaterVersionOf v p) = ">=" ++ p ++ "-" ++ v
showDepend (DependEither depend1 depend2) = showDepend depend1 showDepend (OrEarlierVersionOf v p) = "<=" ++ p ++ "-" ++ v
++ " || " ++ showDepend depend2 showDepend (DependEither dep1 dep2) = showDepend dep1
showDepend (DependIfUse useflag depend@(DependEither _ _)) ++ " || " ++ showDepend dep2
= useflag ++ "? " ++ showDepend depend showDepend (DependIfUse useflag dep@(DependEither _ _))
showDepend (DependIfUse useflag depend) = useflag ++ "? ( " ++ showDepend depend ++ " )" = useflag ++ "? " ++ showDepend dep
showDepend (DependIfUse useflag dep) = useflag ++ "? ( " ++ showDepend dep++ " )"


ss :: String -> String -> String
ss = showString ss = showString

sc :: Char -> String -> String
sc = showChar sc = showChar

nl :: String -> String
nl = sc '\n' nl = sc '\n'


quote :: String -> String -> String
quote str = sc '"'. ss str. sc '"' quote str = sc '"'. ss str. sc '"'

quote' :: (String -> String) -> String -> String
quote' str = sc '"'. str. sc '"' quote' str = sc '"'. str. sc '"'


sepBy :: String -> [String] -> ShowS sepBy :: String -> [String] -> ShowS
sepBy s [] = id sepBy _ [] = id
sepBy s [x] = ss x sepBy _ [x] = ss x
sepBy s (x:xs) = ss x. ss s. sepBy s xs sepBy s (x:xs) = ss x. ss s. sepBy s xs


getRestIfPrefix :: getRestIfPrefix ::
Expand All @@ -251,9 +261,9 @@ replaceMultiVars ::
String -> -- ^ string to be searched String -> -- ^ string to be searched
String -- ^ the result String -- ^ the result
replaceMultiVars [] str = str replaceMultiVars [] str = str
replaceMultiVars whole@((name,cont):rest) str = case subStr cont str of replaceMultiVars whole@((pname,cont):rest) str = case subStr cont str of
Nothing -> replaceMultiVars rest str Nothing -> replaceMultiVars rest str
Just (pre,post) -> (replaceMultiVars rest pre)++name++(replaceMultiVars whole post) Just (pre,post) -> (replaceMultiVars rest pre)++pname++(replaceMultiVars whole post)


replaceCommonVars :: replaceCommonVars ::
String -> -- ^ PN String -> -- ^ PN
Expand Down
4 changes: 2 additions & 2 deletions Cache.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import Version
import Control.Arrow import Control.Arrow
import Data.Char import Data.Char
import Data.List import Data.List
import Network.URI import Network.URI (URI, uriPath)
import Network.HTTP import Network.HTTP (Request(..), RequestMethod(GET), simpleHTTP, rspBody)
import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy as L
import System.Time import System.Time
import System.FilePath import System.FilePath
Expand Down
15 changes: 5 additions & 10 deletions Config.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ module Config where


import Network.URI import Network.URI
import System.Console.GetOpt import System.Console.GetOpt
import Control.Exception
import Text.Regex import Text.Regex
import Distribution.Package

import Error
import MaybeRead


data HackPortOptions data HackPortOptions
= OverlayPath String = OverlayPath String
| PortagePath String | PortagePath String
| Category String
| Server String | Server String
| TempDir String | TempDir String
| Verbosity String | Verbosity String
Expand Down Expand Up @@ -49,6 +43,7 @@ data Verbosity
| Normal | Normal
| Silent | Silent


packageRegex :: Regex
packageRegex = mkRegex "^(.*?)-([0-9].*)$" packageRegex = mkRegex "^(.*?)-([0-9].*)$"


defaultConfig :: Config defaultConfig :: Config
Expand Down Expand Up @@ -91,17 +86,17 @@ parseConfig opts = let
"diff":"additions":[] -> Right (DiffTree ShowAdditions) "diff":"additions":[] -> Right (DiffTree ShowAdditions)
"diff":"newer":[] -> Right (DiffTree ShowNewer) "diff":"newer":[] -> Right (DiffTree ShowNewer)
"diff":"common":[] -> Right (DiffTree ShowCommon) "diff":"common":[] -> Right (DiffTree ShowCommon)
"diff":arg:[] -> Left ("Unknown argument to 'diff': Use all,missing,additions,newer or common.\n") "diff":arg:[] -> Left ("Unknown argument to diff: '" ++ arg ++ "'. Use all,missing,additions,newer or common.\n")
"diff":arg1:args -> Left ("'diff' takes one argument("++show ((length args)+1)++" given).\n") "diff":_:xs -> Left ("'diff' takes one argument("++show ((length xs)+1)++" given).\n")
"update":[] -> Right Update "update":[] -> Right Update
"update":rest -> Left ("'update' takes zero arguments("++show (length rest)++" given).\n") "update":rest -> Left ("'update' takes zero arguments("++show (length rest)++" given).\n")
"status":[] -> Right Status "status":[] -> Right Status
"status":args -> Left ("'status' doesn't take any arguments. ("++show ((length args)+1)++" given).\n") "status":xs-> Left ("'status' doesn't take any arguments. ("++show ((length xs)+1)++" given).\n")
[] -> Right ShowHelp [] -> Right ShowHelp
_ -> Left "Unknown opertation mode\n" _ -> Left "Unknown opertation mode\n"
in case mode of in case mode of
Left err -> Left err Left err -> Left err
Right mod -> Right (popts,mod) Right m -> Right (popts,m)


hackageUsage :: IO () hackageUsage :: IO ()
hackageUsage = putStr $ flip usageInfo hackageOptions $ unlines hackageUsage = putStr $ flip usageInfo hackageOptions $ unlines
Expand Down
4 changes: 1 addition & 3 deletions Diff.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ module Diff
( diffAction ( diffAction
) where ) where


import Data.Set as Set (Set)
import qualified Data.Set as Set
import qualified Data.Map as Map import qualified Data.Map as Map


import Control.Monad.Trans import Control.Monad.Trans
import Data.Char import Data.Char


import Action import Action
import Cache import Cache
import Config import Config (DiffMode(..))
import P2 import P2
import Portage import Portage
import Version import Version
Expand Down
5 changes: 2 additions & 3 deletions Error.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
module Error where module Error where


import Data.Typeable import Data.Typeable
import Distribution.Package import Control.Monad.Error (Error)
import Control.Monad.Error
import Control.Exception


data HackPortError data HackPortError
= ArgumentError String = ArgumentError String
Expand Down Expand Up @@ -52,5 +50,6 @@ hackPortShowError err = case err of
MultipleOverlays overlays -> "You have the following overlays available: '"++unwords overlays++"'. Please choose one by using '-p path-to-overlay'" 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'" NoOverlay -> "You don't have PORTDIR_OVERLAY set in '/etc/make.conf'. Please set it or use '-p path-to-overlay'"
UnknownVerbosityLevel str -> "The verbosity level '"++str++"' is invalid. Please use debug,normal or silent" UnknownVerbosityLevel str -> "The verbosity level '"++str++"' is invalid. Please use debug,normal or silent"
InvalidServer srv -> "Invalid server address, could not parse: " ++ srv
--WrongCacheVersion -> "The version of the cache is too old. Please update the cache using 'hackport update'" --WrongCacheVersion -> "The version of the cache is too old. Please update the cache using 'hackport update'"
--InvalidCache -> "Could not read the cache. Please ensure that it's up to date using 'hackport update'" --InvalidCache -> "Could not read the cache. Please ensure that it's up to date using 'hackport update'"
6 changes: 0 additions & 6 deletions GenerateEbuild.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ module GenerateEbuild where


import Action import Action
import Cabal2Ebuild import Cabal2Ebuild
--import Fetch
--import TarUtils
import Config import Config
import Error


import Prelude hiding (catch) import Prelude hiding (catch)
import Control.Monad.Trans
import Control.Monad.Error import Control.Monad.Error
import Control.Exception
import Distribution.PackageDescription
import Distribution.Package import Distribution.Package
import Data.Version (showVersion) import Data.Version (showVersion)
import Network.URI import Network.URI
Expand Down
2 changes: 1 addition & 1 deletion Index.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ readIndex str = do
case splitDirectories (tarFileName (entryHeader entr)) of case splitDirectories (tarFileName (entryHeader entr)) of
[".",pkgname,vers,file] -> do [".",pkgname,vers,file] -> do
let descr = case parsePackageDescription (unpack (entryData entr)) of let descr = case parsePackageDescription (unpack (entryData entr)) of
ParseOk _ descr -> descr ParseOk _ pkg_desc -> pkg_desc
_ -> error $ "Couldn't read cabal file "++show file _ -> error $ "Couldn't read cabal file "++show file
return (pkgname,vers,descr) return (pkgname,vers,descr)
_ -> fail "doesn't look like the proper path" _ -> fail "doesn't look like the proper path"
Expand Down
7 changes: 4 additions & 3 deletions Main.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import Data.List
import Data.Version import Data.Version
import Distribution.Package import Distribution.Package
import Distribution.PackageDescription import Distribution.PackageDescription
(packageDescription, finalizePackageDescription, package)
import System.IO import System.IO
import System.Info (os, arch) import System.Info (os, arch)
import qualified Data.Map as Map import qualified Data.Map as Map
import Text.ParserCombinators.Parsec import Text.ParserCombinators.Parsec



import Action import Action
import qualified Cabal2Ebuild as E import qualified Cabal2Ebuild as E
import Cache import Cache
Expand All @@ -25,7 +25,6 @@ import Status
import Package import Package
import Portage import Portage
import P2 import P2
import Utils


list :: String -> HPAction () list :: String -> HPAction ()
list name = do list name = do
Expand Down Expand Up @@ -68,6 +67,8 @@ merge pstr = do
case ebuilds of case ebuilds of
[] -> throwError (PackageNotFound (pname ++ '-':show v)) [] -> throwError (PackageNotFound (pname ++ '-':show v))
[e] -> return e [e] -> return e
_ -> fail "the impossible happened"
_ -> fail "the impossible happened"
category <- do category <- do
case m_category of case m_category of
Just cat -> return cat Just cat -> return cat
Expand Down Expand Up @@ -106,7 +107,7 @@ hpmain = do
ShowHelp -> liftIO hackageUsage ShowHelp -> liftIO hackageUsage
List pkg -> list pkg List pkg -> list pkg
Merge pkg -> merge pkg Merge pkg -> merge pkg
DiffTree mode -> diffAction mode DiffTree dtmode -> diffAction dtmode
Update -> updateCache Update -> updateCache
Status -> status Status -> status


Expand Down
2 changes: 0 additions & 2 deletions P2.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Data.Map (Map)
import qualified Data.Map as Map import qualified Data.Map as Map
import Data.Maybe import Data.Maybe
import qualified Data.List as List import qualified Data.List as List
import Data.Monoid


import System.Directory import System.Directory
import System.IO import System.IO
Expand All @@ -24,7 +23,6 @@ import System.FilePath
import Text.Regex import Text.Regex


import Version import Version
import Utils


type Portage = PortageMap [Ebuild] type Portage = PortageMap [Ebuild]
type PortageMap a = Map Package a type PortageMap a = Map Package a
Expand Down
Loading

0 comments on commit 87d875b

Please sign in to comment.