where should config files go in Windows?

  • Thread starter Russell E. Owen
  • Start date
R

Russell E. Owen

I'm writing a cross-platform app. Presently it runs on unix and MacOS X,
but eventually I'd like to get it working on Windows (nothing older than
2000).

For unix and MacOS X I store settings in ~/.TUIPrefs and ~/.TUIGeom and
allow extensions to be stored in ~/TUIAdditions/ and <app's parent
dir>/TUIAdditions/.

Is the home dir easily accessible from vanilla Python (and if so, how do
I get there)? Is there a better directory (I'm really not keen to mess
with the registry) or some special add-on library that I'll need?

Also, is there something simple like unix's leading "." that makes
Windows files invisible?

Any help appreciated. I tried google and found this topic discussed
several years ago, but the answers were confusing and didn't seem to
apply to current Windows.

-- Russell
 
M

Mike C. Fletcher

Russell E. Owen wrote:
....
For unix and MacOS X I store settings in ~/.TUIPrefs and ~/.TUIGeom and
allow extensions to be stored in ~/TUIAdditions/ and <app's parent
dir>/TUIAdditions/.

Is the home dir easily accessible from vanilla Python (and if so, how do
I get there)? Is there a better directory (I'm really not keen to mess
with the registry) or some special add-on library that I'll need?
There are actually multiple directories for this kind of thing,
depending on whether you're describing user's documents,
application-specific data for the user (e.g. custom dictionaries),
common application-specific data (app-specific system dictionaries),
etceteras. You can see an example of retrieving the user's
application-specific data directory here:

http://cvs.sourceforge.net/viewcvs.py/pyopengl/OpenGLContext/browser/homedirectory.py?view=markup

using either of _winreg (standard module) or win32com's shell (common
add-on, part of win32all).

See the MSDN documentation for the various folders which are defined.

http://msdn.microsoft.com/library/d...shell/reference/functions/shgetfolderpath.asp
Also, is there something simple like unix's leading "." that makes
Windows files invisible?
Haven't tried to do this myself. But then I hate "hidden" files enough
to simply disable hiding them in the explorer, so who knows, maybe I
hide them all the time :) . On windows it's more common to just put the
file in the correct directory, where they are "out of the way", instead
of dumping them into a "home" directory and hiding them.

Good luck,
Mike

_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
 
J

Josiah Carlson

I use the following for multi-platform home directories in my own
project http://pype.sourceforge.net

I've had no complaints from people using *nix or Windows. I haven't
heard of any users on macs yet, so have no comment.

- Josiah


default_homedir = os.path.dirname(os.path.abspath(__file__))
dotpath = '.application_name'

try:
#all user-based OSes
thd = os.path.expanduser("~")
if thd == "~": raise
homedir = os.path.join(thd, dotpath)
except:
try:
#*nix fallback
homedir = os.path.join(os.environ['HOME'], dotpath)
except:
try:
#windows NT,2k,XP,etc. fallback
homedir = os.path.join(os.environ['USERPROFILE'], dotpath)
except:
#What os are people using?
homedir = os.path.join(default_homedir, dotpath)
try:
# create the config directory if it
# doesn't already exist
def expandfull(var, rem=3):
if not rem:
return os.path.expandvars(var)
a = os.path.expandvars(var)
b = []
d = [b.extend(i.split('\\')) for i in a.split('/')]
c = []
for i in b:
if '%' in i:
c.append(expandfull(i, rem-1))
else:
c.append(i)
return '\\'.join(c)
if eol == "\r\n" and '%' in homedir:
homedir = expandfull(homedir)
if not os.path.exists(homedir):
os.mkdir(homedir)
except:
#print "unable to create config directory", homedir
homedir = default_homedir
 
R

Russell E. Owen

"Mike C. Fletcher said:
Russell E. Owen wrote:
...

There are actually multiple directories for this kind of thing,
depending on whether you're describing user's documents,
application-specific data for the user (e.g. custom dictionaries),
common application-specific data (app-specific system dictionaries),
etceteras. You can see an example of retrieving the user's
application-specific data directory here:

http://cvs.sourceforge.net/viewcvs.py/pyopengl/OpenGLContext/browser/homedirect
ory.py?view=markup

using either of _winreg (standard module) or win32com's shell (common
add-on, part of win32all).

See the MSDN documentation for the various folders which are defined.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platfo
rm/shell/reference/functions/shgetfolderpath.asp

Thank you very much! That's just what I wanted. I'll put preferences
<AppData>\TUIPrefs, optional user additions in <AppData>\TUIAdditions
and optional shared additions in <Common_AppData>\TUIAdditions. There
are equivalent standard directories on MacOS X (easily found; code
available on request). For unix I'll use ~/.TUIPrefs, ~/TUIAdditions and
(for lack of a better place), shared additions in
<tui_root>/TUIAdditions, where <tui_root> is the folder containing the
app's code.

-- Russell
 
M

Michael Geary

See the MSDN documentation for the various folders which are defined.
atform/shell/reference/functions/shgetfolderpath.asp

Thank you very much! That's just what I wanted. I'll put preferences
<AppData>\TUIPrefs, optional user additions in <AppData>\TUIAdditions
and optional shared additions in <Common_AppData>\TUIAdditions.

I'd like to suggest creating only a single folder under Application Data,
with additional folders inside it for your specific needs. The usual
convention is to create a folder with your company name, then additional
folders inside that for each product, and finally folders inside those for
things like your TUIPrefs and TUIAdditions.

Also, make careful note of the difference between Application Data and Local
Settings\Application Data. On most machines, it doesn't matter which of
those you use. But if someone uses "roaming profiles", then you need to
choose which of those folders to use. Application Data is part of the
roaming profile, and it gets copied from a server when the user logs in, and
back to the server when the user logs out. Local Settings\Application Data
resides strictly on the local machine.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top