Michael Orlitzky | 19 Dec 04:46 2013

Abstracting configuration directories

I'm writing a small utility whose only non-portable code involves the
two paths,

  /etc/htsnrc
  $HOME/.htsnrc

These have sort-of analogues under Windows; in .NET they are available
through something like,

  Environment.SpecialFolder.CommonApplicationData
  Environment.SpecialFolder.ApplicationData

I personally will only ever need to run on Linux, but as a matter of
principle I'd like to abstract the paths. Is there a library that can do
this already?
Tim C. Schroeder | 19 Dec 07:40 2013
Picon

Re: Abstracting configuration directories

I think this is what you're looking for:

http://hackage.haskell.org/package/directory-1.2.0.1/docs/System-Directory.html#g:2

Cheers,
Tim

On Dec 19, 2013, at 4:46 AM, Michael Orlitzky wrote:

> I'm writing a small utility whose only non-portable code involves the
> two paths,
> 
>  /etc/htsnrc
>  $HOME/.htsnrc
> 
> These have sort-of analogues under Windows; in .NET they are available
> through something like,
> 
>  Environment.SpecialFolder.CommonApplicationData
>  Environment.SpecialFolder.ApplicationData
> 
> I personally will only ever need to run on Linux, but as a matter of
> principle I'd like to abstract the paths. Is there a library that can do
> this already?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
Michael Orlitzky | 19 Dec 18:15 2013

Re: Abstracting configuration directories

On 12/19/2013 01:40 AM, Tim C. Schroeder wrote:
> I think this is what you're looking for:
> 
> http://hackage.haskell.org/package/directory-1.2.0.1/docs/System-Directory.html#g:2
> 

getAppUserDataDirectory will give me the user's configuration directory
(ala $HOME/.htsnrc), but not the global one (whatever I'm supposed to
use instead of /etc on Windows).

A non-default config is necessary for the application to work at all, so
it would be nice to be able to install one globally (so each user
doesn't have to copy the example and modify it). Then again, until my
patches allowing cabal to emit electric shocks are accepted, that may
just have to be the punishment for using Windows.
Colin Adams | 19 Dec 18:29 2013
Picon

Re: Abstracting configuration directories


On 19 December 2013 17:15, Michael Orlitzky <michael <at> orlitzky.com> wrote:

 Then again, until my
patches allowing cabal to emit electric shocks are accepted, that may
just have to be the punishment for using Windows.

The virus writers' union might object to that - that's there job. 
 

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Henk-Jan van Tuyl | 20 Dec 12:29 2013
Picon

Re: Abstracting configuration directories

On Thu, 19 Dec 2013 18:15:09 +0100, Michael Orlitzky  
<michael <at> orlitzky.com> wrote:

> On 12/19/2013 01:40 AM, Tim C. Schroeder wrote:
>> I think this is what you're looking for:
>>
>> http://hackage.haskell.org/package/directory-1.2.0.1/docs/System-Directory.html#g:2
>>
>
> getAppUserDataDirectory will give me the user's configuration directory
> (ala $HOME/.htsnrc), but not the global one (whatever I'm supposed to
> use instead of /etc on Windows).

You could use the environment variable AllUsersProfile[0] for this.

The directory package should be extended with a function  
getAppGlobalDataDirectory.

Regards,
Henk-Jan van Tuyl

[0] http://environmentvariables.org/AllUsersProfile

--

-- 
Folding <at> home
What if you could share your unused computer power to help find a cure? In  
just 5 minutes you can join the world's biggest networked computer and get  
us closer sooner. Watch the video.
http://folding.stanford.edu/

http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
Henk-Jan van Tuyl | 20 Dec 14:13 2013
Picon

Re: Abstracting configuration directories

On Fri, 20 Dec 2013 12:29:03 +0100, Henk-Jan van Tuyl <hjgtuyl <at> chello.nl>  
wrote:

> You could use the environment variable AllUsersProfile[0] for this.

Another way to do this:

Prelude> :m System.Win32
Prelude System.Win32> sHGetFolderPath nullPtr 35 nullPtr 0
"C:\\Documents and Settings\\All Users\\Application Data"

Regards,
Henk-Jan van Tuyl

--

-- 
Folding <at> home
What if you could share your unused computer power to help find a cure? In  
just 5 minutes you can join the world's biggest networked computer and get  
us closer sooner. Watch the video.
http://folding.stanford.edu/

http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
Michael Orlitzky | 20 Dec 20:09 2013

Re: Abstracting configuration directories

On 12/20/2013 08:13 AM, Henk-Jan van Tuyl wrote:
> On Fri, 20 Dec 2013 12:29:03 +0100, Henk-Jan van Tuyl
> <hjgtuyl <at> chello.nl> wrote:
> 
>> You could use the environment variable AllUsersProfile[0] for this.
> 
> Another way to do this:
> 
> Prelude> :m System.Win32
> Prelude System.Win32> sHGetFolderPath nullPtr 35 nullPtr 0
> "C:\\Documents and Settings\\All Users\\Application Data"
> 

Thanks, this is what getAppUserDataDirectory (from System.Directory) is
doing:

  getAppUserDataDirectory :: String -> IO FilePath
  getAppUserDataDirectory appName = do
    ...
    s <- Win32.sHGetFolderPath nullPtr Win32.cSIDL_APPDATA nullPtr 0
    ...

I think your path above is the correct location on Win32; in that case,
Windows makes it available[1] as CSIDL_COMMON_APPDATA. System.Win32
doesn't use this constant at the moment, but I think it could go in [2]
along with the rest of them.

Then, System.Directory could provide getAppGlobalDataDirectory as you
suggest.

A patch looks easy, but I'm not sure that I would call /etc the "global
data directory" on Unix. I'll have to think about it some more.

[1]
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762494%28v=vs.85%29.aspx

[2]
http://hackage.haskell.org/package/Win32-2.2.2.0/docs/System-Win32-Shell.html
Michael Orlitzky | 22 Dec 00:10 2013

Re: Abstracting configuration directories

On 12/20/2013 02:09 PM, Michael Orlitzky wrote:
> 
> A patch looks easy, but I'm not sure that I would call /etc the "global
> data directory" on Unix. I'll have to think about it some more.

For posterity, when using Cabal, the system config directory is
available via getSysconfDir in build/autogen/Paths_<program>.hs. This
puts the responsibility on the person who runs configure, which I kind
of like.
Joeri van Eekelen | 22 Dec 13:48 2013
Picon

Re: Abstracting configuration directories

Interesting. Is there documentation anywhere about what Cabal puts into 
the Paths_*.hs files? I couldn't find anything beyond getDataFileName 
and version :: Version in the Cabal user guide. The link to "prefix 
independence" refers to a non-existing anchor tag.

On 2013-12-22 00:10, Michael Orlitzky wrote:
> For posterity, when using Cabal, the system config directory is
> available via getSysconfDir in build/autogen/Paths_<program>.hs. This
> puts the responsibility on the person who runs configure, which I kind
> of like.
>

--

-- 
Joeri van Eekelen - j.v.eekelen <at> gmail.com
Michael Orlitzky | 23 Dec 03:26 2013

Re: Abstracting configuration directories

On 12/22/2013 07:48 AM, Joeri van Eekelen wrote:
> Interesting. Is there documentation anywhere about what Cabal puts into 
> the Paths_*.hs files? I couldn't find anything beyond getDataFileName 
> and version :: Version in the Cabal user guide. The link to "prefix 
> independence" refers to a non-existing anchor tag.

I don't think so, I found it by accident.
Joeri van Eekelen | 20 Dec 18:51 2013
Picon

Re: Abstracting configuration directories

I think the "right" way to accomplish this is through the Paths_pkg 
module generated by Cabal:

http://www.haskell.org/cabal/users-guide/developing-packages.html#accessing-data-files-from-package-code

Specifically, the getDataFile function can be used to look up the actual 
location of files specified in the data-files: field of the .cabal file. 
This should even work if someone uses a nonstandard --prefix.

On 2013-12-20 12:29, Henk-Jan van Tuyl wrote:
> On Thu, 19 Dec 2013 18:15:09 +0100, Michael Orlitzky
> <michael <at> orlitzky.com> wrote:
>
>> On 12/19/2013 01:40 AM, Tim C. Schroeder wrote:
>>> I think this is what you're looking for:
>>>
>>> http://hackage.haskell.org/package/directory-1.2.0.1/docs/System-Directory.html#g:2
>>>
>>>
>>
>> getAppUserDataDirectory will give me the user's configuration directory
>> (ala $HOME/.htsnrc), but not the global one (whatever I'm supposed to
>> use instead of /etc on Windows).
>
> You could use the environment variable AllUsersProfile[0] for this.
>
> The directory package should be extended with a function
> getAppGlobalDataDirectory.
>
> Regards,
> Henk-Jan van Tuyl
>
>
> [0] http://environmentvariables.org/AllUsersProfile
>
>

--

-- 
Joeri van Eekelen - j.v.eekelen <at> gmail.com
Michael Orlitzky | 20 Dec 20:17 2013

Re: Abstracting configuration directories

On 12/20/2013 12:51 PM, Joeri van Eekelen wrote:
> I think the "right" way to accomplish this is through the Paths_pkg
> module generated by Cabal:
> 
> http://www.haskell.org/cabal/users-guide/developing-packages.html#accessing-data-files-from-package-code
> 

This is more for when you want to install a data file and don't care
where, but you need to be able to find it later. My configuration file
should wind up in a fixed location (e.g. /etc on Linux); I'm just not
sure where that is on Windows, and I don't want to have to hard-code it
in case it changes in Windows 3000.

Thanks for the suggestion though.

Gmane