aboutsummaryrefslogtreecommitdiffstats
path: root/src/bus.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-05-17 15:04:49 +0200
committerMattias Andrée <maandree@operamail.com>2015-05-17 15:06:28 +0200
commit439121bd48c9f5366d962da30272b82dd31fd01f (patch)
tree2773a69aa16c16cc2d456fa828721bc484302ffc /src/bus.py
parentupdate poll (diff)
downloadpython-bus-439121bd48c9f5366d962da30272b82dd31fd01f.tar.gz
python-bus-439121bd48c9f5366d962da30272b82dd31fd01f.tar.bz2
python-bus-439121bd48c9f5366d962da30272b82dd31fd01f.tar.xz
Bus.chown can keep current owner or group + Bus.chmod can use a permission mask to keep or remove permissions
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/bus.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/bus.py b/src/bus.py
index dcc6e80..fd6257f 100644
--- a/src/bus.py
+++ b/src/bus.py
@@ -232,32 +232,50 @@ class Bus:
return message
- def chown(self, owner : int, group : int):
+ def chown(self, owner : int = None, group : int = None):
'''
Change the ownership of a bus
`os.stat` can be used of the bus's associated file to get the bus's ownership
- @param owner:int The user ID of the bus's new owner
- @param group:int The group ID of the bus's new group
+ @param owner:int? The user ID of the bus's new owner, if `None`, keep current
+ @param group:int? The group ID of the bus's new group, if `None`, keep current
'''
from native_bus import bus_chown_wrapped
+ if (owner is None) or (group is None):
+ from os import stat
+ attr = stat(self.pathname)
+ if owner is None: owner = attr.st_uid
+ if group is None: group = attr.st_gid
(r, e) = bus_chown_wrapped(self.pathname, owner, group)
if r == -1:
raise self.__oserror(e)
- def chmod(self, mode : int):
+ def chmod(self, mode : int, mask : int = None):
'''
Change the permissions for a bus
`os.stat` can be used of the bus's associated file to get the bus's permissions
- @param mode:int The permissions of the bus, any permission for a user implies
- full permissions for that user, except only the owner may
- edit the bus's associated file
+ @param mode:int The permissions of the bus, any permission for a user implies
+ full permissions for that user, except only the owner may
+ edit the bus's associated file
+ @param mask:int? Bits to clear before setting the bits in `mode`, if `None`,
+ all bits are cleared
'''
from native_bus import bus_chmod_wrapped
+ if mask is not None:
+ from os import stat
+ current = stat(self.pathname).st_mode
+ if current & 0o700: current |= 0o700
+ if current & 0o70: current |= 0o70
+ if current & 0o7: current |= 0o7
+ if mask & 0o700: mask |= 0o700
+ if mask & 0o70: mask |= 0o70
+ if mask & 0o7: mask |= 0o7
+ current &= ~mask
+ mode |= current
(r, e) = bus_chmod_wrapped(self.pathname, mode)
if r == -1:
raise self.__oserror(e)