List installed packages from a repository
All checks were successful
Build / audit (push) Successful in 9s
Build / test (push) Successful in 16m24s

This commit is contained in:
2024-11-25 17:08:28 +01:00
parent b5e6e3a2d6
commit 468852410e
7 changed files with 103 additions and 38 deletions

View File

@@ -7,6 +7,7 @@ module SlackBuilder.Info
( PackageInfo(..)
, generate
, parseInfoFile
, readInfoFile
) where
import Control.Applicative (Alternative(..))
@@ -26,7 +27,7 @@ import Crypto.Hash (Digest, MD5, digestFromByteString)
import Data.Void (Void)
import Data.Word (Word8)
import Numeric (readHex, showHex)
import Text.Megaparsec (Parsec, count, eof, takeWhile1P)
import Text.Megaparsec (Parsec, count, eof, parse, takeWhile1P)
import Text.Megaparsec.Byte (space, string, hexDigitChar)
import Text.URI
( URI(..)
@@ -34,6 +35,14 @@ import Text.URI
, render
)
import qualified Data.Word8 as Word8
import SlackBuilder.Trans
( SlackBuilderT(..)
, SlackBuilderException(..)
, relativeToRepository
)
import System.FilePath ((</>), (<.>))
import Control.Monad.IO.Class (MonadIO(..))
import Conduit (MonadThrow(throwM))
type GenParser = Parsec Void ByteString
@@ -110,6 +119,17 @@ parseInfoFile = PackageInfo . Char8.unpack
*> packageName
<* "\"\n"
readInfoFile :: Text -> Text -> SlackBuilderT PackageInfo
readInfoFile category packageName' = do
let packageName'' = Text.unpack packageName'
infoPath <- relativeToRepository
$ Text.unpack category </> packageName'' </> packageName'' <.> "info"
infoContents <- liftIO $ ByteString.readFile infoPath
either (throwM . MalformedInfoFile) pure
$ parse parseInfoFile infoPath infoContents
generate :: PackageInfo -> Text
generate pkg = Lazy.Text.toStrict $ Text.Builder.toLazyText builder
where