Re: [Tutor] Configuaration files and paths?

2009-08-09 Thread Martin Walsh
Allen Fowler wrote: FWIW: When using relative paths I got extra ../../ terms, so I changed join_relative() to: def join_relative(base, path): return os.path.normpath(os.path.join(script_dir(base), path)) Seems to work... Yeah, good catch ... looks great, and thanks for sharing

Re: [Tutor] Configuaration files and paths?

2009-08-07 Thread Allen Fowler
FWIW: When using relative paths I got extra ../../ terms, so I changed join_relative() to: def join_relative(base, path): return os.path.normpath(os.path.join(script_dir(base), path)) Seems to work... Yeah, good catch ... looks great, and thanks for sharing

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Dave Angel
Allen Fowler wrote: What is the recommended way to configure my application find the various database and/or configuration files it needs? Recommemded by whom? A lot depends on the OS. Apple for example have one set of recommendations for MacOS, Windows has another and Linux has

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote: What is the recommended way to configure my application find the various database and/or configuration files it needs? Recommemded by whom? A lot depends on the OS. Apple for example have one set of recommendations for MacOS, Windows has another and Linux has

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote: snip As a follow-up question, how do give my modules stored under ./lib access to the data in my ConfigParser object? (For instance, database connection string, storage path, etc.) I guess a global ConfigParser object would work, but that seems wrong. And yet,

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Allen Fowler
Assuming the application could be invoked in odd ways that may alter the notion of the current working directory, how do I unambiguously find the absolute path to the current python source file? (So I can load the nearby .ini) I use a helper function that calculates the absolute

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Allen Fowler
Martin Walsh mwa...@mwalsh.org Allen Fowler wrote: As a follow-up question, how do give my modules stored under ./lib access to the data in my ConfigParser object? (For instance, database connection string, storage path, etc.) I guess a global ConfigParser object

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Allen Fowler
Something like this ... # lib/mypaths.py # -- import os def script_path(base): return os.path.realpath(os.path.abspath(base)) def script_dir(base): return os.path.dirname(script_path(base)) def join_relative(base, path): return

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Alan Gauld
Allen Fowler allen.fow...@yahoo.com wrote For an object that needs many settings, what about passing in an instance of ConfigParser? (Or should I extract the settings to a dict, first?) Personally I usually extract an ini type settings to either global variables or an object or a dict at

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote: Something like this ... # lib/mypaths.py # -- import os def script_path(base): return os.path.realpath(os.path.abspath(base)) def script_dir(base): return os.path.dirname(script_path(base)) def join_relative(base, path): return

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote: Martin Walsh mwa...@mwalsh.org Allen Fowler wrote: As a follow-up question, how do give my modules stored under ./lib access to the data in my ConfigParser object? (For instance, database connection string, storage path, etc.) I guess a global ConfigParser

[Tutor] Configuaration files and paths?

2009-08-05 Thread Allen Fowler
Hello, What is the recommended way to configure my application find the various database and/or configuration files it needs? For instance my folder layout: /path_to_app/app.py /path_to_app/lib/ /path_to_app/database/ /path_to_app/config/ /path_to_app/photos and so on. (app.py being

Re: [Tutor] Configuaration files and paths?

2009-08-05 Thread Alan Gauld
Allen Fowler allen.fow...@yahoo.com wrote What is the recommended way to configure my application find the various database and/or configuration files it needs? Recommemded by whom? A lot depends on the OS. Apple for example have one set of recommendations for MacOS, Windows has another and

Re: [Tutor] Configuaration files and paths?

2009-08-05 Thread Allen Fowler
What is the recommended way to configure my application find the various database and/or configuration files it needs? Recommemded by whom? A lot depends on the OS. Apple for example have one set of recommendations for MacOS, Windows has another and Linux has several to choose