summaryrefslogtreecommitdiff
path: root/shellutils.py
diff options
context:
space:
mode:
authorSylvain <syt@logilab.fr>2008-01-29 13:02:27 +0100
committerSylvain <syt@logilab.fr>2008-01-29 13:02:27 +0100
commita4c7486e5935b56427dcaa426f484e9d0d69e8f6 (patch)
tree21729ed94e8f54e024d46773866d3ca4de3f6710 /shellutils.py
parentc88a079d97c6ba7be40b09a37a1de5a57c8a106c (diff)
downloadlogilab-common-a4c7486e5935b56427dcaa426f484e9d0d69e8f6.tar.gz
shellutils: new chmod function
Diffstat (limited to 'shellutils.py')
-rw-r--r--shellutils.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/shellutils.py b/shellutils.py
index fb22358..892f54d 100644
--- a/shellutils.py
+++ b/shellutils.py
@@ -1,23 +1,26 @@
-# Copyright (c) 2003-2007 LOGILAB S.A. (Paris, FRANCE).
-# http://www.logilab.fr/ -- mailto:contact@logilab.fr
-
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
-
+#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
+#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
Some shell/term utilities, useful to write some python scripts instead of shell
scripts
+
+:author: Logilab
+:copyright: 2003-2008 LOGILAB S.A. (Paris, FRANCE)
+:contact: http://www.logilab.fr/ -- mailto:python-projects@logilab.org
"""
+__docformat__ = "restructuredtext en"
+
import os
import glob
import shutil
@@ -28,6 +31,30 @@ from os.path import exists, isdir, islink, basename, join, walk
from logilab.common import STD_BLACKLIST
+
+def chown(path, login=None, group=None):
+ """same as `os.chown` function but accepting user login or group name as
+ argument. If login or group is omitted, it's left unchanged.
+ """
+ if login is None:
+ uid = -1
+ else:
+ try:
+ uid = int(login)
+ except ValueError:
+ import pwd
+ uid = pwd.getpwname(login).pw_uid
+ if group is None:
+ gid = -1
+ else:
+ try:
+ gid = int(group)
+ except ValueError:
+ import grp
+ gid = grp.getgrname(group).gr_gid
+ os.chown(path, uid, gid)
+
+
def mv(source, destination, _action=shutil.move):
"""a shell like mv, supporting wildcards
"""