Re: Python regexp help; WAS Re: [A-a-p-user] compilation vs. publishing
Brought to you by:
vimboss
From: Matthew W. O. <mat...@we...> - 2003-02-22 18:52:54
|
-- Bram Moolenaar <Br...@mo...> wrote (on Saturday, 22 February 2003, 03:34 PM +0100): > Matthew Weier O'Phinney wrote: > > There's only one portion of it with which I'm unhappy, and it has to do > > with using a regexp in Python (I'm a Perl guy, myself, so the Python > > constructions seem a bit foreign). > > > > Basically, I have the following list of sourcefiles: > > > > HTMFILES = `glob("src/*.htm")` > > `glob("src/dir1/*.htm")` > > `glob("src/dir2/*.htm")` > > `glob("src/dir2/sub1/*.htm")` > > > > and so on. I then define HTMLFILES as follows: > > > > HTMLFILES = > > @p = re.compile('src/') > > @for fname in HTMFILES.split(): > > @ htmlname = aap_sufreplace("htm", "html", os.path.basename(fname)) > > @ htmlpath = p.sub('',os.path.dirname(fname)) > > HTMLFILES += $BDIR/$htmlpath/$htmlname { publish = $PUBLISH/$htmlpath/$htmlname } > > > > This does a couple things: > > it replaces the .htm suffix with .html > > it strips the leading "src/" off the path > > it creates the path to the compiled HTML file based on BDIR, the > > stripped path, and the filename with new suffix > > it creates the publish path basedon the stripped path and the > > filename with new suffix > > > > Unfortunately, for all files in the first level of the source tree -- > > src/* -- the path isn't stripped! The file is still compiled, but it > > then is published to the wrong area. > > > > Is it a problem with how I've created the regexp? or does it have to do > > with the way os.path.basename works? > > I think the problem is that you first apply os.path.dirname() to the > file, so that "src/foo.htm" is changed to "src". You match with "src/" > but there is no slash. Try doing the substitution first, like this: > > htmlpath = os.path.dirname(p.sub('', fname)) Yes, that did the trick. Thanks for all the help the last couple days! -- Matthew Weier O'Phinney ma...@we... |