[Pythonmac-SIG] macostools.copytree() problems...
Jack Jansen
jack@oratrix.nl
Fri, 15 Jun 2001 15:00:42 +0200
After looking at this for a long time I think I have a possible solution.
If NOVELL_SERVER:Home:User:Whatever exists, and let's say for sake of argument
that there's nothing in there at the moment, then it's OK to copy something
into NOVELL_SERVER:Home:User:Whatever:bla but it is NOT ok to copy something
into NOVELL_SERVER:Home:User:Whatever:bla:bletch. Or, in other words: copytree
will create the destination but it will not create the whole path leading up
to the destination.
You can use mkdirs to do this, something like this just before the copytree
call:
parent_d = os.path.split(d)[0]
macostools.mkdirs(parent_d)
But note that this is all from just thinking about the problem a bit, so it
could be wildly off.
PS: here's a tip: if you run this thing under the IDE you get a chance to
inspect the variables after the crash. If you can't run under the IDE for some
reason: <option>drag the script to PythonInterpreter, set the "interactive
mode after script" flag, run, watch it crash and at the >>> prompt do "import
pdb" and "pdb.pm()" and you're also able to inspect things. In your case
srcfss and dstfss should be interesting, both printed as-is and with
.as_pathname().
> f=open('backuplist', 'r+')
> str_list = f.readlines()
> backup_folder = 'NOVELL_SERVER:Home:User:Whatever'
>
> for s in str_list:
> s = re.sub('\n', '', s)
> if os.path.isdir(s):
> d = backup_folder + ':' + s
> # The above is just to recreate my HDD folder structure
> macostools.copytree(s, d)
>
> This does not work on any mac I've tried it on. I've suspected it may have
> something to do with the way I get rid of '\n' from each line in the file,
> or maybe that I'm missing some other special characters that are causing
> weird behaviors? Or perhaps my re.sub() is adding something?
> The error I get is as follows:
> File "system:applications:python 2.1:mac:lib:macostools.py", line 126,
> in copytree
> copy(src, dst, 1, copydates)
> File "system:applications:python 2.1:mac:lib:macostools.py", line 107,
> in copy
> df = dstfss.GetFInfo()
> Mac OS Error: (-43, 'File not found')
--
Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm