[Rest2web-develop] RE: File Bug
Brought to you by:
mjfoord
From: Andrew I. <and...@us...> - 2006-04-06 03:20:54
|
I love one-line fixes. Changed src = join(self.dir, filename, entry) to src = join(self.dir, entry) It appears that the filename value set the path to "index.txt/thefilename.ext" instead of just "thefilename.ext". Once I removed it, both the index and non-index pages copied files fine (so I did not need to change the other loop's src line). Andrew > -----Original Message----- > From: Fuzzyman [mailto:fuz...@vo...] > Sent: Tuesday, April 04, 2006 2:34 AM > To: res...@li...; Andrew Ittner > Subject: Re: File Bug > > > Hello Andrew, > > I would certainly appreciate your eyes in tracking down this bug. I > don't *think* it can be platform specific though, as there is no > platform specific code (I use platform independent functions from > ``os.path`` and ``shutil`` to do all the work). > > I can see where the bug is happening - for you it seems to be where the > location of the source file is determined. I've pasted the full code in > below - and explained the logic of the first part which determines the > source location. You could add in a print statement to see where it > thinks the source file *should be*, which will give us a clue as to what > is happening. > > The code exists twice (which means it ought to be turned into a method > of Processor). Once in the ``process`` method and once in the > ``processindex`` method. > > When rest2web starts, it changes the current directory to be the 'start' > directory (top level of the site directory tree). > > As it goes through the files, the current directory being worked on is > stored in ``self.dir`` (self being the processor instance). At the top > level directory the following is set in ``__init__``, ``self.dir = > os.curdir``. (Is it possible that this is the cause of the problem ?) > > Following code taken from - > http://rest2web.python-hosting.com/file/trunk/rest2web/restprocessor.py > - from the process method. > > # also copy files (from restindex) into same dir as target > for entry in restindex['file']: > src = join(self.dir, dirname(filename), entry) > ## XXX Add a ``print src`` here :-) > if not os.path.isfile(src): > print ('File "%s" referenced by file keyword missing.' % > entry) > continue > # > target_file_name = url2pathname(target) > targetfile = os.path.normpath(join( > self.target, self.dir, target_file_name)) > dest = join(dirname(targetfile), split(entry)[1]) > comparefile = os.path.normpath(join( > self.compare, self.dir, target_file_name)) > cmp = join(dirname(comparefile), split(entry)[1]) > if comparefiles(src, cmp): > print 'File "%s" identical, skipping.' % entry > continue > if not isdir(dirname(dest)): > os.makedirs(dirname(dest)) > print 'Copying "%s".' % entry > copy2(src, dest) # alias for shutil.copy2 > > I'll step through the code to explain the process. > > for entry in restindex['file']: > > restindex['file'] should be a list of all your file keywords from the > page being processed. > > > src = join(self.dir, dirname(filename), entry) > > ``join`` is an alias for ``os.path.join``. > > ``filename`` is the name of the file being processed. When we are > processing an index file, it could actually be a path relative to > ``self.dir`` if the ``index-file`` option is set. > > You were getting lots of ``File "..." referenced by file keyword > missing.`` errors - so this logic seems to be faulty ? > > If you add the print statement I suggest, then you should be able to > tell what is happening. I'm sure the solution is simple enough - but I > can't see it. > > Thanks > > Fuzzyman > http://www.voidspace.org.uk/python/index.shtml |