473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

where should config files go in Windows?

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
Jul 18 '05 #1
4 1709
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.p...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/de...folderpath.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/

Jul 18 '05 #2
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
Jul 18 '05 #3
In article <ma***************************************@python. org>,
"Mike C. Fletcher" <mc******@rogers.com> wrote:
Russell E. Owen wrote:
...
(essentially I asked where prefs and application-specific data go on Windows)

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.p...ser/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/de...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
Jul 18 '05 #4
> >See the MSDN documentation for the various folders which are defined.

http://msdn.microsoft.com/library/de...-us/shellcc/pl

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
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Fuzzyman | last post by:
There have been a couple of config file 'systems' announced recently, that focus on building more powerful and complex configuration files. ConfigObj is a module to enable you to much more *simply*...
3
by: Peter Blum | last post by:
I have built an assembly (dll) from which I expect third parties to subclass. As a result, when my assembly has a version change, it will cause any third party assembly based on it to break unless...
3
by: Geoff Pennington | last post by:
It is really pathetic that I don't know this, but here it is. I have been writing ASP.Net apps for a while, and all configuration information, such as the database connection string, goes in a text...
5
by: Guadala Harry | last post by:
What are my options for *securely* storing/retrieving the ID and password used by an ASP.NET application for accessing a SQL Server (using SQL Server authentication)? Please note that this ID and...
2
by: Anna | last post by:
I added a small Web.Config file to the root of my website so that I could view errors on a machine other than the server: <configuration> <system.web> <customErrors mode="Off" /> </system.web>...
4
by: Henke | last post by:
Hi I'm building an globalized application (english, swedish and russian languages) and have a few questions: 1. In order to see the russian characters correct I have to set the requestEncoding...
1
by: herbert | last post by:
In VS.2005 a Windows Service can have an app.config file. A class library can also have an app.config file. Now if my Windows Services uses three class libraries, each of it coming with its own...
10
by: =?Utf-8?B?U3RlZmFuIEJhcmxvdw==?= | last post by:
This has been working perfectly for months. Since we switched from ASP.NET 1.1 to 2.0, we have constant and sporadic issues with updating our applications. Touching the web.config works about...
21
by: Nick Craig-Wood | last post by:
Lance Gamet <lance@gamet.comwrote: I've found http://docs.python.org/lib/module-ConfigParser.html To be easy to use and built in. It makes human readable / editable ..ini - like files. ...
1
by: =?Utf-8?B?VGVycnk=?= | last post by:
I am using the My.Settings object to save user settings. During testing, I want to 'zero' out what has been saved to start with the defaults again. Where doies the framwork actually persist these...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.