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