|
From: Vincent Fu <vf...@fu...> - 2013-09-03 17:12:28
|
We are using ConfigObj to parse an ini file that has grown to an unwieldy 5000+ lines. Does anyone have suggestions for how to use ConfigObj if we split the ini into multiple files? Thanks. Vincent This e-mail (and any attachments) is confidential and may be privileged. Any unauthorized use, copying, disclosure or dissemination of this communication is prohibited. If you are not the intended recipient, please notify the sender immediately and delete all copies of the message and its attachments. |
|
From: Jason U. <ent...@gm...> - 2013-09-03 18:30:14
|
It might be cool to have an include directive, usable at any node position. On Tue, Sep 3, 2013 at 9:52 AM, Vincent Fu <vf...@fu...> wrote: > We are using ConfigObj to parse an ini file that has grown to an > unwieldy 5000+ lines. Does anyone have suggestions for how to use > ConfigObj if we split the ini into multiple files? Thanks. > > Vincent > > This e-mail (and any attachments) is confidential and may be privileged. > Any unauthorized use, copying, disclosure or dissemination of this > communication is prohibited. If you are not the intended recipient, > please notify the sender immediately and delete all copies of the message > and its attachments. > > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > -- ~ Jason Unger |
|
From: Michael F. <fuz...@vo...> - 2013-09-03 22:52:34
|
On 3 Sep 2013, at 19:29, Jason Unger <ent...@gm...> wrote: > It might be cool to have an include directive, usable at any node position. It would be. I'm not actively working on configobj at the moment I'm afraid. Have a look at configglue instead which does have an include system. For configobj you can use multiple ini files and the "merge" method to combine them into a single ConfigObj. Michael > > > On Tue, Sep 3, 2013 at 9:52 AM, Vincent Fu <vf...@fu...> wrote: > We are using ConfigObj to parse an ini file that has grown to an > unwieldy 5000+ lines. Does anyone have suggestions for how to use > ConfigObj if we split the ini into multiple files? Thanks. > > Vincent > > This e-mail (and any attachments) is confidential and may be privileged. Any unauthorized use, copying, disclosure or dissemination of this communication is prohibited. If you are not the intended recipient, please notify the sender immediately and delete all copies of the message and its attachments. > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > > -- > ~ Jason Unger > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk_______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop -- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html |
|
From: Jason U. <ent...@gm...> - 2013-09-03 22:54:11
|
And what would happen if you did a root level save()? On Tue, Sep 3, 2013 at 3:34 PM, Michael Foord <fuz...@vo...>wrote: > > On 3 Sep 2013, at 19:29, Jason Unger <ent...@gm...> wrote: > > > It might be cool to have an include directive, usable at any node > position. > > > It would be. I'm not actively working on configobj at the moment I'm > afraid. Have a look at configglue instead which does have an include system. > > For configobj you can use multiple ini files and the "merge" method to > combine them into a single ConfigObj. > > Michael > > > > > > > On Tue, Sep 3, 2013 at 9:52 AM, Vincent Fu <vf...@fu...> wrote: > > We are using ConfigObj to parse an ini file that has grown to an > > unwieldy 5000+ lines. Does anyone have suggestions for how to use > > ConfigObj if we split the ini into multiple files? Thanks. > > > > Vincent > > > > This e-mail (and any attachments) is confidential and may be privileged. > Any unauthorized use, copying, disclosure or dissemination of this > communication is prohibited. If you are not the intended recipient, > please notify the sender immediately and delete all copies of the message > and its attachments. > > > > > ------------------------------------------------------------------------------ > > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > > Discover the easy way to master current and previous Microsoft > technologies > > and advance your career. Get an incredible 1,500+ hours of step-by-step > > tutorial videos with LearnDevNow. Subscribe today and save! > > > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > > _______________________________________________ > > Configobj-develop mailing list > > Con...@li... > > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > > > > > > -- > > ~ Jason Unger > > > ------------------------------------------------------------------------------ > > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > > Discover the easy way to master current and previous Microsoft > technologies > > and advance your career. Get an incredible 1,500+ hours of step-by-step > > tutorial videos with LearnDevNow. Subscribe today and save! > > > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk_______________________________________________ > > Configobj-develop mailing list > > Con...@li... > > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > -- > http://www.voidspace.org.uk/ > > > May you do good and not evil > May you find forgiveness for yourself and forgive others > May you share freely, never taking more than you give. > -- the sqlite blessing > http://www.sqlite.org/different.html > > > > > > > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > -- ~ Jason Unger |
|
From: Michael F. <fuz...@vo...> - 2013-09-03 22:54:51
|
On 3 Sep 2013, at 23:53, Jason Unger <ent...@gm...> wrote: > And what would happen if you did a root level save()? > > The wrong thing :-) Michael > On Tue, Sep 3, 2013 at 3:34 PM, Michael Foord <fuz...@vo...> wrote: > > On 3 Sep 2013, at 19:29, Jason Unger <ent...@gm...> wrote: > > > It might be cool to have an include directive, usable at any node position. > > > It would be. I'm not actively working on configobj at the moment I'm afraid. Have a look at configglue instead which does have an include system. > > For configobj you can use multiple ini files and the "merge" method to combine them into a single ConfigObj. > > Michael > > > > > > > On Tue, Sep 3, 2013 at 9:52 AM, Vincent Fu <vf...@fu...> wrote: > > We are using ConfigObj to parse an ini file that has grown to an > > unwieldy 5000+ lines. Does anyone have suggestions for how to use > > ConfigObj if we split the ini into multiple files? Thanks. > > > > Vincent > > > > This e-mail (and any attachments) is confidential and may be privileged. Any unauthorized use, copying, disclosure or dissemination of this communication is prohibited. If you are not the intended recipient, please notify the sender immediately and delete all copies of the message and its attachments. > > > > ------------------------------------------------------------------------------ > > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > > Discover the easy way to master current and previous Microsoft technologies > > and advance your career. Get an incredible 1,500+ hours of step-by-step > > tutorial videos with LearnDevNow. Subscribe today and save! > > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > > _______________________________________________ > > Configobj-develop mailing list > > Con...@li... > > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > > > > > > -- > > ~ Jason Unger > > ------------------------------------------------------------------------------ > > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > > Discover the easy way to master current and previous Microsoft technologies > > and advance your career. Get an incredible 1,500+ hours of step-by-step > > tutorial videos with LearnDevNow. Subscribe today and save! > > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk_______________________________________________ > > Configobj-develop mailing list > > Con...@li... > > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > -- > http://www.voidspace.org.uk/ > > > May you do good and not evil > May you find forgiveness for yourself and forgive others > May you share freely, never taking more than you give. > -- the sqlite blessing > http://www.sqlite.org/different.html > > > > > > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > > -- > ~ Jason Unger > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk_______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop -- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html |
|
From: Vincent Fu <vf...@fu...> - 2013-09-03 22:57:43
|
It appears to me that merge method would not work if sections in one ini file referenced sections in another. Is this correct? On 09/03/2013 04:54 PM, Michael Foord wrote: > > On 3 Sep 2013, at 23:53, Jason Unger <ent...@gm...> wrote: > >> And what would happen if you did a root level save()? >> >> > > The wrong thing :-) > > Michael > >> On Tue, Sep 3, 2013 at 3:34 PM, Michael Foord <fuz...@vo...> wrote: >> >> On 3 Sep 2013, at 19:29, Jason Unger <ent...@gm...> wrote: >> >>> It might be cool to have an include directive, usable at any node position. >> >> >> It would be. I'm not actively working on configobj at the moment I'm afraid. Have a look at configglue instead which does have an include system. >> >> For configobj you can use multiple ini files and the "merge" method to combine them into a single ConfigObj. >> >> Michael >> >>> >>> >>> On Tue, Sep 3, 2013 at 9:52 AM, Vincent Fu <vf...@fu...> wrote: >>> We are using ConfigObj to parse an ini file that has grown to an >>> unwieldy 5000+ lines. Does anyone have suggestions for how to use >>> ConfigObj if we split the ini into multiple files? Thanks. >>> >>> Vincent >>> >>> This e-mail (and any attachments) is confidential and may be privileged. Any unauthorized use, copying, disclosure or dissemination of this communication is prohibited. If you are not the intended recipient, please notify the sender immediately and delete all copies of the message and its attachments. >>> >>> ------------------------------------------------------------------------------ >>> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >>> Discover the easy way to master current and previous Microsoft technologies >>> and advance your career. Get an incredible 1,500+ hours of step-by-step >>> tutorial videos with LearnDevNow. Subscribe today and save! >>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk >>> _______________________________________________ >>> Configobj-develop mailing list >>> Con...@li... >>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >>> >>> >>> >>> -- >>> ~ Jason Unger >>> ------------------------------------------------------------------------------ >>> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >>> Discover the easy way to master current and previous Microsoft technologies >>> and advance your career. Get an incredible 1,500+ hours of step-by-step >>> tutorial videos with LearnDevNow. Subscribe today and save! >>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk_______________________________________________ >>> Configobj-develop mailing list >>> Con...@li... >>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> >> >> -- >> http://www.voidspace.org.uk/ >> >> >> May you do good and not evil >> May you find forgiveness for yourself and forgive others >> May you share freely, never taking more than you give. >> -- the sqlite blessing >> http://www.sqlite.org/different.html >> >> >> >> >> >> >> ------------------------------------------------------------------------------ >> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >> Discover the easy way to master current and previous Microsoft technologies >> and advance your career. Get an incredible 1,500+ hours of step-by-step >> tutorial videos with LearnDevNow. Subscribe today and save! >> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk >> _______________________________________________ >> Configobj-develop mailing list >> Con...@li... >> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> >> >> >> -- >> ~ Jason Unger >> ------------------------------------------------------------------------------ >> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >> Discover the easy way to master current and previous Microsoft technologies >> and advance your career. Get an incredible 1,500+ hours of step-by-step >> tutorial videos with LearnDevNow. Subscribe today and save! >> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk_______________________________________________ >> Configobj-develop mailing list >> Con...@li... >> https://lists.sourceforge.net/lists/listinfo/configobj-develop > > > -- > http://www.voidspace.org.uk/ > > > May you do good and not evil > May you find forgiveness for yourself and forgive others > May you share freely, never taking more than you give. > -- the sqlite blessing > http://www.sqlite.org/different.html > > > > > > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > |
|
From: Michael F. <fuz...@vo...> - 2013-09-03 22:58:59
|
On 3 Sep 2013, at 23:56, Vincent Fu <vf...@fu...> wrote: > It appears to me that merge method would not work if sections in one ini > file referenced sections in another. Is this correct? Correct. Those references would be resolved when the individual files were loaded, so cross file references wouldn't work. Michael > > On 09/03/2013 04:54 PM, Michael Foord wrote: >> >> On 3 Sep 2013, at 23:53, Jason Unger <ent...@gm...> wrote: >> >>> And what would happen if you did a root level save()? >>> >>> >> >> The wrong thing :-) >> >> Michael >> >>> On Tue, Sep 3, 2013 at 3:34 PM, Michael Foord <fuz...@vo...> wrote: >>> >>> On 3 Sep 2013, at 19:29, Jason Unger <ent...@gm...> wrote: >>> >>>> It might be cool to have an include directive, usable at any node position. >>> >>> >>> It would be. I'm not actively working on configobj at the moment I'm afraid. Have a look at configglue instead which does have an include system. >>> >>> For configobj you can use multiple ini files and the "merge" method to combine them into a single ConfigObj. >>> >>> Michael >>> >>>> >>>> >>>> On Tue, Sep 3, 2013 at 9:52 AM, Vincent Fu <vf...@fu...> wrote: >>>> We are using ConfigObj to parse an ini file that has grown to an >>>> unwieldy 5000+ lines. Does anyone have suggestions for how to use >>>> ConfigObj if we split the ini into multiple files? Thanks. >>>> >>>> Vincent >>>> >>>> This e-mail (and any attachments) is confidential and may be privileged. Any unauthorized use, copying, disclosure or dissemination of this communication is prohibited. If you are not the intended recipient, please notify the sender immediately and delete all copies of the message and its attachments. >>>> >>>> ------------------------------------------------------------------------------ >>>> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >>>> Discover the easy way to master current and previous Microsoft technologies >>>> and advance your career. Get an incredible 1,500+ hours of step-by-step >>>> tutorial videos with LearnDevNow. Subscribe today and save! >>>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk >>>> _______________________________________________ >>>> Configobj-develop mailing list >>>> Con...@li... >>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >>>> >>>> >>>> >>>> -- >>>> ~ Jason Unger >>>> ------------------------------------------------------------------------------ >>>> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >>>> Discover the easy way to master current and previous Microsoft technologies >>>> and advance your career. Get an incredible 1,500+ hours of step-by-step >>>> tutorial videos with LearnDevNow. Subscribe today and save! >>>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk_______________________________________________ >>>> Configobj-develop mailing list >>>> Con...@li... >>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >>> >>> >>> -- >>> http://www.voidspace.org.uk/ >>> >>> >>> May you do good and not evil >>> May you find forgiveness for yourself and forgive others >>> May you share freely, never taking more than you give. >>> -- the sqlite blessing >>> http://www.sqlite.org/different.html >>> >>> >>> >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >>> Discover the easy way to master current and previous Microsoft technologies >>> and advance your career. Get an incredible 1,500+ hours of step-by-step >>> tutorial videos with LearnDevNow. Subscribe today and save! >>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk >>> _______________________________________________ >>> Configobj-develop mailing list >>> Con...@li... >>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >>> >>> >>> >>> -- >>> ~ Jason Unger >>> ------------------------------------------------------------------------------ >>> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >>> Discover the easy way to master current and previous Microsoft technologies >>> and advance your career. Get an incredible 1,500+ hours of step-by-step >>> tutorial videos with LearnDevNow. Subscribe today and save! >>> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk_______________________________________________ >>> Configobj-develop mailing list >>> Con...@li... >>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> >> >> -- >> http://www.voidspace.org.uk/ >> >> >> May you do good and not evil >> May you find forgiveness for yourself and forgive others >> May you share freely, never taking more than you give. >> -- the sqlite blessing >> http://www.sqlite.org/different.html >> >> >> >> >> >> >> ------------------------------------------------------------------------------ >> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! >> Discover the easy way to master current and previous Microsoft technologies >> and advance your career. Get an incredible 1,500+ hours of step-by-step >> tutorial videos with LearnDevNow. Subscribe today and save! >> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk >> _______________________________________________ >> Configobj-develop mailing list >> Con...@li... >> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop -- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html |
|
From: Lars L. <la...@mo...> - 2013-09-04 17:07:48
|
I used this solution for the same problem in some of my work at Mozilla:
import re
class ConfigObjWithIncludes(configobj.ConfigObj):
"""This derived class is an extention to ConfigObj that adds nested
includes to ini files. Here's an example:
db.ini:
dbhostname=myserver
dbname=some_database
dbuser=dwight
dbpassword=secrets
app.ini:
[source]
+include ./db.ini
[destination]
+include ./db.ini
when the 'app.ini' file is loaded, ConfigObj will respond as if the file
had been written like this:
[source]
dbhostname=myserver
dbname=some_database
dbuser=dwight
dbpassword=secrets
[destination]
dbhostname=myserver
dbname=some_database
dbuser=dwight
dbpassword=secrets
"""
_include_re = re.compile(r'^(\s*)\+include\s+(.*?)\s*$')
def _expand_files(self, file_name, original_path, indent=""):
"""This recursive function accepts a file name, opens the file and then
spools the contents of the file into a list, examining each line as it
does so. If it detects a line beginning with "+include", it assumes
the string immediately following is a file name. Recursing, the file
new file is opened and its contents are spooled into the accumulating
list."""
expanded_file_contents = []
with open(file_name) as f:
for a_line in f:
match = ConfigObjWithIncludes._include_re.match(a_line)
if match:
include_file = match.group(2)
if include_file.startswith('.'):
include_file = os.path.join(
original_path,
include_file
)
new_lines = self._expand_files(include_file, os.path.dirname(include_file),
indent + match.group(1))
expanded_file_contents.extend(new_lines)
else:
expanded_file_contents.append(indent + a_line.rstrip())
return expanded_file_contents
def _load(self, infile, configspec):
"""this overrides the original ConfigObj method of the same name. It
runs through the input file collecting lines into a list. When
completed, this method submits the list of lines to the super class'
function of the same name. ConfigObj proceeds, completely unaware
that it's input file has been preprocessed."""
if isinstance(infile, basestring):
original_path = os.path.dirname(infile)
expanded_file_contents = self._expand_files(infile, original_path)
super(ConfigObjWithIncludes, self)._load(
expanded_file_contents,
configspec
)
else:
super(ConfigObjWithIncludes, self)._load(infile, configspec)
|
|
From: Vincent Fu <vf...@fu...> - 2013-09-09 19:25:51
|
Lars, this works great. Thank you very much.
Vincent
On 09/04/2013 10:49 AM, Lars Lohn wrote:
> I used this solution for the same problem in some of my work at Mozilla:
>
>
> import re
>
>
> class ConfigObjWithIncludes(configobj.ConfigObj):
> """This derived class is an extention to ConfigObj that adds nested
> includes to ini files. Here's an example:
>
> db.ini:
>
> dbhostname=myserver
> dbname=some_database
> dbuser=dwight
> dbpassword=secrets
>
> app.ini:
> [source]
> +include ./db.ini
>
> [destination]
> +include ./db.ini
>
> when the 'app.ini' file is loaded, ConfigObj will respond as if the file
> had been written like this:
> [source]
> dbhostname=myserver
> dbname=some_database
> dbuser=dwight
> dbpassword=secrets
>
> [destination]
> dbhostname=myserver
> dbname=some_database
> dbuser=dwight
> dbpassword=secrets
> """
> _include_re = re.compile(r'^(\s*)\+include\s+(.*?)\s*$')
>
> def _expand_files(self, file_name, original_path, indent=""):
> """This recursive function accepts a file name, opens the file and then
> spools the contents of the file into a list, examining each line as it
> does so. If it detects a line beginning with "+include", it assumes
> the string immediately following is a file name. Recursing, the file
> new file is opened and its contents are spooled into the accumulating
> list."""
> expanded_file_contents = []
> with open(file_name) as f:
> for a_line in f:
> match = ConfigObjWithIncludes._include_re.match(a_line)
> if match:
> include_file = match.group(2)
> if include_file.startswith('.'):
> include_file = os.path.join(
> original_path,
> include_file
> )
> new_lines = self._expand_files(include_file, os.path.dirname(include_file),
> indent + match.group(1))
> expanded_file_contents.extend(new_lines)
> else:
> expanded_file_contents.append(indent + a_line.rstrip())
> return expanded_file_contents
>
> def _load(self, infile, configspec):
> """this overrides the original ConfigObj method of the same name. It
> runs through the input file collecting lines into a list. When
> completed, this method submits the list of lines to the super class'
> function of the same name. ConfigObj proceeds, completely unaware
> that it's input file has been preprocessed."""
> if isinstance(infile, basestring):
> original_path = os.path.dirname(infile)
> expanded_file_contents = self._expand_files(infile, original_path)
> super(ConfigObjWithIncludes, self)._load(
> expanded_file_contents,
> configspec
> )
> else:
> super(ConfigObjWithIncludes, self)._load(infile, configspec)
>
>
>
> ------------------------------------------------------------------------------
> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> Discover the easy way to master current and previous Microsoft technologies
> and advance your career. Get an incredible 1,500+ hours of step-by-step
> tutorial videos with LearnDevNow. Subscribe today and save!
> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
This e-mail (and any attachments) is confidential and may be privileged. Any unauthorized use, copying, disclosure or dissemination of this communication is prohibited. If you are not the intended recipient, please notify the sender immediately and delete all copies of the message and its attachments.
|