Safe Haskell | None |
---|
A module for working with Debian control files http://www.debian.org/doc/debian-policy/ch-controlfields.html
- newtype Control' a = Control {
- unControl :: [Paragraph' a]
- newtype Paragraph' a = Paragraph [Field' a]
- data Field' a
- type Control = Control' String
- type Paragraph = Paragraph' String
- type Field = Field' String
- type ControlParser a = CharParser () a
- class ControlFunctions a where
- parseControlFromFile :: FilePath -> IO (Either ParseError (Control' a))
- parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' a))
- parseControl :: String -> a -> Either ParseError (Control' a)
- lookupP :: String -> Paragraph' a -> Maybe (Field' a)
- stripWS :: a -> a
- asString :: a -> String
- pControl :: ControlParser Control
- mergeControls :: [Control' a] -> Control' a
- fieldValue :: ControlFunctions a => String -> Paragraph' a -> Maybe a
- removeField :: Eq a => a -> Paragraph' a -> Paragraph' a
- prependFields :: [Field' a] -> Paragraph' a -> Paragraph' a
- appendFields :: [Field' a] -> Paragraph' a -> Paragraph' a
- renameField :: Eq a => a -> a -> Paragraph' a -> Paragraph' a
- modifyField :: Eq a => a -> (a -> a) -> Paragraph' a -> Paragraph' a
- raiseFields :: Eq a => (a -> Bool) -> Paragraph' a -> Paragraph' a
- packParagraph :: Paragraph -> Paragraph
- packField :: Field' String -> Field' Text
- formatControl :: Control' Text -> [Text]
- formatParagraph :: Paragraph' Text -> Text
- formatField :: Field' Text -> Text
- class HasDebianControl a where
- debianControl :: a -> DebianControl
- data ControlFileError
- = NoParagraphs { }
- | NoBinaryParagraphs { }
- | MissingField { }
- | ParseRelationsError {
- locs :: [Loc]
- parseError :: ParseError
- | ParseControlError {
- locs :: [Loc]
- parseError :: ParseError
- | IOError { }
- parseDebianControlFromFile :: FilePath -> IO (Either ControlFileError DebianControl)
- validateDebianControl :: MonadCatch m => Control' Text -> m (Either ControlFileError DebianControl)
- unsafeDebianControl :: Control' Text -> DebianControl
- debianSourceParagraph :: HasDebianControl a => a -> Paragraph' Text
- debianBinaryParagraphs :: HasDebianControl a => a -> [Paragraph' Text]
- debianPackageParagraphs :: HasDebianControl a => a -> (Paragraph' Text, [Paragraph' Text])
- debianPackageNames :: HasDebianControl a => a -> (SrcPkgName, [BinPkgName])
- debianSourcePackageName :: HasDebianControl a => a -> SrcPkgName
- debianBinaryPackageNames :: HasDebianControl a => a -> [BinPkgName]
- debianRelations :: HasDebianControl a => String -> a -> Either ControlFileError (Maybe Relations)
- debianBuildDeps :: HasDebianControl a => a -> Maybe Relations
- debianBuildDepsIndep :: HasDebianControl a => a -> Maybe Relations
Types
Control | |
|
newtype Paragraph' a Source
Eq a => Eq (Paragraph' a) | |
Ord a => Ord (Paragraph' a) | |
Read a => Read (Paragraph' a) | |
Show a => Show (Paragraph' a) | |
Pretty a => Pretty (Paragraph' a) |
NOTE: we do not strip the leading or trailing whitespace in the name or value
type Paragraph = Paragraph' StringSource
type ControlParser a = CharParser () aSource
class ControlFunctions a whereSource
parseControlFromFile :: FilePath -> IO (Either ParseError (Control' a))Source
parseControlFromFile
filepath
is a simple wrapper function
that parses filepath
using pControl
parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' a))Source
parseControlFromHandle
sourceName
handle
- sourceName
is only used for error reporting
parseControl :: String -> a -> Either ParseError (Control' a)Source
parseControlFromString
sourceName
text
- sourceName
is only used for error reporting
lookupP :: String -> Paragraph' a -> Maybe (Field' a)Source
lookupP
fieldName paragraph
looks up a Field
in a Paragraph
.
N.B.
trailing and leading whitespace is not stripped.
Strip the trailing and leading space and tab characters from a string. Folded whitespace is not unfolded. This should probably be moved to someplace more general purpose.
Control File Parser
pControl :: ControlParser ControlSource
A parser for debian control file. This parser handles control files
that end without a newline as well as ones that have several blank
lines at the end. It is very liberal and does not attempt validate
the fields in any way. All trailing, leading, and folded whitespace
is preserved in the field values. See stripWS
.
Helper Functions
mergeControls :: [Control' a] -> Control' aSource
fieldValue :: ControlFunctions a => String -> Paragraph' a -> Maybe aSource
removeField :: Eq a => a -> Paragraph' a -> Paragraph' aSource
prependFields :: [Field' a] -> Paragraph' a -> Paragraph' aSource
appendFields :: [Field' a] -> Paragraph' a -> Paragraph' aSource
renameField :: Eq a => a -> a -> Paragraph' a -> Paragraph' aSource
modifyField :: Eq a => a -> (a -> a) -> Paragraph' a -> Paragraph' aSource
raiseFields :: Eq a => (a -> Bool) -> Paragraph' a -> Paragraph' aSource
Move selected fields to the beginning of a paragraph.
formatControl :: Control' Text -> [Text]Source
formatField :: Field' Text -> TextSource
Policy classes and functions
class HasDebianControl a whereSource
Class of things that contain a validated Debian control file.
debianControl :: a -> DebianControlSource
data ControlFileError Source
Errors that control files might throw, with source file name and line number generated by template haskell.
validateDebianControl :: MonadCatch m => Control' Text -> m (Either ControlFileError DebianControl)Source
Validate and return a control file in an opaque wrapper. May throw a ControlFileError. Currently we only verify that it has a Source field in the first paragraph and one or more subsequent paragraphs each with a Package field, and no syntax errors in the build dependencies (though they may be absent.)
debianSourceParagraph :: HasDebianControl a => a -> Paragraph' TextSource
debianBinaryParagraphs :: HasDebianControl a => a -> [Paragraph' Text]Source
debianPackageParagraphs :: HasDebianControl a => a -> (Paragraph' Text, [Paragraph' Text])Source
debianPackageNames :: HasDebianControl a => a -> (SrcPkgName, [BinPkgName])Source
debianSourcePackageName :: HasDebianControl a => a -> SrcPkgNameSource
debianBinaryPackageNames :: HasDebianControl a => a -> [BinPkgName]Source
debianRelations :: HasDebianControl a => String -> a -> Either ControlFileError (Maybe Relations)Source
This could access fields we haven't validated, so it can return an error. Additionally, the field might be absent, in which case it returns Nothing.
debianBuildDeps :: HasDebianControl a => a -> Maybe RelationsSource
debianBuildDepsIndep :: HasDebianControl a => a -> Maybe RelationsSource