List installed packages from a repository
This commit is contained in:
@ -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
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user