Re: asyncio: setting file permissions of a Unix socket?

2014-10-27 Thread Michael Ströder
Martin wrote:
> I'm using the asyncio.Protocol interface to build a server which binds
> to a unix socket file.  I want other system users to connect to the
> unix socket, so to communicate with the server.
> 
> Where should I set the permissions of the file?

You should start the demon with a strict umask and set the permissions after
the socket is created.

Deriving from SocketServer.UnixStreamServer I'm overriding the server_bind()
method:

class MyServer(SocketServer.UnixStreamServer):
[..]
  def server_bind(self):
"""Override server_bind to set socket options."""
self.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
self.socket.settimeout(SOCKET_TIMEOUT)
try:
  os.unlink(self.server_address)
except OSError:
  if os.path.exists(self.server_address):
raise
SocketServer.UnixStreamServer.server_bind(self)
os.chmod(self.server_address,int(SOCKET_PERMISSIONS,8))
return # server_bind()

Ciao, Michael.

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


asyncio: setting file permissions of a Unix socket?

2014-10-27 Thread Martin
Hi! :)

I'm using the asyncio.Protocol interface to build a server which binds
to a unix socket file.  I want other system users to connect to the
unix socket, so to communicate with the server.

Where should I set the permissions of the file?

The problem is that the socket file is created when the programs
starts listening for the connections.  Because of this, I can't change
the file permission before a connection is made.  At the same time, a
connection can't happen because of the file permissions.

Currently, I workaround this with os.umask(0o000).  But I also want to
make other files later with default permissions.  So I have to revert
the umask, but where?  I can only do this in the client connection
code, which is out of place.

Bellow is what I've done.  Can you suggest a better way?  I wish to
avoid permission fixing code like os.umask() for every connection.
Maybe I shouldn't use asyncio.Protocol in the first place?

Thank you! :)

Example code:

#! /usr/bin/env python3

import os
import asyncio

class ExampleServer(asyncio.Protocol):
def __init__(self):
os.umask(0o002)# This is my workaround.  Can I avoid this?
# if not umask_restored: # An alternative workaround.
# os.umask(0o002)

def connection_made(self, transport):
self.transport = transport

def data_received(self, data):
print("Data: ", data)
self.transport.write(b"OK, bye!\n")
self.transport.close()


def main():
socket_filepath = "/tmp/example-server.socket"
loop = asyncio.get_event_loop()
server_coroutine = loop.create_unix_server(ExampleServer, socket_filepath)
server = loop.run_until_complete(server_coroutine)

os.umask(0o000) # This is my workaround.

try:
loop.run_forever()
except KeyboardInterrupt:
print("exit")
finally:
server.close()
loop.close()
os.remove(socket_filepath)


if __name__ == "__main__":
main()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Reading and setting file permissions programmatically

2009-06-17 Thread Kushal Kumaran
On Thu, Jun 18, 2009 at 2:05 AM, Cameron
Pulsford wrote:
> Sorry to flood the list but my google fu isn't up to par today I guess.
> Basically, is it possible to read the permissions on one file and then set
> the permissions of another file to the ones we just read? os.dup2 seemed
> like it would work but I might not be using it correctly.
> I know there is os.chmod, but I haven't found the equivalent to read
> permissions. Preferably this would work on unix and windows too.

shutil.copymode

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


Re: Reading and setting file permissions programmatically

2009-06-17 Thread MRAB

Cameron Pulsford wrote:

Sorry to flood the list but my google fu isn't up to par today I guess.

Basically, is it possible to read the permissions on one file and then 
set the permissions of another file to the ones we just read? os.dup2 
seemed like it would work but I might not be using it correctly.


I know there is os.chmod, but I haven't found the equivalent to read 
permissions. Preferably this would work on unix and windows too.



os.stat(path).st_mode
--
http://mail.python.org/mailman/listinfo/python-list


Reading and setting file permissions programmatically

2009-06-17 Thread Cameron Pulsford
Sorry to flood the list but my google fu isn't up to par today I guess.
Basically, is it possible to read the permissions on one file and then set
the permissions of another file to the ones we just read? os.dup2 seemed
like it would work but I might not be using it correctly.

I know there is os.chmod, but I haven't found the equivalent to read
permissions. Preferably this would work on unix and windows too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mailbox.mbox.add() also seems to set file permissions

2009-04-27 Thread tinnews
Aahz  wrote:
> In article ,
> Grant Edwards   wrote:
> >On 2009-04-25, tinn...@isbd.co.uk  wrote:
> >>
> >> Where should one report bugs/errors in python library classes?
> >
> >http://docs.python.org/bugs.html
> 
> That's for doc bugs; regular bugs go to bugs.python.org (which is
> currently down due to hardware problems).

No, it's a page that tells you how to report bugs, it directs you to
bugs.python.org which, as you say, is dead at the moment.

-- 
Chris Green

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


Re: mailbox.mbox.add() also seems to set file permissions

2009-04-26 Thread Aahz
In article ,
Grant Edwards   wrote:
>On 2009-04-25, tinn...@isbd.co.uk  wrote:
>>
>> Where should one report bugs/errors in python library classes?
>
>http://docs.python.org/bugs.html

That's for doc bugs; regular bugs go to bugs.python.org (which is
currently down due to hardware problems).
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
--
http://mail.python.org/mailman/listinfo/python-list


Re: mailbox.mbox.add() also seems to set file permissions

2009-04-25 Thread Grant Edwards
On 2009-04-25, tinn...@isbd.co.uk  wrote:

> Where should one report bugs/errors in python library classes?

http://docs.python.org/bugs.html

-- 
Grant Edwards   grante Yow! Gee, I feel kind of
  at   LIGHT in the head now,
   visi.comknowing I can't make my
   satellite dish PAYMENTS!
--
http://mail.python.org/mailman/listinfo/python-list


mailbox.mbox.add() also seems to set file permissions

2009-04-25 Thread tinnews
mailbox.mbox.add() has *another* 'quirk'.  When it adds a message to
an mbox file it seems to set the permissions to 0755 which is quite
wrong for mbox files.  I get the feeling that the mbox versions of the
functions are just bodged maildir ones.  If one was creating a maildir
it *might* make some sense setting to 0755.

Where should one report bugs/errors in python library classes?

-- 
Chris Green

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


Preserving file permissions with distutils

2009-01-14 Thread George Sakkis
I'm trying to use distutils to install some package data and
additional files, some of which may be executable. It turns out that
distutils does not preserve the permissions. Digging in the code,
there is the following comment on distutils/command/build_py:

# XXX copy_file by default preserves mode, which appears to be
the
# wrong thing to do: if a file is read-only in the working
# directory, we want it to be installed read/write so that the
next
# installation of the same module distribution can overwrite
it
# without problems.  (This might be a Unix-specific issue.)
Thus

If the only reason for not preserving the mode is ensuring it's read/
write, why not preserve the rest permissions and set the write flag
for the owner ? The comment continues:

# we turn off 'preserve_mode' when copying to the build
directory,
# since the build directory is supposed to be exactly what the
# installation will look like (ie. we preserve mode when
# installing).

But installing copies from the build dir which has forgotten the
original permissions, so there is no actual preservation! Am I reading
this wrong or should I submit a bug report ?

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


Re: Checking File permissions

2006-07-21 Thread Tal Einat

Anoop wrote:
> Hi All
>
> Please tell me how to check the existence of a file and the read
> permission to the file using python script
>
> Thanks for ur inputs
>
> Anoop

os.access(path, mode) does just this, check it out.

Cross-platform-ness isn't a problem, the docs say it is available for
Windows, Unix and Mac, and I've used it without a hitch on Win2k, WinXP
and various Linux and Unix platforms.

>>> help(os.access)
Help on built-in function access in module nt:

access(...)
access(path, mode) -> 1 if granted, 0 otherwise

Use the real uid/gid to test for access to a path.  Note that most
operations will use the effective uid/gid, therefore this routine
can
be used in a suid/sgid environment to test if the invoking user has
the
specified access to the path.  The mode argument can be F_OK to
test
existence, or the inclusive-OR of R_OK, W_OK, and X_OK.

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


Re: Checking File permissions

2006-07-20 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Anoop
wrote:

> Please tell me how to check the existence of a file and the read
> permission to the file using python script

Without knowing what your precise needs are, the best way is to open the
file and try to read from it. If that succeeds, then you've got read
access.

Checking permissions as a separate step from opening the file exposes your
code to a race condition where the permissions may be OK during the initial
check, but then change to deny access before the subsequent open.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking File permissions

2006-07-20 Thread Larry Bates
Note: You really don't have to post the same question
3 times (2 in response to yourself).

import os

if os.path.exists(pathname):
  

To see if a file is writeable:

import stat

def iswriteable(path):
mode=os.stat(path)[stat.ST_mode]
return bool(stat.S_IMODE(mode) & stat.S_IWRITE)


Larry Bates

Anoop wrote:
> Hi All
> 
> Please tell me how to check the existence of a file and the read
> permission to the file using python script
> 
> Thanks for ur inputs
> 
> Anoop
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking File permissions

2006-07-20 Thread Avell Diroll
Anoop wrote:
> Please tell me how to check the existence of a file and the read
> permission to the file using python script

You can check the os module (os.stat comes to mind).

For an exemple you can have a look at :
http://www.pixelbeat.org/talks/python/ls.py

Regards,

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


Checking File permissions

2006-07-20 Thread Anoop
Hi All

Please tell me how to check the existence of a file and the read
permission to the file using python script

Thanks for ur inputs

Anoop

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


Checking File permissions

2006-07-20 Thread Anoop
Hi All

Please tell me how to check the existence of a file and the read
permission to the file using python script

Thanks for ur inputs

Anoop

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


Checking File permissions

2006-07-20 Thread Anoop
Hi All

Please tell me how to check the existence of a file and the read
permission to the file using python script

Thanks for ur inputs

Anoop

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


Re: setting file permissions on a web server

2006-04-30 Thread Martin P. Hellwig
John Salerno wrote:


Most FTP servers do allow to use chmod in a ftp session, although you're 
client must support it. See for example a cli ftp client (and server) on 
FreeBSD.

> [EMAIL PROTECTED]:~$ ftp ftp.xs4all.nl
> Connected to ftp2.xs4all.nl.
> 220 XS4ALL ftpd DCLXVI
> Name (ftp.xs4all.nl:mhellwig):
> 331 Password required for mhellwig.
> Password:
> 230 User mhellwig logged in.
> Remote system type is UNIX.
> Using binary mode to transfer files.
> ftp> ls MHellwigCV_02_10_01.pdf
> 150 Opening ASCII mode data connection for file list
> --   1 mhellwig user   211102 May 19  2003 MHellwigCV_02_10_01.pdf
> 226 Transfer complete.
> ftp> chmod 400 MHellwigCV_02_10_01.pdf
> 200 SITE CHMOD command successful
> ftp> ls MHellwigCV_02_10_01.pdf
> 150 Opening ASCII mode data connection for file list
> -r   1 mhellwig user   211102 May 19  2003 MHellwigCV_02_10_01.pdf
> 226 Transfer complete.
> ftp>

See?

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


Re: setting file permissions on a web server

2006-04-30 Thread John Salerno
Daniel Nogradi wrote:

> This depends on your arrangements with your web server provider.
> Perhaps you are allowed to ssh into that machine, perhaps not, you
> need to ask your provider. In case you can use ssh, then you can log
> in with putty (an ssh client for windows, grab it from here:
> http://www.chiark.greenend.org.uk/~sgtatham/putty/) and you will have
> a command line on the server so you can run chmod there.

Turns out that my web hosting company provides ssh access on the next 
highest plan and up, but not mine. :)

Oh well, I think I'll explore FileZilla a little more and see if there's 
more of an automated way to do it than just right-clicking each file (or 
even right-clicking multiple files at once, if possible). It shouldn't 
be too big of a deal anyway, but I'm always after more automated ways to 
do things...call me lazy! :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setting file permissions on a web server

2006-04-30 Thread Kirk McDonald
Daniel Nogradi wrote:
> I have next to zero experience with windows but as far as I know
> windows doesn't have file permissions at all (anyone, please correct
> me if I'm wrong :)) so in windows land it doesn't make any sense to
> "change file permissions". Even if it has some sort of a notion of
> file permissions I wouldn't know how that gets translated into unix.

This is getting a little off-topic, I admit, but the NT-derived versions 
of Windows do indeed have file permissions. The Windows-equivalent of 
chmod (and chown) is cacls ("Change Access Control Lists"):

http://www.ss64.com/nt/cacls.html

In essence, each file has an owner and a list of other users and groups, 
who may each have "Full control" (meaning they can change permissions), 
read-only, write-only, read-write, or no access.

Windows 95 and its descendants don't have permissions any more than DOS 
does. (Except with respect to Windows network file-sharing.)

(Heh, I checked just before posting this and someone beat me to it. 
Here's my post anyway.) :-)

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


Re: setting file permissions on a web server

2006-04-30 Thread Edward Elliott
Daniel Nogradi wrote:
> I have next to zero experience with windows but as far as I know
> windows doesn't have file permissions at all (anyone, please correct
> me if I'm wrong :)) so in windows land it doesn't make any sense to
> "change file permissions". 

Actually Windows has a quite good permission scheme, with full owner/group
ACLs and granular permissions for read, write, append, delete, and several
others I can't recall.  The problem is no one uses them much.  The
manipulation tools are a pain, and developers routinely ignore them
(including Microsoft's own developers, although I hear they've gotten much
better lately).

> I guess so. But that's not a terribly big problem even if you can't
> use ssh. What I would do is write a script (in python of course :))
> that does the file permission changing and run that script over the
> web. Since this can have serious security implications my strategy 
> would be to place this script somewhere which is not reachable through
> the web and only relocate it to a web accessible directory when you
> want to run it over the web, and when you are done, you place it back
> to its secure location so nobody can reach it. 

You're right about the security concerns, but your solution sounds like more
trouble than it's worth.  With a bit more effort, you could write a local
python script that acts as an ftp client and applies permissions remotely. 
But why bother when a good ftp client already has that built-in (and is
much less likely to contain destructive bugs).

> You can find out how to
> write this script from http://docs.python.org/lib/os-file-dir.html

You're worried about security and you turn a novice with a scripting
language loose in the briar patch of unix permissions, on a remote server
no less?  And I thought I was sadistic! :)

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


Re: setting file permissions on a web server

2006-04-30 Thread Edward Elliott
John Salerno wrote:
> Thanks, but I'm still a little confused. Since I'm running Windows

You misplaced your period, it goes at the end of that line. ;)

> assume that I can't run the chmod line on my own computer. 

Sure you can, install cygwin.  chmod only affects files on your computer,
and won't alter the Windows permissions (which use a different scheme), but
you can do it.

> My web server 
> uses Unix, but is it possible for me to have access to a command line
> for the server? I didn't know that was possible for basic web hosting
> plans (I'm using 1and1 right now).

It is entirely possible (indeed, I don't know how most things would ever get
done without it).  Most basic hosting plans however don't provide shell
access.

> I suppose I could write a script that would set the permissions of all
> the files in a particular folder on my computer to 755, but is there a
> Windows equivalent command for chmod to do this? Or am I stuck having to
> do it on the server side?

1. Settings permissions on your computer won't do a thing.
2. There's probably a Windows-equiv of chmod for your own files, but it
won't affect files placed on another machine.
3. You're stuck having to do it on the server side.  Now a good ftp program
can automate this for you, but it's still your job, not the servers.

These sound like good questions for your hosting provider, or failing that,
google.

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


Re: setting file permissions on a web server

2006-04-30 Thread Daniel Nogradi
> > In short, chmod refers to local files so wherever you run it it will
> > refer to files on that machine. You run it simply by typing it in a
> > shell as a user who has privilage to perform the operatation, which
> > can mean you have to be an owner of the file but if you are root you
> > can do it in any case. Depending on your ftp, scp, http or whatever
> > method you use to transfer files the file permissions may or may not
> > change during the transfer. If permissions are kept intact you can
> > chmod on your local machine and then transfer, if they are not then
> > you transfer first and chmod on the server. When you transfer files
> > from a windows machine to *nix it again depends on the particular
> > method you choose how the permissions will be set.
>
> Thanks, but I'm still a little confused. Since I'm running Windows, I
> assume that I can't run the chmod line on my own computer.

Correct, chmod is a *nix command.

> My web server
> uses Unix, but is it possible for me to have access to a command line
> for the server?

This depends on your arrangements with your web server provider.
Perhaps you are allowed to ssh into that machine, perhaps not, you
need to ask your provider. In case you can use ssh, then you can log
in with putty (an ssh client for windows, grab it from here:
http://www.chiark.greenend.org.uk/~sgtatham/putty/) and you will have
a command line on the server so you can run chmod there.

> I didn't know that was possible for basic web hosting plans (I'm using 1and1 
> right now).

I have absolutely no experience with public web hosting but I guess
some might provide ssh-ing possibilities although I imagine most
don't.

> I suppose I could write a script that would set the permissions of all
> the files in a particular folder on my computer to 755, but is there a
> Windows equivalent command for chmod to do this?

I have next to zero experience with windows but as far as I know
windows doesn't have file permissions at all (anyone, please correct
me if I'm wrong :)) so in windows land it doesn't make any sense to
"change file permissions". Even if it has some sort of a notion of
file permissions I wouldn't know how that gets translated into unix.

> Or am I stuck having to do it on the server side?

I guess so. But that's not a terribly big problem even if you can't
use ssh. What I would do is write a script (in python of course :))
that does the file permission changing and run that script over the
web. Since this can have serious security implications my strategy
would be to place this script somewhere which is not reachable through
the web and only relocate it to a web accessible directory when you
want to run it over the web, and when you are done, you place it back
to its secure location so nobody can reach it. You can find out how to
write this script from http://docs.python.org/lib/os-file-dir.html

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


Re: setting file permissions on a web server

2006-04-30 Thread Diez B. Roggisch
> I suppose I could write a script that would set the permissions of all 
> the files in a particular folder on my computer to 755, but is there a 
> Windows equivalent command for chmod to do this? Or am I stuck having to 
> do it on the server side?

The chmod has to be executed on the machine the file resides on - aka 
the server. If your plan includes a ssh-account you can use that. 
Otherwise you might be able to create an ftplib-based script that will 
automate this over ftp.

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


Re: setting file permissions on a web server

2006-04-30 Thread John Salerno
Daniel Nogradi wrote:

> In short, chmod refers to local files so wherever you run it it will
> refer to files on that machine. You run it simply by typing it in a
> shell as a user who has privilage to perform the operatation, which
> can mean you have to be an owner of the file but if you are root you
> can do it in any case. Depending on your ftp, scp, http or whatever
> method you use to transfer files the file permissions may or may not
> change during the transfer. If permissions are kept intact you can
> chmod on your local machine and then transfer, if they are not then
> you transfer first and chmod on the server. When you transfer files
> from a windows machine to *nix it again depends on the particular
> method you choose how the permissions will be set.

Thanks, but I'm still a little confused. Since I'm running Windows, I 
assume that I can't run the chmod line on my own computer. My web server 
uses Unix, but is it possible for me to have access to a command line 
for the server? I didn't know that was possible for basic web hosting 
plans (I'm using 1and1 right now).

I suppose I could write a script that would set the permissions of all 
the files in a particular folder on my computer to 755, but is there a 
Windows equivalent command for chmod to do this? Or am I stuck having to 
do it on the server side?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setting file permissions on a web server

2006-04-30 Thread Daniel Nogradi
> I always read about how you need to set certain file permissions (for
> cgi files, for example), but it's never been clear to me *how* you do
> this. I know you can run the line
>
> chmod 755 scriptname.py
>
> but *where* do you run this? Is this done on your personal system, or on
> the server? What if you are using Windows? If it's done on the server,
> how do you do it?
>
> The only way I've figured out so far how to do this is to upload my cgi
> files to my server, then within my FTP program I right-click the file
> and change its permission number that way, but that seems an inefficient
> way to do it, especially having to do it each time.
>
> Is there a way to put the above line within the script perhaps, so that
> the script sets its permission automatically? Or do certain editors
> allow you to save files with a predetermined permission?
>
> Aside from my right-clicking method, I don't know how else to do it.

I guess this would be a good starting point:

http://www.linuxcommand.org/man_pages/chmod1.html

In short, chmod refers to local files so wherever you run it it will
refer to files on that machine. You run it simply by typing it in a
shell as a user who has privilage to perform the operatation, which
can mean you have to be an owner of the file but if you are root you
can do it in any case. Depending on your ftp, scp, http or whatever
method you use to transfer files the file permissions may or may not
change during the transfer. If permissions are kept intact you can
chmod on your local machine and then transfer, if they are not then
you transfer first and chmod on the server. When you transfer files
from a windows machine to *nix it again depends on the particular
method you choose how the permissions will be set.

There is no way of putting this permission information into the file
itself but some (most?) editors can be set to save the file with a
permission of your choice.

Hope this helps.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: setting file permissions on a web server

2006-04-30 Thread Rene Pijlman
John Salerno:
>I always read about how you need to set certain file permissions (for 
>cgi files, for example), but it's never been clear to me *how* you do 
>this. I know you can run the line
>
>chmod 755 scriptname.py
>
>but *where* do you run this? 

This is a Unix/Linux command. You run it in a shell login on the server
(e.g. in Putty, SecureCRT, or some other ssh client you're using).

>Is there a way to put the above line within the script perhaps, so that 
>the script sets its permission automatically?

Not in the script itself via cgi of course, because it needs certain
permissions before it can be run as cgi script. But you could put the
command in an installation script that installs the cgi script.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


setting file permissions on a web server

2006-04-29 Thread John Salerno
I always read about how you need to set certain file permissions (for 
cgi files, for example), but it's never been clear to me *how* you do 
this. I know you can run the line

chmod 755 scriptname.py

but *where* do you run this? Is this done on your personal system, or on 
the server? What if you are using Windows? If it's done on the server, 
how do you do it?

The only way I've figured out so far how to do this is to upload my cgi 
files to my server, then within my FTP program I right-click the file 
and change its permission number that way, but that seems an inefficient 
way to do it, especially having to do it each time.

Is there a way to put the above line within the script perhaps, so that 
the script sets its permission automatically? Or do certain editors 
allow you to save files with a predetermined permission?

Aside from my right-clicking method, I don't know how else to do it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Permissions

2006-03-18 Thread Christos Georgiou
On Fri, 10 Mar 2006 16:43:15 +0200, rumours say that Juho Schultz
<[EMAIL PROTECTED]> might have written:

>VJ wrote:
>> Hi All
>> 
>> Basically i want to write into a file .If the permissions are not there
>> then print a error message.
>> How do i achive this ???
>> 
>> Thanks,
>> VJ
 
>One way would be a try-except block, and leave the permission checking 
>error message generation, etc. to the operating system.
>
>try:
> outfile = file(outfilename,"w")
>except IOError, errormsg
> print "Could not write to file %s: %s" % (outfilename, errormsg)

As a word of caution: the OP is checking for the permissions of an
*existing* file.  Both Juho's and Sybren's suggestions *destroy* the file's
contents.

So, VJ, I'd suggest the following change:

Open the file for read write

outfile= open(outfilename, "r+b") # I assume binary

and later on catch errors in .write operations.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Permissions

2006-03-10 Thread Fredrik Lundh
"VJ" wrote:

> I need to get the user permission of a file using python. I was trying
> the following code which i found on google grups
>
>  st = os.stat(myfile)
> mode = st[stat.ST_MODE]
> if mode & stat.ST_IREAD:
> print "readable"
> if mode & stat.ST_IWRITE:
> print "writable"
> if mode & stat.ST_IEXEC:
> print "executable"
>
> I am getting a error saying
>
> " Traceback (most recent call last):
>   File "./test.py", line 23, in ?
> if mode & stat.ST_IREAD:
> AttributeError: 'module' object has no attribute 'ST_IREAD' "
>
> any idea how to resolve this error ??

fix your spelling:

>>> help(stat)
Help on module stat:
...

S_IREAD = 256
S_IRGRP = 32
S_IROTH = 4
S_IRUSR = 256
...

> Basically i want to write into a file .If the permissions are not there
> then print a error message.
> How do i achive this ???

that's an entirely different thing: if you want open a file and have that
operation fail if the file doesn't have the right permissions, open the file
and deal with any error you get:

try:
f = open(filename, mode)
except IOError, v:
... cannot open the file ...

or

try:
f = open(filename, mode)
except IOError, v:
import errno
if v.errno == errno.EPERM:
... wrong permissions ...
else:
raise # some other error; propagate

(note that there's nothing that guarantees that the permissions won't
change between a stat and a subsequent open, so the "look before you
leap" approach doesn't really work for operations against the file system)





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


Re: File Permissions

2006-03-10 Thread Sybren Stuvel
Sebastjan Trepca enlightened us with:
> Those constants are in stat module so add "import stat" before the
> program.

Yeah, but just opening the file is more Pythonic than first checking
if it can be opened in the first place.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Permissions

2006-03-10 Thread Juho Schultz
VJ wrote:
> Hi All
> 
> Basically i want to write into a file .If the permissions are not there
> then print a error message.
> How do i achive this ???
> 
> Thanks,
> VJ
> 

One way would be a try-except block, and leave the permission checking 
error message generation, etc. to the operating system.

try:
 outfile = file(outfilename,"w")
except IOError, errormsg
 print "Could not write to file %s: %s" % (outfilename, errormsg)

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


Re: File Permissions

2006-03-10 Thread Sybren Stuvel
VJ enlightened us with:
> Basically i want to write into a file .If the permissions are not
> there then print a error message.  How do i achive this ???

f = file('somefile', 'w')

then catch the exception that's thrown when it can't be done.

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File Permissions

2006-03-10 Thread Sebastjan Trepca
Those constants are in stat module so add "import stat" before the program.

On 10 Mar 2006 06:20:18 -0800, VJ <[EMAIL PROTECTED]> wrote:
> Hi All
>
> I need to get the user permission of a file using python. I was trying
> the following code which i found on google grups
>
>  st = os.stat(myfile)
> mode = st[stat.ST_MODE]
> if mode & stat.ST_IREAD:
> print "readable"
> if mode & stat.ST_IWRITE:
> print "writable"
> if mode & stat.ST_IEXEC:
> print "executable"
>
> I am getting a error saying
>
> " Traceback (most recent call last):
>   File "./test.py", line 23, in ?
> if mode & stat.ST_IREAD:
> AttributeError: 'module' object has no attribute 'ST_IREAD' "
>
> any idea how to resolve this error ??
>
> Basically i want to write into a file .If the permissions are not there
> then print a error message.
> How do i achive this ???
>
> Thanks,
> VJ
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


File Permissions

2006-03-10 Thread VJ
Hi All

I need to get the user permission of a file using python. I was trying
the following code which i found on google grups

 st = os.stat(myfile)
mode = st[stat.ST_MODE]
if mode & stat.ST_IREAD:
print "readable"
if mode & stat.ST_IWRITE:
print "writable"
if mode & stat.ST_IEXEC:
print "executable"

I am getting a error saying

" Traceback (most recent call last):
  File "./test.py", line 23, in ?
if mode & stat.ST_IREAD:
AttributeError: 'module' object has no attribute 'ST_IREAD' "

any idea how to resolve this error ??

Basically i want to write into a file .If the permissions are not there
then print a error message.
How do i achive this ???

Thanks,
VJ

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


Re: Getting File Permissions

2006-03-07 Thread Tim Chase
> Traceback (most recent call last):
>  File "", line 1, in ?
> NameError: name 'octal' is not defined
> 
> Since I am new to python, can any one help me to solve this error?

Looks like you just want the oct() function (not "octal()")

 >>> [x for x in dir(__builtins__) if x.lower().find("oct") 
!= -1]
['oct']

The __builtins__ will tell you what functions python 
supports natively, and you can query against this list for 
patterns, as done above.

-tkc







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


Re: Getting File Permissions

2006-03-07 Thread Juho Schultz
Hari wrote:
> Hi,
> For getting permissions of a file, the following script has been
> suggested in the same group
> 
> import os, stat
> st = os.stat(myfile)
> mode = st[stat.ST_MODE]
> print "mode is", octal(mode & 0777)
> 
> But while executing I am getting error message as follows
> 
> Traceback (most recent call last):
>  File "", line 1, in ?
> NameError: name 'octal' is not defined
> 
> Since I am new to python, can any one help me to solve this error?
> A bunch of thanks in advance.
> 
> Hari
> 

You can use "oct" instead of "octal".
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting File Permissions

2006-03-07 Thread Kent Johnson
Hari wrote:
> Hi,
> For getting permissions of a file, the following script has been
> suggested in the same group
> 
> import os, stat
> st = os.stat(myfile)
> mode = st[stat.ST_MODE]
> print "mode is", octal(mode & 0777)
> 
> But while executing I am getting error message as follows
> 
> Traceback (most recent call last):
>  File "", line 1, in ?
> NameError: name 'octal' is not defined

The correct name is oct(). The docs on built-in functions are helpful here:
http://docs.python.org/lib/built-in-funcs.html

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


Getting File Permissions

2006-03-07 Thread Hari
Hi,
For getting permissions of a file, the following script has been
suggested in the same group

import os, stat
st = os.stat(myfile)
mode = st[stat.ST_MODE]
print "mode is", octal(mode & 0777)

But while executing I am getting error message as follows

Traceback (most recent call last):
 File "", line 1, in ?
NameError: name 'octal' is not defined

Since I am new to python, can any one help me to solve this error?
A bunch of thanks in advance.

Hari

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


Re: File permissions script vs shell

2006-01-31 Thread jdlists
Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > I'm running python on windows and have a program that watches a
> > directory and acts on files as they come into the directory.  After
> > processing is complete, i delete the file, or in this case attempt
> > to
> >
> > In the script version I repeatedly get OSError exceptions stating
> > permission denied when trying to delete or rename
> >
> > My exception print out...
> > Files system said no: [Errno 13] Permission denied:
> > u'D:\\Data\\00-0C-41-DD-87-E5.xml'
> >
> > But i can go into the python shell and execute...
> >
> > fileString = 'D:\\Data\\00-0C-41-DD-87-E5.xml'
> > import os
> > os.unlink(fileString)
> >
> > and the file deletes fine
> >
> > Any ideas?  This is on my development windows xp box and i'm the only
> > user.
>
> did you close the file correctly after processing it ?
>
> >>> f = open("somefile.txt", "w")
> >>> import os
> >>> os.remove("somefile.txt")
> Traceback (most recent call last):
>   File "", line 1, in ?
> OSError: [Errno 13] Permission denied: 'somefile.txt'
> >>> f.close()
> >>> f = open("somefile.txt", "r")
> >>> os.remove("somefile.txt")
> Traceback (most recent call last):
>   File "", line 1, in ?
> OSError: [Errno 13] Permission denied: 'somefile.txt'
> >>> f.close()
> >>> os.remove("somefile.txt")
> >>>
>
> 

That was correct...i started to see it just after posting, the open
file was hidden behind the 4Suite library via the FromUri method.
Reading the xml file as a string and passing it to fromString instead
and closing the file myself solved this.

Jeff

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


Re: File permissions script vs shell

2006-01-31 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I'm running python on windows and have a program that watches a
> directory and acts on files as they come into the directory.  After
> processing is complete, i delete the file, or in this case attempt
> to
>
> In the script version I repeatedly get OSError exceptions stating
> permission denied when trying to delete or rename
>
> My exception print out...
> Files system said no: [Errno 13] Permission denied:
> u'D:\\Data\\00-0C-41-DD-87-E5.xml'
>
> But i can go into the python shell and execute...
>
> fileString = 'D:\\Data\\00-0C-41-DD-87-E5.xml'
> import os
> os.unlink(fileString)
>
> and the file deletes fine
>
> Any ideas?  This is on my development windows xp box and i'm the only
> user.

did you close the file correctly after processing it ?

>>> f = open("somefile.txt", "w")
>>> import os
>>> os.remove("somefile.txt")
Traceback (most recent call last):
  File "", line 1, in ?
OSError: [Errno 13] Permission denied: 'somefile.txt'
>>> f.close()
>>> f = open("somefile.txt", "r")
>>> os.remove("somefile.txt")
Traceback (most recent call last):
  File "", line 1, in ?
OSError: [Errno 13] Permission denied: 'somefile.txt'
>>> f.close()
>>> os.remove("somefile.txt")
>>>

 



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


File permissions script vs shell

2006-01-31 Thread jdlists
I'm running python on windows and have a program that watches a
directory and acts on files as they come into the directory.  After
processing is complete, i delete the file, or in this case attempt
to

In the script version I repeatedly get OSError exceptions stating
permission denied when trying to delete or rename

My exception print out...
Files system said no: [Errno 13] Permission denied:
u'D:\\Data\\00-0C-41-DD-87-E5.xml'

But i can go into the python shell and execute...

fileString = 'D:\\Data\\00-0C-41-DD-87-E5.xml'
import os
os.unlink(fileString)

and the file deletes fine

Any ideas?  This is on my development windows xp box and i'm the only
user.

Thanks
Jeff

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


Re: zipfile and file permissions

2006-01-23 Thread Pete Forman
Robert Kern <[EMAIL PROTECTED]> writes:

 > Pete Forman wrote:
>> I'm trying to move the building of a zip file from a shell script into
>> python.  It is mostly working but when I unzip the files the UNIX
>> permissions are not preserved.  The zip program I've been using is the
>> standard(?) one on Linux, from Info-Zip.  Presumably I need to do
>> something with external_attr in ZipInfo, any pointers?
>
 > C.f.: http://mail.python.org/pipermail/pythonmac-sig/2005-March/013491.html

Thanks.  I've put a work around in my code to set create_system.  I've
also made a patch for zipfile.py which I'm trying to submit to
sourceforge.  No luck so far, I'll try again later.  Recently I
submitted a patch to the python-mode project, so I think I'm following
the correct procedure.
-- 
Pete Forman-./\.-  Disclaimer: This post is originated
WesternGeco  -./\.-   by myself and does not represent
[EMAIL PROTECTED]-./\.-   opinion of Schlumberger, Baker
http://petef.port5.com   -./\.-   Hughes or their divisions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: zipfile and file permissions

2006-01-20 Thread Robert Kern
Pete Forman wrote:
> I'm trying to move the building of a zip file from a shell script into
> python.  It is mostly working but when I unzip the files the UNIX
> permissions are not preserved.  The zip program I've been using is the
> standard(?) one on Linux, from Info-Zip.  Presumably I need to do
> something with external_attr in ZipInfo, any pointers?

C.f.: http://mail.python.org/pipermail/pythonmac-sig/2005-March/013491.html

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


zipfile and file permissions

2006-01-20 Thread Pete Forman
I'm trying to move the building of a zip file from a shell script into
python.  It is mostly working but when I unzip the files the UNIX
permissions are not preserved.  The zip program I've been using is the
standard(?) one on Linux, from Info-Zip.  Presumably I need to do
something with external_attr in ZipInfo, any pointers?
-- 
Pete Forman-./\.-  Disclaimer: This post is originated
WesternGeco  -./\.-   by myself and does not represent
[EMAIL PROTECTED]-./\.-   opinion of Schlumberger, Baker
http://petef.port5.com   -./\.-   Hughes or their divisions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Getting TypeError in Changing file permissions

2005-07-22 Thread Peter Hansen
Benjamin Niemann wrote:
> Pranav Bagora wrote:
>>" os.chmod(outfile,0700)
>>TypeError: coercing to Unicode: need string or buffer,
>>file found"
> 
> Looks as if your are using a file object (that you got from an open() call)
> as the first parameter. What you need is a string with the path to the
> file.

Which this should do:

os.chmod(outfile.name, 0700)

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


Re: Getting TypeError in Changing file permissions

2005-07-22 Thread Jeff Epler
If you are using Unix, and all you have is the file object, you can use
os.fchmod(outfile.fileno(), 0700)

Jeff


pgp8U05e26RUt.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Getting TypeError in Changing file permissions

2005-07-22 Thread Benjamin Niemann
Pranav Bagora wrote:

> Hello ,
> i am trying to change mode of files using the
> os.chmod()function. But i am getting an error
> 
> " os.chmod(outfile,0700)
> TypeError: coercing to Unicode: need string or buffer,
> file found"

Looks as if your are using a file object (that you got from an open() call)
as the first parameter. What you need is a string with the path to the
file.

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting TypeError in Changing file permissions

2005-07-22 Thread Pranav Bagora
Hello ,
i am trying to change mode of files using the 
os.chmod()function. But i am getting an error 

" os.chmod(outfile,0700)
TypeError: coercing to Unicode: need string or buffer,
file found"

Please Help,
Pranav

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file permissions on windows XP (home)

2005-06-08 Thread Ivan Van Laningham
Hi All--

[EMAIL PROTECTED] wrote:
> 
> I have noticed a bug that if I have a folder open for viewing in
> Windows Explorer with Thumbnail view enabled that I often run into
> inexplicable problems with modify permissions, say when I want to
> rename or delete an item.  Changing the view to Detailed or rebooting
> seems to make the issue go away.
> 

Makes sense.  With the thumbnail view enabled, Windows has to monitor
every file in the directory for changes, and update the thumbs all the
time.  With other types it watches for changes, but it doesn't have to
be so obsessive about it.  Now that I think about it, the times that
I've had permission trouble it's always been with thumbs.

Not definitive, but worth looking out for.

Metta,
Ivan
--
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file permissions on windows XP (home)

2005-06-08 Thread gratzel
I have noticed a bug that if I have a folder open for viewing in
Windows Explorer with Thumbnail view enabled that I often run into
inexplicable problems with modify permissions, say when I want to
rename or delete an item.  Changing the view to Detailed or rebooting
seems to make the issue go away.

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


Re: file permissions on windows XP (home)

2005-06-08 Thread barney
Thanks, I will go the win32security.SetFileSecurity route. It seems a
pity that I can't use platform independant code to sort this out but I
guess you're saying that I've managed to get my files into a non
standard state that needs non standard code to sort it out. I wonder
how winamp/itunes manage to bypass it.

Barney

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


Re: file permissions on windows XP (home)

2005-06-08 Thread Duncan Booth
barney wrote:

> I realise that theses are windows rather than python issues but I would
> expect there would be some reliable way of changing the file
> permissions from within python. I'm updating ID3 tags in MP3 file to
> give some context. If I use something like winamp to make the change to
> the ID3 tag then the file is updated with no permission errors so there
> must be a way
> 
So it looks as though you have been using cygwin to set the file's access 
permissions and cygwin uses a complex mapping of unix's permission bits 
onto file security, whereas Python uses the more common, but incomplete 
mapping as implemented by the C runtime library.

The relationship between commands is that Python's chmod is equivalent to 
using the command line ATTRIB command, but Cygwin's chmod is equivalent to 
using both ATTRIB and CACLS.

I can think of three options open to you:

a) Let cygwin fix what cygwin broke:

   os.system('\\cygwin\\bin\\chmod u+rwx ' + filename)

b) Use cacls to fix it:

   os.system('cacls %s /P %s:F' % (filename, username))

c) Use win32security.SetFileSecurity()

See http://mail.python.org/pipermail/python-win32/2004-July/002111.html for 
a thread on using this api.

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


Re: file permissions on windows XP (home)

2005-06-07 Thread barney
Thanks,

I tried creating a test file but I get "Access is denied" from windows
explorer! The folder appears to be read only but when I try and uncheck
read only/apply/repopen the folder properties its still read only. This
read only flag seems to propagate down from the My Music directory but
unchecking it there also has no lasting effect.

I realise that theses are windows rather than python issues but I would
expect there would be some reliable way of changing the file
permissions from within python. I'm updating ID3 tags in MP3 file to
give some context. If I use something like winamp to make the change to
the ID3 tag then the file is updated with no permission errors so there
must be a way

I have added a stat call to the code which returns:

(33206, 0L, 2, 1, 0, 0, 4142103L, 1118176036, 920221388, 442057)

and this is the output of cacls (didn't know about this command):

C:\Users\Barney\My Music\U2\The Best Of 1980 - 1990 (US CD 1)\02 - New
Year's Day.mp3 XPHOME\Barney:(special access:)
STANDARD_RIGHTS_ALL
DELETE
READ_CONTROL
WRITE_DAC
WRITE_OWNER
SYNCHRONIZE
STANDARD_RIGHTS_REQUIRED
FILE_GENERIC_READ
FILE_READ_DATA
FILE_READ_EA
FILE_WRITE_EA
FILE_READ_ATTRIBUTES
FILE_WRITE_ATTRIBUTES

XPHOME\None:(special access:)
READ_CONTROL
SYNCHRONIZE
FILE_GENERIC_READ
FILE_READ_DATA
FILE_READ_EA
FILE_READ_ATTRIBUTES

Everyone:(special access:)
READ_CONTROL
SYNCHRONIZE
FILE_GENERIC_READ
FILE_READ_DATA
FILE_READ_EA
FILE_READ_ATTRIBUTES


I'm not entirely sure how to interpret these but will do some reading.
In the meantime if someone could show me some python to force the file
to be writeable that's all I really need at this stage.

Thanks
Barney

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


Re: file permissions on windows XP (home)

2005-06-07 Thread Duncan Booth
Peter Hansen wrote:

>> 
>> Why is python returing True from os.access?
>> Why isn't chmod doing anything?
> 
> Check your results using os.stat() after doing that, perhaps?  If it 
> shows the right values for the permissions, then clearly the problem has 
> nothing to do with Python per se, or your own code.
> 

And also remember that in windows the mode in os.chmod and os.stat is only 
loosely related to the actual permissions on the file. In particular there 
is a 'readonly' flag which is separate from whether any particular user 
or group has write access. The only way to tell whether you have access to 
a file in windows really is to try to open it and handle the exception.

Try using the properties panel, or the windows CACLS to display the 
security permissions on the file.

If you start with a plain file, then you and administrators probably have 
full access (CACLS will display 'your username:F'). If you use Python to 
set an access mode, it simply tries to toggle the attributes on the file 
itself. If you use Cygwin's chmod it will mess about with the security 
permissions in an attempt to get as close to the Unix file mode as it can, 
so your nice simple 'F' mode might become something truly horrendous:

Before:
C:\temp>cacls testfile.txt
C:\temp\testfile.txt BUILTIN\Administrators:F
 NT AUTHORITY\SYSTEM:F
 DELL5150\Duncan:F
 BUILTIN\Users:R

C:\temp>\cygwin\bin\chmod 744 testfile.txt

C:\temp>cacls testfile.txt
C:\temp\testfile.txt DELL5150\Duncan:(special access:)
 STANDARD_RIGHTS_ALL
 DELETE
 READ_CONTROL
 WRITE_DAC
 WRITE_OWNER
 SYNCHRONIZE
 STANDARD_RIGHTS_REQUIRED
 FILE_GENERIC_READ
 FILE_GENERIC_WRITE
 FILE_GENERIC_EXECUTE
 FILE_READ_DATA
 FILE_WRITE_DATA
 FILE_APPEND_DATA
 FILE_READ_EA
 FILE_WRITE_EA
 FILE_EXECUTE
 FILE_READ_ATTRIBUTES
 FILE_WRITE_ATTRIBUTES

 DELL5150\None:(special access:)
   READ_CONTROL
   SYNCHRONIZE
   FILE_GENERIC_READ
   FILE_READ_DATA
   FILE_READ_EA
   FILE_READ_ATTRIBUTES

 Everyone:(special access:)
  READ_CONTROL
  SYNCHRONIZE
  FILE_GENERIC_READ
  FILE_READ_DATA
  FILE_READ_EA
  FILE_READ_ATTRIBUTES

 BUILTIN\Administrators:F
 NT AUTHORITY\SYSTEM:F
 BUILTIN\Users:R

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


Re: file permissions on windows XP (home)

2005-06-07 Thread Peter Hansen
barney wrote (having trouble with a file):
[snip]
> IOError: [Errno 13] Permission denied: "02 - New Year's Day.mp3"
[snip]
> I'm at a loss to understand what is going on.
> 
> Why is python returing True from os.access?
> Why isn't chmod doing anything?

Check your results using os.stat() after doing that, perhaps?  If it 
shows the right values for the permissions, then clearly the problem has 
nothing to do with Python per se, or your own code.

> Why is cygwin able to sort the problem out?

I suggest (a) trying again, making sure that the file is not in use in 
another application such as the Media Player, and (b) trying with some 
other file that you've just created for the purpose of testing this to 
compare your results.

I just tried the whole sequence you showed without any problems, on a 
file called "test" that I created in my own My Music folder.  (Not using 
cygwin, however, since I don't use it, but in this case there was no 
need for me to use it anyway.)

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


file permissions on windows XP (home)

2005-06-06 Thread barney

I'm trying to write to an existing file under windows XP (home). The
files are in 'My Music' which I think may be treated in some special
way under XP. The relevant python code is as follows:

os.chdir(dir)
os.chmod(filename, 0744)
print "Okay to write = "+str(os.access(filename, os.W_OK))
afile = file(filename, 'r+b')

When I run this I get the following console output:

Okay to write = True
Traceback (most recent call last):
  File "c:\temp\eyed3-0.6.6\src\test.py", line 28, in ?
processFiles(root,files)
  File "c:\temp\eyed3-0.6.6\src\test.py", line 24, in processFiles
afile = file(filename, 'r+b')
IOError: [Errno 13] Permission denied: "02 - New Year's Day.mp3"

If I look at the files in explorer then the read only flag is not set.
If I change to cygwin and then do an ls -l I get something like:

-r--r--r--  1 Barney None 4142103 Feb 28  1999 02 - New Year's Day.mp3

If I do a chmod 644 from bash first then the python works fine?

I'm at a loss to understand what is going on.

Why is python returing True from os.access?
Why isn't chmod doing anything?
Why is cygwin able to sort the problem out?

Thanks
Barney

p.s. I'm using ActiveState Python 2.4

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


Re: CGI, anydbm.open() and linux file permissions

2005-01-11 Thread Dan Sommers
On Tue, 11 Jan 2005 15:16:53 -0800 (PST),
Derek Basch <[EMAIL PROTECTED]> wrote:

> Hello,
> I have a CGI script which uses anydb.open() to create a DBM. However I get 
> this
> traceback:

>  /usr/lib/python2.3/bsddb/__init__.py in
> hashopen(file='/var/www/bp/predictor/tools.dbm', flag='c', mode=438,
> pgsize=None, ffactor=None, nelem=None, cachesize=None, lorder=None, hflags=0)
>   190 if ffactor is not None:   d.set_h_ffactor(ffactor)
>   191 if nelem is not None: d.set_h_nelem(nelem)
>   192 d.open(file, db.DB_HASH, flags, mode)
>   193 return _DBWithCursor(d)
>   194 
> d = , d.open = , file =
> '/var/www/bp/predictor/tools.dbm', global db =  '/usr/lib/python2.3/lib-dynload/_bsddb.so'>, db.DB_HASH = 2, flags = 65, mode 
> =
> 438

> DBAccessError: (13, 'Permission denied')
>   args = (13, 'Permission denied')

> The permissions on the CGI script (/usr/lib/cgi-bin/evaluator.py) are:

> -rwxr-xr-x   1 bpeters bpeters  2446 Jan 11 14:42 evaluator.py

> and the permissions on the target DBM creation directory
> (/var/www/bp/predictor/) are:

> drwxr-xr-x  2 bpeters bpeters  4096 Jan 11 14:45 predictor

> Can anyone tell me what I need to do to allow the CGI script to create the DBM
> in the target directory? That is short of changing everything to root.

Chances are that for security reasons your script probably runs as user
"nobody" or another special user ID set up specifically for running CGI
scripts (rather than your user id).  Check your web server's
documentation, or render the output of sys.getuid, sys.geteuid,
sys.getgid, and sys.getedig.  One solution is to open up the permissions
of /var/www/bp/predictor; a better solution is to change its owner to
whatever user ID runs your script.

HTH,
Dan

-- 
Dan Sommers

Never play leapfrog with a unicorn.
-- 
http://mail.python.org/mailman/listinfo/python-list


CGI, anydbm.open() and linux file permissions

2005-01-11 Thread Derek Basch
Hello,

I have a CGI script which uses anydb.open() to create a DBM. However I get this
traceback:

 /usr/lib/python2.3/bsddb/__init__.py in
hashopen(file='/var/www/bp/predictor/tools.dbm', flag='c', mode=438,
pgsize=None, ffactor=None, nelem=None, cachesize=None, lorder=None, hflags=0)
  190 if ffactor is not None:   d.set_h_ffactor(ffactor)
  191 if nelem is not None: d.set_h_nelem(nelem)
  192 d.open(file, db.DB_HASH, flags, mode)
  193 return _DBWithCursor(d)
  194 
d = , d.open = , file =
'/var/www/bp/predictor/tools.dbm', global db = , db.DB_HASH = 2, flags = 65, mode =
438

DBAccessError: (13, 'Permission denied')
  args = (13, 'Permission denied')

The permissions on the CGI script (/usr/lib/cgi-bin/evaluator.py) are:

-rwxr-xr-x   1 bpeters bpeters  2446 Jan 11 14:42 evaluator.py

and the permissions on the target DBM creation directory
(/var/www/bp/predictor/) are:

drwxr-xr-x  2 bpeters bpeters  4096 Jan 11 14:45 predictor

Can anyone tell me what I need to do to allow the CGI script to create the DBM
in the target directory? That is short of changing everything to root.

Thanks everyone,
Derek Basch





__ 
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 
 

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