Skip to content

Commit

Permalink
Update parser/universum deps, custom stript interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
volhovm committed Nov 8, 2019
1 parent 3c5646e commit 6d1283c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.stack-work
stack.yaml.lock
*#
\#*
*~
Expand Down
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.1.7
==========
* Switch "script" output interpreter from "sh" to "/bin/env sh".
* Update universum and orgmode-parse version (includes
https://github.com/ixmatus/orgmode-parse/pull/53)

0.1.6
==========
* Support "or" tags -- now it's possible to specify "t1 | t2 | t3" as a modifier by
Expand Down
6 changes: 3 additions & 3 deletions orgstat.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: orgstat
version: 0.1.6
version: 0.1.7
synopsis: Statistics visualizer for org-mode
license: GPL-3
license-file: LICENSE
Expand Down Expand Up @@ -50,12 +50,12 @@ library
, lens >= 4.14
, mtl >= 2.2.1
, optparse-simple
, orgmode-parse >= 0.2.1 && < 0.3
, orgmode-parse >= 0.2.3 && < 0.3
, process >= 1.6.3.0
, text >= 1.2.2.1
, time >= 1.6.0.1
, turtle >= 1.2.8
, universum >= 1.4.0
, universum >= 1.5.0
, yaml >= 0.8.21.1
hs-source-dirs: src
default-language: Haskell2010
Expand Down
5 changes: 3 additions & 2 deletions src/OrgStat/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ data ConfDate

data ConfRange
= ConfFromTo !ConfDate !ConfDate
| ConfBlockWeek !Integer
| ConfBlockDay !Integer
| ConfBlockWeek !Integer
| ConfBlockMonth !Integer
deriving (Show)

Expand Down Expand Up @@ -159,7 +159,8 @@ instance FromJSON ConfOutputType where
fmap Left (o .: "scriptPath") <|>
fmap Right (o .: "inline")
spReports <- o .: "reports"
pure $ ScriptOutput $ ScriptParams spScript spReports
spInterpreter <- o .:? "interpreter" .!= "sh"
pure $ ScriptOutput $ ScriptParams spScript spReports spInterpreter
(String "block") -> do
boReport <- o .: "report"
_bpMaxLength <- o .:? "maxLength" .!= 80
Expand Down
5 changes: 4 additions & 1 deletion src/OrgStat/Outputs/Script.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import System.Process (callCommand)
import OrgStat.Ast (filterHasClock, orgTotalDuration)
import OrgStat.Config (confReports, crName)
import OrgStat.Helpers (resolveReport)
import OrgStat.Logging
import OrgStat.Outputs.Types (ScriptParams (..))
import OrgStat.Util (timeF)
import OrgStat.WorkMonad (WorkM, wcConfig)
Expand All @@ -31,6 +32,7 @@ processScriptOutput ScriptParams{..} = do
-- Set env variables
prevVars <- forM allReports $ \(toString -> reportName,org) -> do
let duration = timeF $ orgTotalDuration $ filterHasClock org
logDebug $ "Variable " <> show reportName <> " duration is " <> show duration
(prevVar :: Maybe String) <- liftIO $ lookupEnv reportName
liftIO $ setEnv reportName (toString duration)
pure $ (reportName,) <$> prevVar
Expand All @@ -40,7 +42,8 @@ processScriptOutput ScriptParams{..} = do
-- Execute script
let cmdArgument = either id (\t -> "-c \"" <> toString t <> "\"") spScript
liftIO $ callCommand $
"sh " <> cmdArgument
spInterpreter <> " " <> cmdArgument
--"/bin/env sh " <> cmdArgument

-- Restore the old variables, clean new.
forM_ (map fst allReports) $ \(toString -> reportName) -> do
Expand Down
16 changes: 9 additions & 7 deletions src/OrgStat/Outputs/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ module OrgStat.Outputs.Types
, BlockOutput (..)
) where

import Universum
import Universum

import Control.Lens (makeLenses)
import Control.Lens (makeLenses)

import Data.Default (Default (..))
import Diagrams.Backend.SVG (B)
import qualified Diagrams.Prelude as D
import Data.Default (Default (..))
import Diagrams.Backend.SVG (B)
import qualified Diagrams.Prelude as D

----------------------------------------------------------------------------
-- Timeline
Expand Down Expand Up @@ -75,10 +75,12 @@ newtype SummaryOutput = SummaryOutput Text

-- | Parameters of the summary output
data ScriptParams = ScriptParams
{ spScript :: !(Either FilePath Text)
{ spScript :: !(Either FilePath Text)
-- ^ Either path to the script to execute, or a script text itself.
, spReports :: ![Text]
, spReports :: ![Text]
-- ^ Reports to consider.
, spInterpreter :: !String
-- ^ Interpreter to use.
} deriving Show

----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ nix:

extra-deps:
- fmt-0.6
- universum-1.4.0
- orgmode-parse-0.2.2
- universum-1.5.0
- orgmode-parse-0.2.3
- thyme-0.3.5.5 # required by orgmode-parse

0 comments on commit 6d1283c

Please sign in to comment.