source: CMT/v1r10p20011126/mgr/cmt_buildcvsinfos.py @ 1

Last change on this file since 1 was 1, checked in by arnault, 19 years ago

Import all tags

File size: 6.4 KB
Line 
1
2
3import os
4
5import string
6
7import sys
8
9
10
11#---------------------------------------------------------------------
12
13#
14
15# This script should be installed within the loginfo file of CVS
16
17# using the following line :
18
19#
20
21# ...
22
23#.cmtcvsinfos $CVSROOT/CVSROOT/cmt_buildcvsinfos.sh
24
25# ...
26
27#
28
29# and is used whenever one tries to import a module named .cmtcvsinfos/<module>
30
31#
32
33#---------------------------------------------------------------------
34
35
36
37#---------------------------------------------------------------------
38
39def CVSROOT () :
40
41    e = os.environ ['CVSROOT']
42
43    pos = e.find (':')
44
45    if pos == 0 :
46
47        e = e[1:]
48
49        pos = e.find (':')
50
51        e = e[pos+1:]
52
53
54
55    return (e)
56
57#---------------------------------------------------------------------
58
59   
60
61#------------------------------------------------------------
62
63def remove_dir (d):
64
65    if not os.path.exists (d) : return
66
67   
68
69    for f in os.listdir(d) :
70
71        name = d + '/' + f
72
73        if os.path.isdir (name) : remove_dir (name)
74
75        else :
76
77            os.chmod (name, 0777)
78
79            os.remove (name)
80
81
82
83    os.rmdir (d)
84
85#------------------------------------------------------------
86
87
88
89#------------------------------------------------------------
90
91def check_head (head, version) :
92
93    hlist = head.split ('.')
94
95    vlist = version.split ('.')
96
97    i = 0
98
99    for h in hlist :
100
101        if h != vlist[i] : return 0
102
103        i = i + 1
104
105       
106
107    return 1
108
109#------------------------------------------------------------
110
111
112
113#------------------------------------------------------------
114
115#    test :  v1 newer then v2
116
117#
118
119def check_newer (v1, v2) :
120
121    list1 = v1.split ('.')
122
123    if len(list1) == 0 : return 0
124
125   
126
127    list2 = v2.split ('.')
128
129    i = 0
130
131    for h in list1 :
132
133        if i > len(list2) : return 1
134
135        if h > list2[i] : return 1
136
137        i = i + 1
138
139       
140
141    return 0
142
143#------------------------------------------------------------
144
145
146
147#------------------------------------------------------------
148
149def get_tags (module_file) :
150
151    if not os.path.isdir (module_file) : return ('')
152
153   
154
155    tags = ''
156
157    test_file = ''
158
159    if os.path.exists (module_file + '/cmt/requirements,v') :
160
161        test_file = module_file + '/cmt/requirements,v'
162
163    elif os.path.exists (module_file + '/mgr/requirements,v') :
164
165        test_file = module_file + '/mgr/requirements,v'
166
167    else :
168
169        for f in os.listdir (module_file) :
170
171            if f[-2:] == ',v' :
172
173                test_file = module_file + '/' + f
174
175                break;
176
177
178
179    if test_file == '' : return ('')
180
181
182
183    started = 0
184
185    finished = 0
186
187    top = ''
188
189    toptag = ''
190
191    cvstags = ''
192
193   
194
195    f = open (test_file, 'r')
196
197    while 1 :
198
199        line = f.readline ()
200
201        line = line [:-1]
202
203        if len (line) == 0 : break
204
205
206
207        if not started :
208
209            if line.find ('symbols') >= 0 :
210
211                started = 1
212
213                finished = 0
214
215                pos = line.find ('symbols')
216
217                line = line[pos+7:]
218
219               
220
221        if not finished :
222
223            if line.find ('locks;') >= 0 :
224
225                finished = 1
226
227                break
228
229            else :
230
231                line = line.strip ()
232
233                n = line.count ('.')
234
235                if n == 1 or n == 3 or n == 5 :
236
237                    pos = line.find (':')
238
239                    if pos >= 0 :
240
241                        v = line[pos+1:]
242
243                        tag = line[:pos]
244
245                        if check_newer (v, top) == 1 : top = v
246
247                        tags += tag + ' '
248
249                        cvstags += v + ' '
250
251   
252
253    taglist = tags.split ()
254
255    ts = cvstags.split ()
256
257    tags = ''
258
259    i = 0
260
261    for t in ts :
262
263        tags += taglist[i]
264
265        if top == t : tags += '(t)'
266
267        tags += ' '
268
269        i = i + 1
270
271
272
273    f.close ()
274
275
276
277    return (tags)
278
279#------------------------------------------------------------
280
281
282
283#------------------------------------------------------------
284
285def get_branches (module_file) :
286
287    if not os.path.isdir (module_file) : return ('')
288
289    branches = ''
290
291    for branch in os.listdir (module_file) :
292
293        if branch == 'Attic' : continue
294
295        branch_file = module_file + '/' + branch
296
297        if os.path.isdir (branch_file) :
298
299            if not os.path.exists (branch_file + '/cmt/requirements,v') :
300
301                if not os.path.exists (branch_file + '/mgr/requirements,v') :
302
303                    branches += branch + ' '
304
305
306
307    return (branches)
308
309#------------------------------------------------------------
310
311
312
313#------------------------------------------------------------
314
315def get_subpackages (module_file) :
316
317    if not os.path.isdir (module_file) : return ('')
318
319    subpackages = ''
320
321    for branch in os.listdir (module_file) :
322
323        if branch == 'Attic' : continue
324
325        branch_file = module_file + '/' + branch
326
327        if os.path.isdir (branch_file) :
328
329            if os.path.exists (branch_file + '/cmt/requirements,v') :
330
331                subpackages += branch + ' '
332
333            elif os.path.exists (branch_file + '/mgr/requirements,v') :
334
335                subpackages += branch + ' '
336
337               
338
339    return (subpackages)
340
341#------------------------------------------------------------
342
343
344
345if os.path.exists (CVSROOT() + '/.cmtcvsinfos') :
346
347    remove_dir (CVSROOT() + '/.cmtcvsinfos')
348
349
350
351a = raw_input ()
352
353
354
355root = CVSROOT ()
356
357
358
359print ('a=' + a)
360
361
362
363pos = a.find ('.cmtcvsinfos/')
364
365
366
367if pos == -1 :
368
369    print ('error=syntax error')
370
371    sys.exit (1)
372
373
374
375module = a[pos+len('.cmtcvsinfos/'):]
376
377
378
379print ('module=[' + module + ']')
380
381
382
383errormsg = ''
384
385
386
387module_file = CVSROOT () + '/' + module
388
389
390
391print ('module_file=[' + module_file + ']')
392
393
394
395if not os.path.isdir (module_file) :
396
397    errormsg = '### Module ' + module + ' not found.'
398
399   
400
401tags = get_tags (module_file)
402
403branches = get_branches (module_file)
404
405subpackages = get_subpackages (module_file)
406
407
408
409if errormsg != '' :
410
411    print ('error=' + errormsg)
412
413
414
415taglist = tags.split ()
416
417tags_top = ''
418
419tags = ''
420
421for t in taglist :
422
423    pos = t.find ('(t)')
424
425    if pos >= 0 :
426
427        tags_top += t[:pos] + ' '
428
429    else :
430
431        tags += t + ' '
432
433
434
435print ('tags_top=' + tags_top)
436
437print ('tags=' + tags)
438
439print ('branches=' + branches)
440
441print ('subpackages=' + subpackages)
442
443
444
445sys.exit (1)
446
447
448
449
450
451
452
453
454
Note: See TracBrowser for help on using the repository browser.