/[gentoo-src]/portage/pym/portage_file.py
Gentoo

Contents of /portage/pym/portage_file.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download) (as text)
Mon Mar 7 04:00:30 2005 UTC (9 years, 8 months ago) by ferringb
Branch: MAIN
CVS Tags: HEAD
Branch point for: portage_2_1
Changes since 1.4: +69 -12 lines
File MIME type: text/x-python
eclass_cache is now eclass_cache.py:cache, config is config.py:config.
Shifted support functions around as needed, left references in portage.py (from blah import) where relevant.

1 # portage_file.py -- general fs stuff. I think.
2 # Copyright 1998-2004 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo-src/portage/pym/portage_file.py,v 1.4 2005/02/26 06:35:20 jstubbs Exp $
5 cvs_id_string="$Id: portage_file.py,v 1.4 2005/02/26 06:35:20 jstubbs Exp $"[5:-2]
6
7 import os
8 import portage_data
9 import portage_exception
10 import orig_dict_cache
11 from portage_localization import _
12
13 def normpath(mypath):
14 newpath = os.path.normpath(mypath)
15 if len(newpath) > 1:
16 if newpath[:2] == "//":
17 newpath = newpath[1:]
18 return newpath
19
20
21 def makedirs(path, perms=0755, uid=None, gid=None, must_chown=False):
22 old_umask = os.umask(0)
23 if(uid == None):
24 uid = portage_data.portage_uid
25 if(gid == None):
26 gid = portage_data.portage_gid
27 if not path:
28 raise portage_exception.InvalidParameter, _("Invalid path: type: '%(type)s' value: '%(path)s'") % {"path": path, "type": type(path)}
29 if(perm > 1535) or (perm == 0):
30 raise portage_exception.InvalidParameter, _("Invalid permissions passed. Value is octal and no higher than 02777.")
31
32 mypath = normpath(path)
33 dirs = string.split(path, "/")
34
35 mypath = ""
36 if dirs and dirs[0] == "":
37 mypath = "/"
38 dirs = dirs[1:]
39 for x in dirs:
40 mypath += x+"/"
41 if not os.path.exists(mypath):
42 os.mkdir(mypath, perm)
43 try:
44 os.chown(mypath, uid, gid)
45 except SystemExit, e:
46 raise
47 except:
48 if must_chown:
49 os.umask(old_umask)
50 raise
51 portage_util.writemsg(_("Failed to chown: %(path)s to %(uid)s:%(gid)s\n") % {"path":mypath,"uid":uid,"gid":gid})
52
53 os.umask(old_umask)
54
55 def listdir(mypath, recursive=False, filesonly=False, ignorecvs=False, ignorelist=[],
56 followSymlinks=True, cacheObject=None):
57
58 if cacheObject:
59 cfunc = cacheObject.cacheddir
60 else:
61 cfunc = orig_dict_cache.cacheddir
62 try:
63 list, ftype = cfunc(mypath)
64 except SystemExit:
65 raise
66 except Exception:
67 return []
68
69 if list is None:
70 list=[]
71 if ftype is None:
72 ftype=[]
73
74 if ignorecvs or len(ignorelist):
75 x=0
76 while x < len(list):
77 #we're working with first level entries, no os.path.basename requirement
78 if (ignorecvs and (list[x] in ('CVS','.svn') or list[x].startswith(".#"))) and not \
79 list[x] in ignorelist:
80 list.pop(x)
81 ftype.pop(x)
82 continue
83 x += 1
84
85 if not filesonly and not recursive:
86 return list
87
88 if recursive:
89 x=0
90 while x<len(ftype):
91 b=os.path.basename(list[x])
92 # if it was cvs, it was filtered already.
93 if ftype[x] == 1 or (followSymlinks and ftype[x] == 3):
94
95 l,f = cfunc(mypath+"/"+list[x])
96
97 y=0
98 while y < len(l):
99 # use list comprehension here.
100 if not (ignorecvs and (l[y] in ('CVS','.svn') or l[y].startswith(".#"))) \
101 and not l[y] in ignorelist:
102 l[y]=list[x]+"/"+l[y]
103 y += 1
104 else:
105 l.pop(y)
106 f.pop(y)
107
108 list=list+l
109 ftype=ftype+f
110 x+=1
111 if filesonly:
112 rlist=[]
113 for x in range(0,len(ftype)):
114 if ftype[x]==0:
115 rlist=rlist+[list[x]]
116 else:
117 rlist=list
118
119 return rlist

  ViewVC Help
Powered by ViewVC 1.1.20