Lines 1-15
Link Here
|
1 |
# portage_data.py -- Calculated/Discovered Data Values |
1 |
# portage_file.py -- Portage file handling utilities |
2 |
# Copyright 1998-2004 Gentoo Foundation |
2 |
# Copyright 1998-2006 Gentoo Foundation |
3 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# Distributed under the terms of the GNU General Public License v2 |
4 |
# $Id: /var/cvsroot/gentoo-src/portage/pym/portage_file.py,v 1.3.2.1 2005/01/16 02:35:33 carpaski Exp $ |
4 |
# $Id: /var/cvsroot/gentoo-src/portage/pym/portage_file.py,v 1.3.2.1 2005/01/16 02:35:33 carpaski Exp $ |
5 |
|
5 |
|
|
|
6 |
""" |
7 |
Portage file handling utilities |
8 |
""" |
6 |
|
9 |
|
7 |
import os |
10 |
import os |
8 |
import portage_data |
11 |
import portage_data |
9 |
import portage_exception |
12 |
import portage_exception |
|
|
13 |
import portage_util |
10 |
from portage_localization import _ |
14 |
from portage_localization import _ |
11 |
|
15 |
|
12 |
def normpath(mypath): |
16 |
def normpath(mypath): |
|
|
17 |
"""Normalize mypath""" |
13 |
newpath = os.path.normpath(mypath) |
18 |
newpath = os.path.normpath(mypath) |
14 |
if len(newpath) > 1: |
19 |
if len(newpath) > 1: |
15 |
if newpath[:2] == "//": |
20 |
if newpath[:2] == "//": |
Lines 18-35
Link Here
|
18 |
|
23 |
|
19 |
|
24 |
|
20 |
def makedirs(path, perms=0755, uid=None, gid=None, must_chown=False): |
25 |
def makedirs(path, perms=0755, uid=None, gid=None, must_chown=False): |
|
|
26 |
""" |
27 |
Create directory tree with provided owner, group, and file permissions |
28 |
""" |
21 |
old_umask = os.umask(0) |
29 |
old_umask = os.umask(0) |
22 |
if(uid is None): |
30 |
if(uid is None): |
23 |
uid = portage_data.portage_uid |
31 |
uid = portage_data.portage_uid |
24 |
if(gid is None): |
32 |
if(gid is None): |
25 |
gid = portage_data.portage_gid |
33 |
gid = portage_data.portage_gid |
26 |
if not path: |
34 |
if not path: |
27 |
raise portage_exception.InvalidParameter, _("Invalid path: type: '%(type)s' value: '%(path)s'") % {"path": path, "type": type(path)} |
35 |
raise portage_exception.IncorrectParameter, _("Invalid path: type: '%(type)s' value: '%(path)s'") % {"path": path, "type": type(path)} |
28 |
if(perm > 1535) or (perm == 0): |
36 |
if(perms > 1535) or (perms == 0): |
29 |
raise portage_exception.InvalidParameter, _("Invalid permissions passed. Value is octal and no higher than 02777.") |
37 |
raise portage_exception.IncorrectParameter, _("Invalid permissions passed. Value is octal and no higher than 02777.") |
30 |
|
38 |
|
31 |
mypath = normpath(path) |
39 |
mypath = normpath(path) |
32 |
dirs = string.split(path, "/") |
40 |
dirs = path.split('/') |
33 |
|
41 |
|
34 |
mypath = "" |
42 |
mypath = "" |
35 |
if dirs and dirs[0] == "": |
43 |
if dirs and dirs[0] == "": |
Lines 38-53
Link Here
|
38 |
for x in dirs: |
46 |
for x in dirs: |
39 |
mypath += x+"/" |
47 |
mypath += x+"/" |
40 |
if not os.path.exists(mypath): |
48 |
if not os.path.exists(mypath): |
41 |
os.mkdir(mypath, perm) |
49 |
os.mkdir(mypath, perms) |
42 |
try: |
50 |
try: |
43 |
os.chown(mypath, uid, gid) |
51 |
os.chown(mypath, uid, gid) |
44 |
except SystemExit, e: |
52 |
except SystemExit: |
45 |
raise |
53 |
raise |
46 |
except: |
54 |
except: |
47 |
if must_chown: |
55 |
if must_chown: |
48 |
os.umask(old_umask) |
56 |
os.umask(old_umask) |
49 |
raise |
57 |
raise |
50 |
portage_util.writemsg(_("Failed to chown: %(path)s to %(uid)s:%(gid)s\n") % {"path":mypath,"uid":uid,"gid":gid}) |
58 |
portage_util.writemsg(_("Failed to chown: %(path)s to %(uid)s:%(gid)s\n") % {"path":mypath, "uid":uid, "gid":gid}) |
51 |
|
59 |
|
52 |
os.umask(old_umask) |
60 |
os.umask(old_umask) |
53 |
|
61 |
|