bug in os.path.samefile (Python 1.5.1)?

Matej Cepl Cepl at fpm.cz
Mon Jun 7 11:32:05 CEST 1999


Hi,

trying to finish my port of sitemap.py (for original Sitemap.pl from ESR
see http://www.tuxedo.org/%7Eesr/sitemap-1.9.tar.gz for it), I am not
able to debug the attached procedure.

There is a huge dictionary, where key is abspath of the file and content
is list of some stuff to be pressented in the page. This procedure walks
through this dictionary (recursively) and make the writings into output
HTML.

Now, I need to check whether the processed file is in the "current"
directory or I should make steps to make recursive calling on another
directory. I guess, that the best way how to do it, is by calling
os.path.samefile(os.path.dirname(full_name),base) {see below for
context). However, Python 1.5.1 (I cannot use 1.5.2 not having
administrator's rights on WinNT 4.0 WK) complains by following report:
---------------------------
C:\Program Files\Python\Contrib\SiteMap>python report.py > neco.txt
Traceback (innermost last):
  File "report.py", line 121, in ?
    P = ReportPage(List,"","f:\\website\\",1)
  File "report.py", line 22, in __init__
    self.generate()
  File "html_page.py", line 44, in generate
    self.generate_body ()
  File "report.py", line 67, in generate_body
    if os.path.samefile(name,base):
  File "C:\Program Files\python\lib\ntpath.py", line 197, in samefile
    s2 = os.stat(f2)
os.error: (2, 'No such file or directory')
---------------------------

Do you have any idea, what's up (ntpath.samefile seems to be OK) and
what should I do (please, do not recommend me 1.5.2)?

			Thanks

				Matthew


---------------------------

    def generate_body(self,base="",curIndex=0):
        """
        prepare the list of all material in one directory and its
subdirectories
        """
        if base == "":
            base = string.lower(self.total_base)
        LCDir = len(base)
        Index = curIndex
        LenDict = len(self.klice)
        B = 1
        self.f.write("<b>" + base + "</b>\n")
        self.prlog("Base = " + base)
        self.f.write("<dl>\n")
        while ((Index + 1) <= LenDict) and B:
            full_name = string.lower(self.klice[Index])
            self.prlog("Full_name = " + full_name)
            name = os.path.dirname(full_name)
            self.prlog("Shortened name = " + name)
# THIS SEEMS TO BE A PROBLEM!!! ********
            if os.path.samefile(name,base):
                # there is not dirname in name, therefore we can
                # printout current file information
                filetitle = self.WholeDict[full_name][0]
                filedesc = self.WholeDict[full_name][1]
                if filetitle <> "":
                    self.f.write ("<dt><i>")
                    self.f.write ("<a href=\"" + full_name + "\">")
                    self.f.write (filetitle)
                    self.f.write ("</a></i></dt>\n")
                    self.f.write ("<dd>" + filedesc + "<br></dd>\n")
                Index = Index + 1
            else:
                # there is a dirname in a name
                next_base = string.lower(os.path.dirname(full_name))
                self.prlog("Next dir is " + next_base)
                self.f.write("</dl></li>\n")
                self.f.write ("<li>")
                self.generate_body(next_base,Index)
                B = 0




More information about the Python-list mailing list