Finding where to store application data portably

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Houghton

    #1

    Finding where to store application data portably


    I'm using pygame to write a game called Bombz which needs to save some
    data in a directory associated with it. In Unix/Linux I'd probably use
    "~/.bombz", in Windows something like
    "C:\Documen ts And Settings\<user> \Applicacation Data\Bombz".

    There are plenty of messages in the archives for this group about how to
    find the correct location in Windows, but what about Mac OS? There I
    don't know the correct location for this sort of thing at all. And there
    are other, more obscure systems like RISC OS (it may not have pygame but
    it definitely has python). Surely this is something that's crying out
    for an official function in os or sys.

    --
    The address in the Reply-To is genuine and should not be edited.
    See <http://www.realh.co.uk/contact.html> for more reliable contact
    addresses.
  • Robert Kern

    #2
    Re: Finding where to store application data portably

    Tony Houghton wrote:[color=blue]
    > I'm using pygame to write a game called Bombz which needs to save some
    > data in a directory associated with it. In Unix/Linux I'd probably use
    > "~/.bombz", in Windows something like
    > "C:\Documen ts And Settings\<user> \Applicacation Data\Bombz".
    >
    > There are plenty of messages in the archives for this group about how to
    > find the correct location in Windows, but what about Mac OS? There I
    > don't know the correct location for this sort of thing at all. And there
    > are other, more obscure systems like RISC OS (it may not have pygame but
    > it definitely has python). Surely this is something that's crying out
    > for an official function in os or sys.[/color]

    On OS X, the data should probably go to
    ~/Library/Application Support/Bombz/

    --
    Robert Kern
    rkern@ucsd.edu

    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter

    Comment

    • Peter Hansen

      #3
      Re: Finding where to store application data portably

      Tony Houghton wrote:[color=blue]
      >
      > I'm using pygame to write a game called Bombz which needs to save some
      > data in a directory associated with it. In Unix/Linux I'd probably use
      > "~/.bombz", in Windows something like
      > "C:\Documen ts And Settings\<user> \Applicacation Data\Bombz".
      >
      > There are plenty of messages in the archives for this group about how to
      > find the correct location in Windows, but what about Mac OS? There I
      > don't know the correct location for this sort of thing at all. And there
      > are other, more obscure systems like RISC OS (it may not have pygame but
      > it definitely has python). Surely this is something that's crying out
      > for an official function in os or sys.[/color]

      Perhaps using "import user; user.home" would be adequate. Note the
      documented side effects of doing that however.

      -Peter

      Comment

      • Steven D'Aprano

        #4
        Re: Finding where to store application data portably

        On Tue, 20 Sep 2005 23:03:52 +0100, Tony Houghton wrote:
        [color=blue]
        > I'm using pygame to write a game called Bombz which needs to save some
        > data in a directory associated with it. In Unix/Linux I'd probably use
        > "~/.bombz", in Windows something like
        > "C:\Documen ts And Settings\<user> \Applicacation Data\Bombz".[/color]

        In Windows, you shouldn't hard-code the drive letter. I don't know how you
        find out what the correct value is, but hard-coding it is just Bad.

        As a Linux user, I really am sick of every damn application, script and
        program under the sun filling the top level of my home directory with
        dot-files.

        I wish the Linux Standard Base folks would specify that settings files
        should all go into a subdirectory like ~/settings rather than filling up
        the home directory with cruft. That was acceptable in the days when people
        only looked at their files with ls, but in these days of GUI file
        managers, it is ridiculous that there are more than 100 dot files and
        directories in my home directory.

        <tilting at windmills>

        Can I ask developers to break with the obsolete and annoying habit of
        creating user-specific config files as ~/.app-name and use
        ~/settings/app-name instead?

        </tilting at windmills>


        --
        Steven.

        Comment

        • Steve Holden

          #5
          Re: Finding where to store application data portably

          Steven D'Aprano wrote:[color=blue]
          > On Tue, 20 Sep 2005 23:03:52 +0100, Tony Houghton wrote:
          >
          >[color=green]
          >>I'm using pygame to write a game called Bombz which needs to save some
          >>data in a directory associated with it. In Unix/Linux I'd probably use
          >>"~/.bombz", in Windows something like
          >>"C:\Documen ts And Settings\<user> \Applicacation Data\Bombz".[/color]
          >
          >
          > In Windows, you shouldn't hard-code the drive letter. I don't know how you
          > find out what the correct value is, but hard-coding it is just Bad.
          >
          > As a Linux user, I really am sick of every damn application, script and
          > program under the sun filling the top level of my home directory with
          > dot-files.
          >
          > I wish the Linux Standard Base folks would specify that settings files
          > should all go into a subdirectory like ~/settings rather than filling up
          > the home directory with cruft. That was acceptable in the days when people
          > only looked at their files with ls, but in these days of GUI file
          > managers, it is ridiculous that there are more than 100 dot files and
          > directories in my home directory.
          >
          > <tilting at windmills>
          >
          > Can I ask developers to break with the obsolete and annoying habit of
          > creating user-specific config files as ~/.app-name and use
          > ~/settings/app-name instead?
          >
          > </tilting at windmills>
          >
          >[/color]
          While we're asking for the improbable, perhaps we could make that

          ~/.settings/app-name

          Ssh has used the ~/.ssh directory for a long time to avoid the need for
          lots of little dot files, and this works quite well. Good luck in your
          campaign!

          regards
          Steve
          --
          Steve Holden +44 150 684 7255 +1 800 494 3119
          Holden Web LLC www.holdenweb.com
          PyCon TX 2006 www.pycon.org

          Comment

          • Dennis Lee Bieber

            #6
            Re: Finding where to store application data portably

            On Thu, 22 Sep 2005 00:23:56 +1000, Steven D'Aprano
            <steve@REMOVETH IScyber.com.au> declaimed the following in
            comp.lang.pytho n:
            [color=blue]
            > On Tue, 20 Sep 2005 23:03:52 +0100, Tony Houghton wrote:
            >[color=green]
            > > I'm using pygame to write a game called Bombz which needs to save some
            > > data in a directory associated with it. In Unix/Linux I'd probably use
            > > "~/.bombz", in Windows something like
            > > "C:\Documen ts And Settings\<user> \Applicacation Data\Bombz".[/color]
            >
            > In Windows, you shouldn't hard-code the drive letter. I don't know how you
            > find out what the correct value is, but hard-coding it is just Bad.
            >[/color]
            XP Pro seems to take
            [color=blue][color=green][color=darkred]
            >>> print os.environ["APPDATA"][/color][/color][/color]
            C:\Documents and Settings\Dennis Lee Bieber\Applicat ion Data

            Though the more consistent might be to hit the registry:

            HKEY_CURRENT_US ER\Software\Mic rosoft\Windows\ CurrentVersion\ Explorer\Shell
            Folders\AppData

            and to confuse matters, there is also a "Local AppData" entry
            --[color=blue]
            > =============== =============== =============== =============== == <
            > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
            > wulfraed@dm.net | Bestiaria Support Staff <
            > =============== =============== =============== =============== == <
            > Home Page: <http://www.dm.net/~wulfraed/> <
            > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

            Comment

            • Jeff Schwab

              #7
              Re: Finding where to store application data portably

              Steven D'Aprano wrote:
              [color=blue]
              > As a Linux user, I really am sick of every damn application, script and
              > program under the sun filling the top level of my home directory with
              > dot-files.
              >
              > I wish the Linux Standard Base folks would specify that settings files
              > should all go into a subdirectory like ~/settings rather than filling up
              > the home directory with cruft. That was acceptable in the days when people
              > only looked at their files with ls, but in these days of GUI file
              > managers, it is ridiculous that there are more than 100 dot files and
              > directories in my home directory.[/color]

              What difference does it make whether one is using a GUI or a command
              line? Anyway, the vast majority of Unix users I know still use ls a lot
              more often than GUI-based file managers.

              I prefer to keep my settings in ~/etc, as a sort of intuitive parallel
              to the Filesystem Hierarchy Standard.
              [color=blue]
              > <tilting at windmills>
              >
              > Can I ask developers to break with the obsolete and annoying habit of
              > creating user-specific config files as ~/.app-name and use
              > ~/settings/app-name instead?
              >
              > </tilting at windmills>[/color]

              Better: a user-specified $ETCDIR.

              Comment

              • Trent Mick

                #8
                Re: Finding where to store application data portably

                > > > I'm using pygame to write a game called Bombz which needs to save some[color=blue][color=green][color=darkred]
                > > > data in a directory associated with it. In Unix/Linux I'd probably use
                > > > "~/.bombz", in Windows something like
                > > > "C:\Documen ts And Settings\<user> \Applicacation Data\Bombz".[/color]
                > >
                > > In Windows, you shouldn't hard-code the drive letter. I don't know how you
                > > find out what the correct value is, but hard-coding it is just Bad.
                > >[/color]
                > XP Pro seems to take
                >[color=green][color=darkred]
                > >>> print os.environ["APPDATA"][/color][/color]
                > C:\Documents and Settings\Dennis Lee Bieber\Applicat ion Data
                >
                > Though the more consistent might be to hit the registry:
                >
                > HKEY_CURRENT_US ER\Software\Mic rosoft\Windows\ CurrentVersion\ Explorer\Shell
                > Folders\AppData
                >
                > and to confuse matters, there is also a "Local AppData" entry[/color]

                It isn't just the drive letter you shouldn't hardcode. In different
                locales the phrases "Documents and Settings" and "Applicatio n Data"
                are often different. The canonical way to get this dir on Windows is by
                using the SHGetFolderPath Windows API call with the CSIDL_APPDATA
                constant:

                http://msdn.microsoft.com/library/de...folderpath.asp

                In Python code that is:

                from win32com.shell import shellcon, shell
                path = shell.SHGetFold erPath(0, shellcon.CSIDL_ APPDATA, 0, 0)

                Unfortunately that either means having the PyWin32 extensions installed
                (which not all Python installations on Windows have) or building your
                own small binary extension to make that call. Failing that, using the
                registry location or the environment variable above might suffice
                Note that on some older Windows flavours -- not sure exactly which --
                the APPDATA env. var. might not be defined.

                Also note that Windows app guidelines encourage you to have an
                additional vendor/owner directory level before the app name. So:

                %APPDATA%\<comp any-or-vendor-name>\Bombz

                I have a little working script that I use for this kind of stuff which
                you are welcome too, if it helps. (attached)

                Trent

                --
                Trent Mick
                TrentM@ActiveSt ate.com

                Comment

                • Tony Houghton

                  #9
                  Re: Finding where to store application data portably

                  Steven D'Aprano wrote:[color=blue]
                  > On Tue, 20 Sep 2005 23:03:52 +0100, Tony Houghton wrote:
                  >
                  >[color=green]
                  >>I'm using pygame to write a game called Bombz which needs to save some
                  >>data in a directory associated with it. In Unix/Linux I'd probably use
                  >>"~/.bombz", in Windows something like
                  >>"C:\Documen ts And Settings\<user> \Applicacation Data\Bombz".[/color]
                  >
                  > In Windows, you shouldn't hard-code the drive letter. I don't know[/color]
                  how you[color=blue]
                  > find out what the correct value is, but hard-coding it is just Bad.[/color]

                  That's why I said "something like". It seems there is a definitive way
                  of finding the correct value, but it needs extra W32 extensions
                  installed. You could also start from os.path.expandu ser('~') I suppose.
                  [color=blue]
                  > As a Linux user, I really am sick of every damn application, script and
                  > program under the sun filling the top level of my home directory with
                  > dot-files.
                  >
                  > I wish the Linux Standard Base folks would specify that settings files
                  > should all go into a subdirectory like ~/settings rather than filling up
                  > the home directory with cruft. That was acceptable in the days when[/color]
                  people[color=blue]
                  > only looked at their files with ls, but in these days of GUI file
                  > managers, it is ridiculous that there are more than 100 dot files and
                  > directories in my home directory.[/color]

                  Don't all file managers have an option to hide files beginning with '.'?
                  [color=blue]
                  > <tilting at windmills>
                  >
                  > Can I ask developers to break with the obsolete and annoying habit of
                  > creating user-specific config files as ~/.app-name and use
                  > ~/settings/app-name instead?
                  >
                  > </tilting at windmills>[/color]

                  You'll probably like the XDG basedir spec then:
                  <http://freedesktop.org/wiki/Standards_2fbas edir_2dspec>

                  I suppose I should really use that, but the trouble is it can be very
                  difficult to decide whether some files are config or data, so it would
                  be nice to have a standard that doesn't segregate the two.

                  Thanks to everyone else who's replied. I've saved Trent Mick's script
                  for later reference.

                  --
                  The address in the Reply-To is genuine and should not be edited.
                  See <http://www.realh.co.uk/contact.html> for more reliable contact
                  addresses.

                  Comment

                  • Steven D'Aprano

                    #10
                    Re: Finding where to store application data portably

                    On Wed, 21 Sep 2005 20:07:54 +0100, Tony Houghton wrote:
                    [color=blue][color=green]
                    > > I wish the Linux Standard Base folks would specify that settings files
                    > > should all go into a subdirectory like ~/settings rather than filling up
                    > > the home directory with cruft. That was acceptable in the days when
                    > > people
                    > > only looked at their files with ls, but in these days of GUI file
                    > > managers, it is ridiculous that there are more than 100 dot files and
                    > > directories in my home directory.[/color]
                    >
                    > Don't all file managers have an option to hide files beginning with '.'?[/color]

                    I don't want to hide them. I just don't want them in my face when I open
                    my home directory.


                    --
                    Steven.

                    Comment

                    • Ron Adam

                      #11
                      Re: Finding where to store application data portably

                      Steven D'Aprano wrote:
                      [color=blue]
                      > On Wed, 21 Sep 2005 20:07:54 +0100, Tony Houghton wrote:
                      >
                      >[color=green][color=darkred]
                      >> > I wish the Linux Standard Base folks would specify that settings files
                      >> > should all go into a subdirectory like ~/settings rather than filling up
                      >> > the home directory with cruft. That was acceptable in the days when
                      >> > people
                      >> > only looked at their files with ls, but in these days of GUI file
                      >> > managers, it is ridiculous that there are more than 100 dot files and
                      >> > directories in my home directory.[/color]
                      >>
                      >>Don't all file managers have an option to hide files beginning with '.'?[/color]
                      >
                      >
                      > I don't want to hide them. I just don't want them in my face when I open
                      > my home directory.[/color]

                      +1

                      This has been a gripe of mine on windows as well, and hiding files (or
                      extensions) is definitely not the answer.

                      Personally I think hidden files do more harm than good. It's not a
                      substitute for good file management, and it not an acceptable
                      alternative to good security either.

                      Cheers,
                      Ron

                      Comment

                      • Ron Adam

                        #12
                        Re: Finding where to store application data portably

                        Tony Houghton wrote:[color=blue]
                        >
                        > I'm using pygame to write a game called Bombz which needs to save some
                        > data in a directory associated with it. In Unix/Linux I'd probably use
                        > "~/.bombz", in Windows something like
                        > "C:\Documen ts And Settings\<user> \Applicacation Data\Bombz".
                        >
                        > There are plenty of messages in the archives for this group about how to
                        > find the correct location in Windows, but what about Mac OS? There I
                        > don't know the correct location for this sort of thing at all. And there
                        > are other, more obscure systems like RISC OS (it may not have pygame but
                        > it definitely has python). Surely this is something that's crying out
                        > for an official function in os or sys.[/color]


                        This works on Win XP. Not sure if it will work on Linux.

                        import os

                        parent = os.path.split(o s.path.abspath( os.sys.argv[0]))[0]
                        file = parent + os.sep + '.bombz'

                        Cheers,
                        Ron

                        Comment

                        • Steven D'Aprano

                          #13
                          Re: Finding where to store application data portably

                          On Thu, 22 Sep 2005 02:14:57 +0000, Ron Adam wrote:
                          [color=blue][color=green][color=darkred]
                          >>>Don't all file managers have an option to hide files beginning with '.'?[/color]
                          >>
                          >>
                          >> I don't want to hide them. I just don't want them in my face when I open
                          >> my home directory.[/color]
                          >
                          > +1
                          >
                          > This has been a gripe of mine on windows as well, and hiding files (or
                          > extensions) is definitely not the answer.
                          >
                          > Personally I think hidden files do more harm than good. It's not a
                          > substitute for good file management, and it not an acceptable
                          > alternative to good security either.[/color]

                          Agreed. If "hidden files" are under the control of the user, then they
                          aren't really hidden, they are merely filtered from the current view.
                          Filtering may be useful in many circumstances, but if you are filtering
                          the same files all the time (eg "don't show me files starting with a
                          period" or "don't show me files with the invisible flag set") then you
                          should stick them in a subdirectory.

                          And if hidden files aren't under the control of the user (as certain
                          obscure ways of hiding files under Windows aren't), then it is a serious
                          security risk. You, the user might not be able to hide the files, but you
                          can bet some virus will. Eg if you drop an executable file in the Windows
                          XP font directory, it will not show up in the file explorer.


                          --
                          Steven.

                          Comment

                          • Tony Houghton

                            #14
                            Re: Finding where to store application data portably

                            Ron Adam wrote:[color=blue]
                            > Tony Houghton wrote:
                            >[color=green]
                            >>
                            >> I'm using pygame to write a game called Bombz which needs to save some
                            >> data in a directory associated with it. In Unix/Linux I'd probably use
                            >> "~/.bombz", in Windows something like
                            >> "C:\Documen ts And Settings\<user> \Applicacation Data\Bombz".
                            >>
                            >> There are plenty of messages in the archives for this group about how to
                            >> find the correct location in Windows, but what about Mac OS? There I
                            >> don't know the correct location for this sort of thing at all. And there
                            >> are other, more obscure systems like RISC OS (it may not have pygame but
                            >> it definitely has python). Surely this is something that's crying out
                            >> for an official function in os or sys.[/color]
                            >
                            > This works on Win XP. Not sure if it will work on Linux.
                            >
                            > import os
                            >
                            > parent = os.path.split(o s.path.abspath( os.sys.argv[0]))[0]
                            > file = parent + os.sep + '.bombz'[/color]

                            Ooh, no, I don't want saved data to go in the installation directory. In
                            general that practice encourages people to run with Admin access, and
                            it's about time Windows users were discouraged from that.

                            --
                            The address in the Reply-To is genuine and should not be edited.
                            See <http://www.realh.co.uk/contact.html> for more reliable contact
                            addresses.

                            Comment

                            • Steve Holden

                              #15
                              Re: Finding where to store application data portably

                              Ron Adam wrote:[color=blue]
                              > Tony Houghton wrote:
                              >[color=green]
                              >>I'm using pygame to write a game called Bombz which needs to save some
                              >>data in a directory associated with it. In Unix/Linux I'd probably use
                              >>"~/.bombz", in Windows something like
                              >>"C:\Documen ts And Settings\<user> \Applicacation Data\Bombz".
                              >>
                              >>There are plenty of messages in the archives for this group about how to
                              >>find the correct location in Windows, but what about Mac OS? There I
                              >>don't know the correct location for this sort of thing at all. And there
                              >>are other, more obscure systems like RISC OS (it may not have pygame but
                              >>it definitely has python). Surely this is something that's crying out
                              >>for an official function in os or sys.[/color]
                              >
                              >
                              >
                              > This works on Win XP. Not sure if it will work on Linux.
                              >
                              > import os
                              >
                              > parent = os.path.split(o s.path.abspath( os.sys.argv[0]))[0]
                              > file = parent + os.sep + '.bombz'
                              >
                              > Cheers,
                              > Ron
                              >[/color]
                              Since you've gone to the trouble to use os.path functions why not use

                              file = os.path.join(pa rent, 'bombz')

                              regards
                              Steve
                              --
                              Steve Holden +44 150 684 7255 +1 800 494 3119
                              Holden Web LLC www.holdenweb.com
                              PyCon TX 2006 www.pycon.org

                              Comment

                              Working...