[Pythonmac-SIG] File path problem (long post)

Josh English english at spiritone.com
Sun Jun 15 05:26:42 EDT 2003


The Problem so far.

This has to do with translating a bunch of xml files into html. There is
a project folder Zaphod:Web (Zaphod is not my boot partition. Marvin is,
and Python is installed in Marvin). Inside the Zaphod:Web folder there
is a folder called "input", so it's path name is 'Zaphod:Web:input:' and
inside this folder I have subfolders containing xml files. Here is the
files being read:

Zaphod:Web:input:code:pbm:pbmdoc.xml
Zaphod:Web:nput:code:webmenu:webmenudd.xml

The program reads the file at Zaphod:Web:cms.ini which has to pertinent entries:
inpath = input
outpath = output

Basically, the program reads the files in Zaphod:Web:input and should
process each file into HTML and put them in a similar file directory
under the Zaphod:Web:output directory (which does exist and is created
by the program if needed). The files I am looking to get should have the paths:

Zaphod:Web:output:code:pbm:pbmdoc.html
Zaphod:Web:output:code:webmenu:webmenudd.html

Now here's the sticky bit: In the Python Interactive window I can get
the following:

>>>os.path.join('Zaphod:Wev:xml:code:pbm:pbmdoc.xml','Zaphod:Web:output:code:pbm:pbmdoc.html')
'Zaphod:Web:output:code:pbm:pbmdoc.html'
>>>os.path.join('Zaphod:Web:output:code:pbm,pbmdoc.html','Zaphod:Web:input:code:pbm:pbmdoc.xml')
'Zaphod:Web:input:code:pbm:pbmdoc.xml'

Typo's notwithstanding, the first example is what I want to get.

Now in my code the class object doing all of the work is called
SiteUpdater, initialized as

mycms = SiteUpdater(1,1)  
The parameters simply tell the program to process every file in the
input directory (and subdirectories) and write a report to the standard
output. Here are the four lines of code where I think my problem lies:

print file,self.cms.outpath
opath = os.path.join(file,self.cms.outpath)
opath = os.path.splitext(opath)[0]+'.html'
print "Updating",os.path.join(self.cms.inpath,file),"to",opath
self.UpdatePage(os.path.join(self.cms.inpath,file),opath)

Here is what I get on my report:

Zaphod:Web:input:code:pbm:pbmdoc.xml Zaphod:Web:output
Updating Zaphod:Web:input:code:pbm:pbmdoc.xml to Zaphod:Web:input:code:pbm:pbmdoc.html
Zaphod:Web:input:code:webmenu:webmenudd.xml Zaphod:Web:output
Updating Zaphod:Web:input:code:webmenu:webmenudd.xml to Zaphod:Web:input:code:webmenu:webmenudd.html
SiteUpdater Report -- Processing Zaphod:Web:input:code:pbm:pbmdoc.xml...
...Done.
Processing Zaphod:Web:input:code:webmenu:webmenudd.xml...
...Done.

What's happening is that the html files are being written to the same
subdirectory as the xml input file sits. As far as I can see I should
get the same behaviour that I got in the Python interactive session. 
When I reverse the second line of the sample code to:

opath = os.path.join(self.cms.outpath,file)

My report comes out to:

Zaphod:Web:input:code:pbm:pbmdoc.xml Zaphod:Web:output
Updating Zaphod:Web:input:code:pbm:pbmdoc.xml to Zaphod:Web:input:code:pbm:pbmdoc.html
Zaphod:Web:input:code:webmenu:webmenudd.xml Zaphod:Web:output
Updating Zaphod:Web:input:code:webmenu:webmenudd.xml to Zaphod:Web:input:code:webmenu:webmenudd.html
SiteUpdater Report -- Processing Zaphod:Web:input:code:pbm:pbmdoc.xml...
...Done.
Processing Zaphod:Web:input:code:webmenu:webmenudd.xml...
...Done.

Hey, Now it's exhibiting the exact same behaviour as before. Earlier I
was getting every file to be output to Zaphod:Web:output.html,
overwriting the output file for every input file generated.

I'm obviously being blind to this problem. I'm running Python 2.2.2 on
Mac OS 9.1, which is the latest I have been able to get to run
successfully on this machine (all sorts of problems with 9.2 for some reason).

Can anyone spot what's going on here?

Thanks,
Josh English
english at spiritone.com



More information about the Pythonmac-SIG mailing list