| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
System.OsRelease
Description
A module to retrieve os-release information according to the freedesktop standard: https://www.freedesktop.org/software/systemd/man/os-release.html
Usage example:
do
Just (OsRelease {..}) <- fmap osRelease <$> parseOsRelease
putStrLn name
Synopsis
- data OsReleaseResult = OsReleaseResult {
- osRelease :: !OsRelease
- unknown_fields :: [(String, String)]
- parse_errors :: [ParseError String Void]
- data OsRelease = OsRelease {
- name :: !String
- version :: !(Maybe String)
- id :: !String
- id_like :: !(Maybe String)
- version_codename :: !(Maybe String)
- version_id :: !(Maybe String)
- pretty_name :: !String
- ansi_color :: !(Maybe String)
- cpe_name :: !(Maybe String)
- home_url :: !(Maybe String)
- documentation_url :: !(Maybe String)
- support_url :: !(Maybe String)
- bug_report_url :: !(Maybe String)
- privacy_policy_url :: !(Maybe String)
- build_id :: !(Maybe String)
- variant :: !(Maybe String)
- variant_id :: !(Maybe String)
- logo :: !(Maybe String)
- parseOsRelease :: IO (Maybe OsReleaseResult)
- readOsRelease :: IO String
- defaultOsRelease :: OsRelease
- defaultAssignments :: [(String, String)]
- parseAssignments :: Parsec Void String [Either (ParseError String Void) (String, String)]
- parseAssignment :: Parsec Void String (String, String)
- getAllAssignments :: String -> [Either (ParseError String Void) (String, String)]
- getOsRelease :: [(String, String)] -> OsRelease
- parseOsRelease' :: String -> OsReleaseResult
data types
data OsReleaseResult Source #
Constructors
| OsReleaseResult | |
Fields
| |
Instances
| Show OsReleaseResult Source # | |
Defined in System.OsRelease Methods showsPrec :: Int -> OsReleaseResult -> ShowS # show :: OsReleaseResult -> String # showList :: [OsReleaseResult] -> ShowS # | |
All the explicitly documented fields of os-release.
Constructors
| OsRelease | |
Fields
| |
Instances
read/parse os-release
parseOsRelease :: IO (Maybe OsReleaseResult) Source #
Tries to read "/etc/os-release" and "/usr/lib/os_release" in order
and parses into OsReleaseResult. Returns Nothing if both files could
not be read.
readOsRelease :: IO String Source #
Tries to read "/etc/os-release" and "/usr/lib/os_release" in order.
Throws IOError if both files could not be read.
defaults
defaultOsRelease :: OsRelease Source #
The defaults as per the spec:
NAME=Linux ID=linux PRETTY_NAME=Linux
defaultAssignments :: [(String, String)] Source #
Like defaultOsRelease, except as key-value pair.
low-level
parseAssignments :: Parsec Void String [Either (ParseError String Void) (String, String)] Source #
Parse the entire file, handling newlines and comments gracefully.
This parser generally shouldn't fail, but instead report a failed
parsed line as Left value.
parseAssignment :: Parsec Void String (String, String) Source #
Parse a single line assignment and extract the right hand side. This is only a subset of a shell parser, refer to the spec for details.
Get all allAssignments as (key, val) from the os-release
file contents.
Parse the assignments into OsRelease. This is merged with the
defaults as per the spec. In case of no assignments, also returns
the defaults.
parseOsRelease' :: String -> OsReleaseResult Source #
Like parseOsRelease, except taking the input String explicitly.
Primarily for tests.