R
ryniek90
I've got some code that checks priviliges on two paths:
First - chosen by user
Second - hardcoded home directory represented by **os.getenv('HOME')** -
(os.getenv('HOME') works both on Linux and Windows)
Here's the code:
"
def __check_set_perm(self, rd_obj_path, backup_dest):
try:
if os.path.exists(rd_obj_path):
if os.access(rd_obj_path, os.R_OK) != True:
print "Have no permissions on [%s] for reading
operation.\nTrying to set them..." % os.path.split(rd_obj_path)[1]
if not os.path.isdir(rd_obj_path):
os.chmod(rd_obj_path, stat.S_IREAD)
else:
for root, dirs, files in os.walk(rd_obj_path):
for f in files:
os.chmod(os.path.join(root, f),
stat.S_IREAD)
print "Get permissions for reading on [%s]
successfully." % os.path.split(rd_obj_path)[1]
else:
print "Have permissions on [%s] for reading." %
os.path.split(rd_obj_path)[1]
if os.access(backup_dest, os.W_OK) != True:
print "Have no permissions on [%s] for writing
operation.\nTrying to set them..." % os.path.split(backup_dest)[1]
os.chmod(backup_dest, stat.S_IWRITE)
print "Get permissions for reading on [%s]
successfully." % os.path.split(backup_dest)[1]
else:
print "Have permissions on [%s] for writing." %
os.path.split(backup_dest)[1]
else:
return "Can't find specified path - [%s]." % rd_obj_path
sys.exit(0)
except (Except), ex:
return ex
"
This code is part of my backup script. When script checks for reading
permission on 'user chosen path' it seems ok, but when it checks for
writing permissions on 'home directory', (this line: **if
os.access(backup_dest, os.W_OK) != True**), i get error:
**TypeError: coercing to Unicode: need string or buffer, NoneType found**
The second os.access check fails, but don't know why. When i turned
os.W_OK to integer, i get the same error.
But when changed os.W_OK or that int to string, i get error that integer
is required. I'm launching this code on WinXP Prof+SP3, on Administrator
account. Is it bug in os.acces() or my code is written wrong?
Btw. i kow that os.chmod in windows can set only read-olny flag, so
later i'll change the line with **os.chmod(path, stat.S_IWRITE)**
Thanks and cheers.
First - chosen by user
Second - hardcoded home directory represented by **os.getenv('HOME')** -
(os.getenv('HOME') works both on Linux and Windows)
Here's the code:
"
def __check_set_perm(self, rd_obj_path, backup_dest):
try:
if os.path.exists(rd_obj_path):
if os.access(rd_obj_path, os.R_OK) != True:
print "Have no permissions on [%s] for reading
operation.\nTrying to set them..." % os.path.split(rd_obj_path)[1]
if not os.path.isdir(rd_obj_path):
os.chmod(rd_obj_path, stat.S_IREAD)
else:
for root, dirs, files in os.walk(rd_obj_path):
for f in files:
os.chmod(os.path.join(root, f),
stat.S_IREAD)
print "Get permissions for reading on [%s]
successfully." % os.path.split(rd_obj_path)[1]
else:
print "Have permissions on [%s] for reading." %
os.path.split(rd_obj_path)[1]
if os.access(backup_dest, os.W_OK) != True:
print "Have no permissions on [%s] for writing
operation.\nTrying to set them..." % os.path.split(backup_dest)[1]
os.chmod(backup_dest, stat.S_IWRITE)
print "Get permissions for reading on [%s]
successfully." % os.path.split(backup_dest)[1]
else:
print "Have permissions on [%s] for writing." %
os.path.split(backup_dest)[1]
else:
return "Can't find specified path - [%s]." % rd_obj_path
sys.exit(0)
except (Except), ex:
return ex
"
This code is part of my backup script. When script checks for reading
permission on 'user chosen path' it seems ok, but when it checks for
writing permissions on 'home directory', (this line: **if
os.access(backup_dest, os.W_OK) != True**), i get error:
**TypeError: coercing to Unicode: need string or buffer, NoneType found**
The second os.access check fails, but don't know why. When i turned
os.W_OK to integer, i get the same error.
But when changed os.W_OK or that int to string, i get error that integer
is required. I'm launching this code on WinXP Prof+SP3, on Administrator
account. Is it bug in os.acces() or my code is written wrong?
Btw. i kow that os.chmod in windows can set only read-olny flag, so
later i'll change the line with **os.chmod(path, stat.S_IWRITE)**
Thanks and cheers.