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

Contents of /portage/pym/cvstree.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations) (download) (as text)
Sat Feb 26 06:35:20 2005 UTC (9 years, 6 months ago) by jstubbs
Branch: MAIN
CVS Tags: HEAD
Branch point for: portage_2_1
Changes since 1.12: +2 -1 lines
File MIME type: text/x-python
Brought forward changes from portage_2_0

1 # cvstree.py -- cvs tree utilities
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/cvstree.py,v 1.12 2004/10/11 04:12:02 carpaski Exp $
5 cvs_id_string="$Id: cvstree.py,v 1.12.2.1 2005/01/16 02:35:33 carpaski Exp $"[5:-2]
6
7 import string,os,time,sys,re
8 from stat import *
9
10 # [D]/Name/Version/Date/Flags/Tags
11
12 def pathdata(entries, path):
13 """(entries,path)
14 Returns the data(dict) for a specific file/dir at the path specified."""
15 mysplit=string.split(path,"/")
16 myentries=entries
17 mytarget=mysplit[-1]
18 mysplit=mysplit[:-1]
19 for mys in mysplit:
20 if myentries["dirs"].has_key(mys):
21 myentries=myentries["dirs"][mys]
22 else:
23 return None
24 if myentries["dirs"].has_key(mytarget):
25 return myentries["dirs"][mytarget]
26 elif myentries["files"].has_key(mytarget):
27 return myentries["files"][mytarget]
28 else:
29 return None
30
31 def fileat(entries, path):
32 return pathdata(entries,path)
33
34 def isadded(entries, path):
35 """(entries,path)
36 Returns true if the path exists and is added to the cvs tree."""
37 mytarget=pathdata(entries, path)
38 if mytarget:
39 if "cvs" in mytarget["status"]:
40 return 1
41
42 basedir=os.path.dirname(path)
43 filename=os.path.basename(path)
44
45 try:
46 myfile=open(basedir+"/CVS/Entries","r")
47 except IOError:
48 return 0
49 mylines=myfile.readlines()
50 myfile.close()
51
52 rep=re.compile("^\/"+re.escape(filename)+"\/");
53 for x in mylines:
54 if rep.search(x):
55 return 1
56
57 return 0
58
59 def findnew(entries,recursive=0,basedir=""):
60 """(entries,recursive=0,basedir="")
61 Recurses the entries tree to find all elements that have been added but
62 have not yet been committed. Returns a list of paths, optionally prepended
63 with a basedir."""
64 if basedir and basedir[-1]!="/":
65 basedir=basedir+"/"
66 mylist=[]
67 for myfile in entries["files"].keys():
68 if "cvs" in entries["files"][myfile]["status"]:
69 if "0" == entries["files"][myfile]["revision"]:
70 mylist.append(basedir+myfile)
71 if recursive:
72 for mydir in entries["dirs"].keys():
73 mylist+=findnew(entries["dirs"][mydir],recursive,basedir+mydir)
74 return mylist
75
76 def findchanged(entries,recursive=0,basedir=""):
77 """(entries,recursive=0,basedir="")
78 Recurses the entries tree to find all elements that exist in the cvs tree
79 and differ from the committed version. Returns a list of paths, optionally
80 prepended with a basedir."""
81 if basedir and basedir[-1]!="/":
82 basedir=basedir+"/"
83 mylist=[]
84 for myfile in entries["files"].keys():
85 if "cvs" in entries["files"][myfile]["status"]:
86 if "current" not in entries["files"][myfile]["status"]:
87 if "exists" in entries["files"][myfile]["status"]:
88 if entries["files"][myfile]["revision"]!="0":
89 mylist.append(basedir+myfile)
90 if recursive:
91 for mydir in entries["dirs"].keys():
92 mylist+=findchanged(entries["dirs"][mydir],recursive,basedir+mydir)
93 return mylist
94
95 def findmissing(entries,recursive=0,basedir=""):
96 """(entries,recursive=0,basedir="")
97 Recurses the entries tree to find all elements that are listed in the cvs
98 tree but do not exist on the filesystem. Returns a list of paths,
99 optionally prepended with a basedir."""
100 if basedir and basedir[-1]!="/":
101 basedir=basedir+"/"
102 mylist=[]
103 for myfile in entries["files"].keys():
104 if "cvs" in entries["files"][myfile]["status"]:
105 if "exists" not in entries["files"][myfile]["status"]:
106 if "removed" not in entries["files"][myfile]["status"]:
107 mylist.append(basedir+myfile)
108 if recursive:
109 for mydir in entries["dirs"].keys():
110 mylist+=findmissing(entries["dirs"][mydir],recursive,basedir+mydir)
111 return mylist
112
113 def findunadded(entries,recursive=0,basedir=""):
114 """(entries,recursive=0,basedir="")
115 Recurses the entries tree to find all elements that are in valid cvs
116 directories but are not part of the cvs tree. Returns a list of paths,
117 optionally prepended with a basedir."""
118 if basedir and basedir[-1]!="/":
119 basedir=basedir+"/"
120 mylist=[]
121
122 #ignore what cvs ignores.
123 for myfile in entries["files"].keys():
124 if "cvs" not in entries["files"][myfile]["status"]:
125 mylist.append(basedir+myfile)
126 if recursive:
127 for mydir in entries["dirs"].keys():
128 mylist+=findunadded(entries["dirs"][mydir],recursive,basedir+mydir)
129 return mylist
130
131 def findremoved(entries,recursive=0,basedir=""):
132 """(entries,recursive=0,basedir="")
133 Recurses the entries tree to find all elements that are in flagged for cvs
134 deletions. Returns a list of paths, optionally prepended with a basedir."""
135 if basedir and basedir[-1]!="/":
136 basedir=basedir+"/"
137 mylist=[]
138 for myfile in entries["files"].keys():
139 if "removed" in entries["files"][myfile]["status"]:
140 mylist.append(basedir+myfile)
141 if recursive:
142 for mydir in entries["dirs"].keys():
143 mylist+=findremoved(entries["dirs"][mydir],recursive,basedir+mydir)
144 return mylist
145
146 def findall(entries, recursive=0, basedir=""):
147 """(entries,recursive=0,basedir="")
148 Recurses the entries tree to find all new, changed, missing, and unadded
149 entities. Returns a 4 element list of lists as returned from each find*()."""
150
151 if basedir and basedir[-1]!="/":
152 basedir=basedir+"/"
153 mynew = findnew(entries,recursive,basedir)
154 mychanged = findchanged(entries,recursive,basedir)
155 mymissing = findmissing(entries,recursive,basedir)
156 myunadded = findunadded(entries,recursive,basedir)
157 myremoved = findremoved(entries,recursive,basedir)
158 return [mynew, mychanged, mymissing, myunadded, myremoved]
159
160 ignore_list = re.compile("(^|/)(RCS(|LOG)|SCCS|CVS(|\.adm)|cvslog\..*|tags|TAGS|\.(make\.state|nse_depinfo)|.*~|(\.|)#.*|,.*|_$.*|.*\$|\.del-.*|.*\.(old|BAK|bak|orig|rej|a|olb|o|obj|so|exe|Z|elc|ln)|core)$")
161 def apply_cvsignore_filter(list):
162 x=0
163 while x < len(list):
164 if ignore_list.match(list[x].split("/")[-1]):
165 list.pop(x)
166 else:
167 x+=1
168 return list
169
170 def getentries(mydir,recursive=0):
171 """(basedir,recursive=0)
172 Scans the given directory and returns an datadict of all the entries in
173 the directory seperated as a dirs dict and a files dict."""
174 myfn=mydir+"/CVS/Entries"
175 # entries=[dirs, files]
176 entries={"dirs":{},"files":{}}
177 if not os.path.exists(mydir):
178 return entries
179 try:
180 myfile=open(myfn, "r")
181 mylines=myfile.readlines()
182 myfile.close()
183 except SystemExit, e:
184 raise
185 except:
186 mylines=[]
187 for line in mylines:
188 if line and line[-1]=="\n":
189 line=line[:-1]
190 if not line:
191 continue
192 if line=="D": # End of entries file
193 break
194 mysplit=string.split(line, "/")
195 if len(mysplit)!=6:
196 print "Confused:",mysplit
197 continue
198 if mysplit[0]=="D":
199 entries["dirs"][mysplit[1]]={"dirs":{},"files":{},"status":[]}
200 entries["dirs"][mysplit[1]]["status"]=["cvs"]
201 if os.path.isdir(mydir+"/"+mysplit[1]):
202 entries["dirs"][mysplit[1]]["status"]+=["exists"]
203 entries["dirs"][mysplit[1]]["flags"]=mysplit[2:]
204 if recursive:
205 rentries=getentries(mydir+"/"+mysplit[1],recursive)
206 #print rentries.keys()
207 #print entries["files"].keys()
208 #print entries["files"][mysplit[1]]
209 entries["dirs"][mysplit[1]]["dirs"]=rentries["dirs"]
210 entries["dirs"][mysplit[1]]["files"]=rentries["files"]
211 else:
212 # [D]/Name/revision/Date/Flags/Tags
213 entries["files"][mysplit[1]]={}
214 entries["files"][mysplit[1]]["revision"]=mysplit[2]
215 entries["files"][mysplit[1]]["date"]=mysplit[3]
216 entries["files"][mysplit[1]]["flags"]=mysplit[4]
217 entries["files"][mysplit[1]]["tags"]=mysplit[5]
218 entries["files"][mysplit[1]]["status"]=["cvs"]
219 if entries["files"][mysplit[1]]["revision"][0]=="-":
220 entries["files"][mysplit[1]]["status"]+=["removed"]
221
222 for file in apply_cvsignore_filter(os.listdir(mydir)):
223 if file=="CVS":
224 continue
225 if file=="digest-framerd-2.4.3":
226 print mydir,file
227 if os.path.isdir(mydir+"/"+file):
228 if not entries["dirs"].has_key(file):
229 entries["dirs"][file]={"dirs":{},"files":{}}
230 if entries["dirs"][file].has_key("status"):
231 if "exists" not in entries["dirs"][file]["status"]:
232 entries["dirs"][file]["status"]+=["exists"]
233 else:
234 entries["dirs"][file]["status"]=["exists"]
235 elif os.path.isfile(mydir+"/"+file):
236 if file=="digest-framerd-2.4.3":
237 print "isfile"
238 if not entries["files"].has_key(file):
239 entries["files"][file]={"revision":"","date":"","flags":"","tags":""}
240 if entries["files"][file].has_key("status"):
241 if file=="digest-framerd-2.4.3":
242 print "has status"
243 if "exists" not in entries["files"][file]["status"]:
244 if file=="digest-framerd-2.4.3":
245 print "no exists in status"
246 entries["files"][file]["status"]+=["exists"]
247 else:
248 if file=="digest-framerd-2.4.3":
249 print "no status"
250 entries["files"][file]["status"]=["exists"]
251 try:
252 if file=="digest-framerd-2.4.3":
253 print "stat'ing"
254 mystat=os.stat(mydir+"/"+file)
255 mytime=time.asctime(time.gmtime(mystat[ST_MTIME]))
256 if not entries["files"][file].has_key("status"):
257 if file=="digest-framerd-2.4.3":
258 print "status not set"
259 entries["files"][file]["status"]=[]
260 if file=="digest-framerd-2.4.3":
261 print "date:",entries["files"][file]["date"]
262 print "sdate:",mytime
263 if mytime==entries["files"][file]["date"]:
264 entries["files"][file]["status"]+=["current"]
265 if file=="digest-framerd-2.4.3":
266 print "stat done"
267
268 del mystat
269 except SystemExit, e:
270 raise
271 except Exception, e:
272 print "failed to stat",file
273 print e
274 return
275
276 else:
277 print
278 print "File of unknown type:",mydir+"/"+file
279 print
280 return entries
281
282 #class cvstree:
283 # def __init__(self,basedir):
284 # self.refdir=os.cwd()
285 # self.basedir=basedir
286 # self.entries={}
287 # self.entries["dirs"]={}
288 # self.entries["files"]={}
289 # self.entries["dirs"][self.basedir]=getentries(self.basedir)
290 # self.getrealdirs(self.dirs, self.files)
291 # def getrealdirs(self,dirs,files):
292 # for mydir in dirs.keys():
293 # list = os.listdir(
294
295

  ViewVC Help
Powered by ViewVC 1.1.20