chore(lpr): call lpr in qualfication renewal message
This commit is contained in:
parent
3ac2151451
commit
4dbf5f35be
@ -513,7 +513,7 @@ makeCourseUserTable cid acts restrict colChoices psValidator csvColumns = do
|
||||
, dbParamsFormResult = id
|
||||
, dbParamsFormIdent = def
|
||||
}
|
||||
dbtCsvName = MsgCourseUserCsvName courseTerm courseSchool courseShorthand
|
||||
dbtCsvName = MsgCourseUserCsvName courseTerm courseSchool courseShorthand
|
||||
dbtCsvSheetName = MsgCourseUserCsvSheetName courseTerm courseSchool courseShorthand
|
||||
dbtCsvEncode = do
|
||||
csvColumns' <- csvColumns
|
||||
|
||||
@ -52,7 +52,10 @@ dispatchNotificationQualificationRenewal nQualification jRecipient = do
|
||||
-- content = $(i18nWidgetFile "qualification/renewal")
|
||||
$logDebugS "LMS" $ "Notify " <> tshow jRecipient <> " for renewal of qualifiaction " <> qname
|
||||
|
||||
let pdfMeta = applyMetas [("recipient", userDisplayName)] mempty -- TODO: add more info to interpolate here!
|
||||
let pdfMeta = applyMetas
|
||||
[ ("recipient", userDisplayName)
|
||||
-- TODO: add more info to interpolate here!
|
||||
] mempty
|
||||
pdfRenewal pdfMeta >>= \case
|
||||
Left err -> do
|
||||
let msg = "Notify " <> tshow jRecipient <> " PDF generation failed with error: " <> err
|
||||
@ -81,7 +84,12 @@ dispatchNotificationQualificationRenewal nQualification jRecipient = do
|
||||
-- TODO: this is just a dummy to continue while i18nHamletFile usage is unclear
|
||||
addHtmlMarkdownAlternatives $(ihamletFile "templates/mail/qualificationRenewal.hamlet")
|
||||
|
||||
Right _pdf | otherwise -> do
|
||||
let _letterHead = error "TODO"
|
||||
-- makePDF "pdflatex" [] writer woptions pandoc
|
||||
error "TODO"
|
||||
Right pdf | otherwise -> do
|
||||
let printJobName = mempty --TODO
|
||||
lprPDF printJobName pdf >>= \case
|
||||
Left err -> do
|
||||
let msg = "Notify " <> tshow jRecipient <> " PDF printing to send letter failed with error: " <> err
|
||||
$logErrorS "LMS" msg
|
||||
error $ unpack msg
|
||||
Right msg | null msg -> return ()
|
||||
| otherwise -> $logWarnS "LMS" $ "PDF printing to send letter with lpr returned ExitSucces and the following message: " <> msg
|
||||
@ -272,6 +272,19 @@ sendLetter' printJobName pdf printJobRecipient printJobSender printJobCourse pri
|
||||
}
|
||||
|
||||
|
||||
-----------------------------
|
||||
-- Typed Process Utilities --
|
||||
-----------------------------
|
||||
|
||||
-- | Converts Triple consisting of @ExitCode@, Success- and Failure-Value to Either Failue- or Success-Value.
|
||||
-- Returns @Right@ if the @ExitCode@ is @ExitsSuccess, entirely ignoring the Failure-Value, which ususally might contain warning messages.
|
||||
-- To be used with 'System.Process.Typed.readProcess'
|
||||
exit2either :: (ExitCode, a, b) -> Either b a
|
||||
exit2either (ExitSuccess , ok, _) = Right ok -- warnings are ignored here!
|
||||
exit2either (ExitFailure _ , _, err) = Left err
|
||||
|
||||
|
||||
|
||||
-----------
|
||||
-- pdftk --
|
||||
-----------
|
||||
@ -295,6 +308,26 @@ encryptPDF pw bs = over _Left (decodeUtf8 . LBS.toStrict) . exit2either <$> read
|
||||
-- Note that pdftk will issue a warning, which will be ignored:
|
||||
-- Warning: Using a password on the command line interface can be insecure.
|
||||
-- Use the keyword PROMPT to supply a password via standard input instead.
|
||||
exit2either :: (ExitCode, a, b) -> Either b a
|
||||
exit2either (ExitSuccess , ok, _) = Right ok -- warnings are ignored here!
|
||||
exit2either (ExitFailure _ , _, err) = Left err
|
||||
|
||||
|
||||
|
||||
---------
|
||||
-- lpr --
|
||||
---------
|
||||
--
|
||||
-- We use the external tool lpr in the variant supplied by busybox
|
||||
-- to print pdfs like so:
|
||||
-- > lpr -P fradrive@fravm017173.fra.fraport.de -J printJobName -
|
||||
--
|
||||
|
||||
lprPDF :: MonadIO m => String -> LBS.ByteString -> m (Either Text Text)
|
||||
lprPDF jb bs = over _Left (decodeUtf8 . LBS.toStrict) .
|
||||
over _Right (decodeUtf8 . LBS.toStrict) . exit2either <$> readProcess pc
|
||||
where
|
||||
pc = setStdin (byteStringInput bs) $
|
||||
proc "lpr" $ [ "-P fradrive@fravm017173.fra.fraport.de:515" -- queue@hostname:port TODO: turn this into a setting
|
||||
] ++ jobname ++ -- a name for job identification at printing site
|
||||
[ "-" -- read from stdin
|
||||
]
|
||||
jobname | null jb = []
|
||||
| otherwise = ["-J", jb]
|
||||
|
||||
Reference in New Issue
Block a user