summaryrefslogtreecommitdiff
path: root/lib/SlackBuilder
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-11-25 17:08:28 +0100
committerEugen Wissner <belka@caraus.de>2024-11-25 17:08:28 +0100
commit468852410e3881910d803192f13ed13f19a7af41 (patch)
treef44f6f06a0d1883ab64a07f440dcef6b773da29f /lib/SlackBuilder
parentb5e6e3a2d68111cc7f84d939dc7b82ff2aac1801 (diff)
downloadslackbuilder-468852410e3881910d803192f13ed13f19a7af41.tar.gz
List installed packages from a repository
Diffstat (limited to 'lib/SlackBuilder')
-rw-r--r--lib/SlackBuilder/Info.hs22
-rw-r--r--lib/SlackBuilder/Package.hs15
-rw-r--r--lib/SlackBuilder/Trans.hs6
3 files changed, 41 insertions, 2 deletions
diff --git a/lib/SlackBuilder/Info.hs b/lib/SlackBuilder/Info.hs
index e2f5018..59342cc 100644
--- a/lib/SlackBuilder/Info.hs
+++ b/lib/SlackBuilder/Info.hs
@@ -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
diff --git a/lib/SlackBuilder/Package.hs b/lib/SlackBuilder/Package.hs
index 5179c4c..c87bf4b 100644
--- a/lib/SlackBuilder/Package.hs
+++ b/lib/SlackBuilder/Package.hs
@@ -5,7 +5,8 @@
-- | Contains data describing packages, methods to update them and to request
-- information about them.
module SlackBuilder.Package
- ( Download(..)
+ ( DataBaseEntry(..)
+ , Download(..)
, DownloadTemplate(..)
, PackageDescription(..)
, PackageUpdateData(..)
@@ -66,3 +67,15 @@ data Updater = Updater
, is64 :: Bool
, getVersion :: Text -> Text -> SlackBuilderT Download
}
+
+data DataBaseEntry = DataBaseEntry
+ { name :: Text
+ , version :: Text
+ , arch :: Text
+ , build :: Text
+ } deriving Eq
+
+instance Show DataBaseEntry
+ where
+ show DataBaseEntry{..} = Text.unpack
+ $ Text.intercalate "-" [name, version, arch, build]
diff --git a/lib/SlackBuilder/Trans.hs b/lib/SlackBuilder/Trans.hs
index dea0d4b..f5697e1 100644
--- a/lib/SlackBuilder/Trans.hs
+++ b/lib/SlackBuilder/Trans.hs
@@ -10,6 +10,7 @@ module SlackBuilder.Trans
) where
import Control.Monad.Trans.Reader (ReaderT(..), asks)
+import Data.ByteString (ByteString)
import Data.Text (Text)
import qualified Data.Text as Text
import SlackBuilder.Config
@@ -20,11 +21,14 @@ import System.FilePath ((</>))
import Text.URI (URI)
import qualified Text.URI as URI
import qualified Codec.Compression.Lzma as Lzma
+import Text.Megaparsec (ParseErrorBundle(..), errorBundlePretty)
+import Conduit (Void)
data SlackBuilderException
= UpdaterNotFound Text
| UnsupportedUrlType URI
| LzmaDecompressionFailed Lzma.LzmaRet
+ | MalformedInfoFile (ParseErrorBundle ByteString Void)
deriving Show
instance Exception SlackBuilderException
@@ -55,6 +59,8 @@ instance Exception SlackBuilderException
"No progress is possible"
displayException (LzmaDecompressionFailed Lzma.LzmaRetProgError) =
"Programming error"
+ displayException (MalformedInfoFile errorBundle) =
+ errorBundlePretty errorBundle
newtype SlackBuilderT a = SlackBuilderT
{ runSlackBuilderT :: ReaderT Settings IO a