[sysadmin-bin] ftpadmin: Add makedirs_chown function
- From: Olav Vitters <ovitters src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] ftpadmin: Add makedirs_chown function
- Date: Fri, 18 Mar 2011 18:29:15 +0000 (UTC)
commit 0813a2d4768d637cbf68d82d558cbc709dd6c24a
Author: Olav Vitters <olav vitters nl>
Date: Fri Mar 18 19:28:02 2011 +0100
ftpadmin: Add makedirs_chown function
Same as the os.makedirs function, but it will also change the
ownership of the newly created directories.
ftpadmin | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/ftpadmin b/ftpadmin
index 69061d6..b7c4f47 100755
--- a/ftpadmin
+++ b/ftpadmin
@@ -108,6 +108,24 @@ def human_size(size):
return fmt % (size/float(lim/2**10), suf)
+def makedirs_chown(name, mode=0777, uid=-1, gid=-1):
+ """Lake os.makedirs, but also does a chown
+ """
+ head, tail = os.path.split(name)
+ if not tail:
+ head, tail = os.path.split(head)
+ if head and tail and not os.path.exists(head):
+ try:
+ makedirs_chown(head, mode, uid, gid)
+ except OSError, e:
+ # be happy if someone already created the path
+ if e.errno != errno.EEXIST:
+ raise
+ if tail == os.path.curdir: # xxx/newdir/. exists if xxx/newdir exists
+ return
+ os.mkdir(name, mode)
+ os.chown(name, uid, gid)
+
class _LZMAProxy(object):
"""Small proxy class that enables external file object
support for "r:lzma" and "w:lzma" modes. This is actually
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]