remove need to set plush_datadir during development (issue 6448105)

5 views
Skip to first unread message

mz...@google.com

unread,
Aug 2, 2012, 3:48:20 PM8/2/12
to thecom...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: thecomfyshell_googlegroups.com,

Message:
please review

Description:
this means that you can just run dist/build/plush/plush -w right after
build.

perhaps this should only be on for developer builds... any thoughts?

Please review this at http://codereview.appspot.com/6448105/

Affected files:
M src/Plush/Run.hs
M src/Plush/Server.hs
M src/Plush/Utilities.hs


Index: src/Plush/Run.hs
diff --git a/src/Plush/Run.hs b/src/Plush/Run.hs
index
5a97c81c7fe3b09ae9a4d2cf18d07cfeb3e44aa7..ab6ffdc7f196c785a9fdb2b6647971202970a5ba
100644
--- a/src/Plush/Run.hs
+++ b/src/Plush/Run.hs
@@ -45,7 +45,7 @@ import Plush.Run.Posix
import Plush.Run.ShellExec
import Plush.Run.TestExec
import Plush.Types
-import Paths_plush -- generated by cabal
+import Plush.Utilities


-- | Encapsulates the state and 'PosixLike' monad of a running shell.
Index: src/Plush/Server.hs
diff --git a/src/Plush/Server.hs b/src/Plush/Server.hs
index
06e32c5f219a6d8daa18b3519cbace5db0e60b2e..73a55181608d05baa30694c2fd26f8a8fc11d57e
100644
--- a/src/Plush/Server.hs
+++ b/src/Plush/Server.hs
@@ -37,7 +37,7 @@ import Plush.Job
import Plush.Run
import Plush.Server.API
import Plush.Server.Utilities
-import Paths_plush -- generated by cabal
+import Plush.Utilities

-- | Run the plush web server. The supplied 'Runner' is used as the shell,
and
-- an optional port can be supplied. This action does not complete until
the
Index: src/Plush/Utilities.hs
diff --git a/src/Plush/Utilities.hs b/src/Plush/Utilities.hs
index
9e608f4af708e07a8e13d409fdad8aa90a24dae9..13d0393c55de4377f977fa9fa3ff35192c4408eb
100644
--- a/src/Plush/Utilities.hs
+++ b/src/Plush/Utilities.hs
@@ -16,10 +16,16 @@ limitations under the License.

module Plush.Utilities (
readUtf8File,
+ getDataDir,
)
where

+import System.Directory (getCurrentDirectory, doesDirectoryExist)
import System.IO
+import System.Posix (getEnv)
+
+import qualified Paths_plush as CabalPaths
+

-- | Lazily get a text file's contents as with 'readFile', but assume its
-- contents are encoded with UTF-8 regardless of the user's current locale.
@@ -28,3 +34,20 @@ readUtf8File path = do
h <- openFile path ReadMode
hSetEncoding h utf8
hGetContents h
+
+
+-- | Return the a data directory where Plush's static data files are
installed.
+-- This is based on 'getDataDir' that Cabal generates, only if the
environment
+-- variable isn't set, and the configured install directory doesn't exist,
then
+-- the current directory is used. As such, it is suggested that this
routine be
+-- used early, before the current directory can be moved.
+getDataDir = do
+ me <- getEnv "plush_datadir"
+ case me of
+ Just e -> return e
+ Nothing -> do
+ d <- CabalPaths.getDataDir
+ de <- doesDirectoryExist d
+ if de -- TODO(mzero): perhaps this check only if a developer
build
+ then return d
+ else getCurrentDirectory


mz...@google.com

unread,
Aug 2, 2012, 5:07:13 PM8/2/12
to thecom...@googlegroups.com, re...@codereview-hr.appspotmail.com
updated to make this behavior only available for development builds

added a Production flag that is off by default

http://codereview.appspot.com/6448105/

jas...@gmail.com

unread,
Aug 8, 2012, 4:32:44 PM8/8/12
to mz...@google.com, thecom...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reply all
Reply to author
Forward
0 new messages