This is what I (just now) put together as an example:

from os import stat,mknod,chown

def match_perms(org_fname,new_fname):
   # Get information on old file
   st = stat(org_fname)
   st_mode = st.st_mode
   st_uid = st.st_uid
   st_gid = st.st_gid

   # Create the new file
   mknod(new_fname,st_mode)

   # Matching permissions
   chown(new_fname,st_uid,st_gid)

if __name__ == "__main__":
   match_perms('old_filename','new_filename')

On 4/13/07, Kevin Kelley <[EMAIL PROTECTED]> wrote:

If you know what the permissions are going to be then you can use umask to
set the default file creation permissions to match. Then any files created
in that directory will have the correct permissions.

I think the "pythonic" way to solve this problem would be to code up your
own module which handles all the dirty parts in the background. It would
create the new file, stat the original, and chmod/chown the new file as
needed to match the original. All you would have to do after creating the
module is pass the new function the original and new file information.

--
Kevin Kelley

On 4/12/07, Paulo da Silva <[EMAIL PROTECTED]> wrote:
>
> [EMAIL PROTECTED] escreveu:
> > On Apr 12, 5:19 pm, [EMAIL PROTECTED] wrote:
> >> On Apr 12, 4:09 pm, Paulo da Silva <[EMAIL PROTECTED] >
> wrote:
> >>
> ...
> >
> > After poking around a bit I also discovered the
> > shutil module.  It looks like you can use
> > shutil.copy2.  More Pythonic, yes?
> >
>
>
> I have seen that in the index but I thought it was a different thing
> because it was referenced as "high-level operations".
> Anyway that helps but I still need to copy the whole file or to use stat
> and chown for the user/group ids.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to