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 grea

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,

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote: > > >> Martin Walsh >> > >> 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 ConfigPa

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(

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Alan Gauld
"Allen Fowler" 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 start up., I then pa

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 os.pa

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Allen Fowler
> Martin Walsh > > 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 w

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 absol

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
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 would work, but that seems wrong. > And yet

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 an

Re: [Tutor] Configuaration files and paths?

2009-08-05 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 several

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 > cho

Re: [Tutor] Configuaration files and paths?

2009-08-05 Thread Alan Gauld
"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 several to

[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 th