Accept up2date package parameter
This commit is contained in:
@ -2,8 +2,6 @@ module SlackBuilder.Info
|
||||
( PackageInfo(..)
|
||||
, generate
|
||||
, parseInfoFile
|
||||
, update
|
||||
, updateDownloadVersion
|
||||
) where
|
||||
|
||||
import Control.Applicative (Alternative(..))
|
||||
@ -12,7 +10,6 @@ import qualified Data.ByteArray as ByteArray
|
||||
import Data.ByteString (ByteString)
|
||||
import qualified Data.ByteString as ByteString
|
||||
import qualified Data.ByteString.Char8 as Char8
|
||||
import qualified Data.List.NonEmpty as NonEmpty
|
||||
import Data.Maybe (mapMaybe)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as Text
|
||||
@ -27,17 +24,15 @@ import Numeric (readHex, showHex)
|
||||
import Text.Megaparsec (Parsec, count, eof, takeWhile1P)
|
||||
import Text.Megaparsec.Byte (space, string, hexDigitChar)
|
||||
import Text.URI
|
||||
( Authority(..)
|
||||
, URI(..)
|
||||
, mkPathPiece
|
||||
( URI(..)
|
||||
, parserBs
|
||||
, render
|
||||
, unRText
|
||||
)
|
||||
import qualified Data.Word8 as Word8
|
||||
|
||||
type GenParser = Parsec Void ByteString
|
||||
|
||||
-- | Data used to generate an .info file.
|
||||
data PackageInfo = PackageInfo
|
||||
{ pkgname :: String
|
||||
, version :: Text
|
||||
@ -108,60 +103,6 @@ parseInfoFile = PackageInfo
|
||||
*> packageName
|
||||
<* "\"\n"
|
||||
|
||||
updateDownloadVersion :: PackageInfo -> Text -> Maybe String -> [URI]
|
||||
updateDownloadVersion package toVersion gnomeVersion
|
||||
= updateDownload (version package) toVersion gnomeVersion
|
||||
<$> downloads package
|
||||
|
||||
updateDownload :: Text -> Text -> Maybe String -> URI -> URI
|
||||
updateDownload fromVersion toVersion gnomeVersion
|
||||
= updateCoreVersion fromVersion toVersion gnomeVersion
|
||||
. updatePackageVersion fromVersion toVersion gnomeVersion
|
||||
|
||||
updatePackageVersion :: Text -> Text -> Maybe String -> URI -> URI
|
||||
updatePackageVersion fromVersion toVersion _gnomeVersion download = download
|
||||
{ uriPath = uriPath download >>= traverse (traverse updatePathPiece)
|
||||
}
|
||||
where
|
||||
updatePathPiece = mkPathPiece
|
||||
. Text.replace fromMajor toMajor
|
||||
. Text.replace fromVersion toVersion
|
||||
. unRText
|
||||
fromMajor = major fromVersion
|
||||
toMajor = major toVersion
|
||||
|
||||
major :: Text -> Text
|
||||
major = Text.intercalate "." . take 2 . Text.splitOn "."
|
||||
|
||||
updateCoreVersion :: Text -> Text -> Maybe String -> URI -> URI
|
||||
updateCoreVersion _fromVersion _toVersion (Just gnomeVersion) download
|
||||
| Just (False, pathPieces) <- uriPath download
|
||||
, (beforeCore, afterCore) <- NonEmpty.break (comparePathPiece "core") pathPieces
|
||||
, _ : _ : _ : sources : afterSources <- afterCore
|
||||
, comparePathPiece "sources" sources && not (null afterSources)
|
||||
, Right Authority{..} <- uriAuthority download
|
||||
, ".gnome.org" `Text.isSuffixOf` unRText authHost
|
||||
, Nothing <- authPort =
|
||||
download { uriPath = buildPath beforeCore afterSources }
|
||||
where
|
||||
comparePathPiece this that = Just that == mkPathPiece this
|
||||
buildPath beforeCore afterSources = do
|
||||
core <- mkPathPiece "core"
|
||||
let textGnomeVersion = Text.pack gnomeVersion
|
||||
minorGnomeVersion <- mkPathPiece $ major textGnomeVersion
|
||||
patchGnomeVersion <- mkPathPiece textGnomeVersion
|
||||
sources <- mkPathPiece "sources"
|
||||
let afterCore = core : minorGnomeVersion : patchGnomeVersion : sources : afterSources
|
||||
(False,) <$> NonEmpty.nonEmpty (beforeCore ++ afterCore)
|
||||
updateCoreVersion _ _ _ download = download
|
||||
|
||||
update :: PackageInfo -> Text -> [URI] -> [Digest MD5] -> PackageInfo
|
||||
update old toVersion downloads' checksums' = old
|
||||
{ version = toVersion
|
||||
, downloads = downloads'
|
||||
, checksums = checksums'
|
||||
}
|
||||
|
||||
generate :: PackageInfo -> Text
|
||||
generate pkg = Lazy.Text.toStrict $ Text.Builder.toLazyText builder
|
||||
where
|
||||
|
@ -3,7 +3,6 @@ module SlackBuilder.Package
|
||||
, Download(..)
|
||||
, DownloadTemplate(..)
|
||||
, Package(..)
|
||||
, PackageInfo(..)
|
||||
, Maintainer(..)
|
||||
, Updater(..)
|
||||
, renderDownloadWithVersion
|
||||
@ -34,15 +33,6 @@ data Download = Download
|
||||
, is64 :: Bool
|
||||
} deriving (Eq, Show)
|
||||
|
||||
-- | Data used to generate an .info file.
|
||||
data PackageInfo = PackageInfo
|
||||
{ path :: FilePath
|
||||
, version :: Text
|
||||
, homepage :: Text
|
||||
, requires :: [Text]
|
||||
, maintainer :: Maintainer
|
||||
} deriving (Eq, Show)
|
||||
|
||||
-- | Package maintainer information.
|
||||
data Maintainer = Maintainer
|
||||
{ name :: Text
|
||||
|
@ -1,11 +1,19 @@
|
||||
module SlackBuilder.Trans
|
||||
( SlackBuilderT(..)
|
||||
( SlackBuilderException(..)
|
||||
, SlackBuilderT(..)
|
||||
) where
|
||||
|
||||
import Control.Monad.Trans.Reader (ReaderT(..))
|
||||
import Data.Text (Text)
|
||||
import SlackBuilder.Config
|
||||
import Control.Monad.IO.Class (MonadIO(..))
|
||||
import Control.Monad.Catch (MonadCatch(..), MonadThrow(..))
|
||||
import Control.Exception (Exception(..))
|
||||
|
||||
newtype SlackBuilderException = UpdaterNotFound Text
|
||||
deriving Show
|
||||
|
||||
instance Exception SlackBuilderException
|
||||
|
||||
newtype SlackBuilderT a = SlackBuilderT
|
||||
{ runSlackBuilderT :: ReaderT Settings IO a
|
||||
|
Reference in New Issue
Block a user