Mailing List Archive

easy filecopy? - JPython?
Aahz Maruch (aahz@netcom.com) wrote:
: Holger Jannsen <holger@phoenix-edv.netzservice.de> wrote:
: >For sure, I could write a thing like open-read-write-close...
: Look at the shutil module.

Copy, copyfile, copymode in shutil apparently haven't been implemented
under jpython. Any copy ideas for jpython (Unix, of course)?

Thanks!
Arielle
--
Arielle K. Masters: arielle@bigfoot.com; http://adams.patriot.net/~arielle/
Lucy dog: http://adams.patriot.net/~arielle/lucy/
Herndon Area Dog Coalition (HADC): http://adams.patriot.net/~arielle/hadc/
Genealogy: http://adams.patriot.net/~arielle/geneal/
easy filecopy? - JPython? [ In reply to ]
A.K. Masters, Frumious Bandersnatch writes:
> Copy, copyfile, copymode in shutil apparently haven't been implemented
> under jpython. Any copy ideas for jpython (Unix, of course)?

shutil.copyfile() works just fine (JPython 1.0.3 on java1.2), but
shutil.copymode() relies on os.chmod(), which isn't there. I'm sure
Barry Warsaw (bwarsaw@python.org) would love to receive a patch for
JPython to support that! ;-)


-Fred

--
Fred L. Drake, Jr. <fdrake@acm.org>
Corporation for National Research Initiatives
easy filecopy? - JPython? [ In reply to ]
Gordon McMillan writes:
> Last I recall (a while ago), os.chmod() doesn't work on Win9* and
> acts as a noop on WinNT under CPython. This might explain why the
> functionality isn't there in Java?

Gordon,
This certainly would make sense. The question becomes "If os.chmod
doesn't exist, should shutil.copy() fail?" I'm not at all sure what
the answer is, but I can see it going either way. shutil.copymode()
and shutil.copystat() should certainly fail, but it's not at all clear
that shutil.copy() should.
Someone more aware of the Java/JPython issues than myself should
make the call; I seem only to start up JPython when a thread like this
pops up. ;-)


-Fred

--
Fred L. Drake, Jr. <fdrake@acm.org>
Corporation for National Research Initiatives
easy filecopy? - JPython? [ In reply to ]
Fred Drake wrote:

> shutil.copyfile() works just fine (JPython 1.0.3 on java1.2), but
> shutil.copymode() relies on os.chmod(), which isn't there. I'm sure
> Barry Warsaw (bwarsaw@python.org) would love to receive a patch for
> JPython to support that! ;-)

Last I recall (a while ago), os.chmod() doesn't work on Win9* and
acts as a noop on WinNT under CPython. This might explain why the
functionality isn't there in Java?

- Gordon
easy filecopy? - JPython? [ In reply to ]
>>>>> "Fred" == Fred L Drake <fdrake@cnri.reston.va.us> writes:

Fred> shutil.copyfile() works just fine (JPython 1.0.3 on
Fred> java1.2), but shutil.copymode() relies on os.chmod(), which
Fred> isn't there. I'm sure Barry Warsaw (bwarsaw@python.org)
Fred> would love to receive a patch for JPython to support that!
Fred> ;-)

Probably not possible in 100% Java. If os.chmod() is really important
to you, then you should check out Finn Bock's JNI implementation of os
and posix.

http://pip.dknet.dk/~pip1848/jpython/Readme_jnios.html

-Barry
easy filecopy? - JPython? [ In reply to ]
>>>>> "Fred" == Fred L Drake <fdrake@cnri.reston.va.us> writes:

Fred> Gordon, This certainly would make sense. The question
Fred> becomes "If os.chmod doesn't exist, should shutil.copy()
Fred> fail?"

I'd say yes, because you can't guarantee the documented semantics,
i.e. that the permission bits are copied. However, shutil.copyfile()
shouldn't fail though -- and doesn't:

JPython 1.1beta1 on java1.2.1
Copyright (C) 1997-1999 Corporation for National Research Initiatives
>>> import shutil
>>> shutil.copy('/tmp/foo.txt', '/tmp/bar.txt')
Traceback (innermost last):
File "<console>", line 1, in ?
File "/home/bwarsaw/projects/python/pristine/Lib/shutil.py", line 53, in copy
File "/home/bwarsaw/projects/python/pristine/Lib/shutil.py", line 34, in copymode
AttributeError: class 'org.python.modules.os' has no attribute 'chmod'
>>> shutil.copyfile('/tmp/foo.txt', '/tmp/bar.txt')

If you had Finn Bock's jnios module (see my other msg in this thread),
then shutil.copymode() and hence shutil.copy() probably won't fail
because then you /would/ have os.chmod(). I haven't tested this
though...

-Barry