<commit_before>module System.MapleSSH (maple) where

import Data.Maybe(fromMaybe)
import Data.Char(isSpace)
import System.IO
import System.Process
import System.Environment
import System.Exit

-- Default values for SSH environment variables
defSSH, defUser, defServer, defModule :: String
defSSH    = "/usr/bin/ssh"
defUser   = "ppaml"
defServer = "quarry.uits.indiana.edu"
defModule = "maple/18"


envVarsSSH :: IO (String, String, String, String)
envVarsSSH = do
    ssh     <- get "MAPLE_SSH"    defSSH
    user    <- get "MAPLE_USER"   defUser
    server  <- get "MAPLE_SERVER" defServer
    mpl_mod <- get "MAPLE_MODULE" defModule
    return (ssh, user, server, mpl_mod)
    where get name def = fmap (fromMaybe def) (lookupEnv name)

process :: IO CreateProcess
process = do
    bin <- lookupEnv "MAPLE"
    case bin of
        Just b  -> return $ proc b ["-q", "-t"]
        Nothing -> 
          do (ssh, user, server, mpl_mod) <- envVarsSSH
             let commands = "module load -s " ++ mpl_mod ++ "; maple -q -t" -- quiet mode
             return $ proc ssh ["-l" ++ user, server, commands]
<commit_msg>second round of tightening code.  Done now.<commit_after>module System.MapleSSH (maple) where

import Data.Maybe(fromMaybe)
import Data.Char(isSpace)
import System.IO (hPutStrLn, hClose, hGetContents)
import System.Process (proc, CreateProcess(..), StdStream(CreatePipe), createProcess, waitForProcess)
import System.Environment (lookupEnv)
import System.Exit (ExitCode(ExitSuccess))

-- Default values for SSH environment variables
defSSH, defUser, defServer, defModule :: String
defSSH    = "/usr/bin/ssh"
defUser   = "ppaml"
defServer = "quarry.uits.indiana.edu"
defModule = "maple/18"


envVarsSSH :: IO (String, String, String, String)
envVarsSSH = do
    ssh     <- get "MAPLE_SSH"    defSSH
    user    <- get "MAPLE_USER"   defUser
    server  <- get "MAPLE_SERVER" defServer
    mpl_mod <- get "MAPLE_MODULE" defModule
    return (ssh, user, server, mpl_mod)
    where get name def = fmap (fromMaybe def) (lookupEnv name)

process :: IO CreateProcess
process = do
    bin <- lookupEnv "MAPLE"
    case bin of
        Just b  -> return $ proc b ["-q", "-t"]
        Nothing -> 
          do (ssh, user, server, mpl_mod) <- envVarsSSH
             let commands = "module load -s " ++ mpl_mod ++ "; maple -q -t" -- quiet mode
             return $ proc ssh ["-l" ++ user, server, commands]

{'fraction_non_alphanumeric': 0.11691542288557213, 'fraction_numerical': 0.001658374792703151, 'mean_word_length': 3.0760135135135136, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '463701', 'n_tokens_mistral': 815, 'n_tokens_neox': 786, 'n_words': 248}