--- portage_file.py 2006-05-15 01:24:17.000000000 -0500 +++ /home/marduk/portage_file.py 2006-05-17 07:41:36.000000000 -0500 @@ -1,15 +1,20 @@ -# portage_data.py -- Calculated/Discovered Data Values -# Copyright 1998-2004 Gentoo Foundation +# portage_file.py -- Portage file handling utilities +# Copyright 1998-2006 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id: /var/cvsroot/gentoo-src/portage/pym/portage_file.py,v 1.3.2.1 2005/01/16 02:35:33 carpaski Exp $ +""" +Portage file handling utilities +""" import os import portage_data import portage_exception +import portage_util from portage_localization import _ def normpath(mypath): + """Normalize mypath""" newpath = os.path.normpath(mypath) if len(newpath) > 1: if newpath[:2] == "//": @@ -18,18 +23,21 @@ def makedirs(path, perms=0755, uid=None, gid=None, must_chown=False): + """ + Create directory tree with provided owner, group, and file permissions + """ old_umask = os.umask(0) if(uid is None): uid = portage_data.portage_uid if(gid is None): gid = portage_data.portage_gid if not path: - raise portage_exception.InvalidParameter, _("Invalid path: type: '%(type)s' value: '%(path)s'") % {"path": path, "type": type(path)} - if(perm > 1535) or (perm == 0): - raise portage_exception.InvalidParameter, _("Invalid permissions passed. Value is octal and no higher than 02777.") + raise portage_exception.IncorrectParameter, _("Invalid path: type: '%(type)s' value: '%(path)s'") % {"path": path, "type": type(path)} + if(perms > 1535) or (perms == 0): + raise portage_exception.IncorrectParameter, _("Invalid permissions passed. Value is octal and no higher than 02777.") mypath = normpath(path) - dirs = string.split(path, "/") + dirs = path.split('/') mypath = "" if dirs and dirs[0] == "": @@ -38,16 +46,16 @@ for x in dirs: mypath += x+"/" if not os.path.exists(mypath): - os.mkdir(mypath, perm) + os.mkdir(mypath, perms) try: os.chown(mypath, uid, gid) - except SystemExit, e: + except SystemExit: raise except: if must_chown: os.umask(old_umask) raise - portage_util.writemsg(_("Failed to chown: %(path)s to %(uid)s:%(gid)s\n") % {"path":mypath,"uid":uid,"gid":gid}) + portage_util.writemsg(_("Failed to chown: %(path)s to %(uid)s:%(gid)s\n") % {"path":mypath, "uid":uid, "gid":gid}) os.umask(old_umask)