source: CMT/v1r18p20041201/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.2 KB
Line 
1
2import os
3import string
4import sys
5
6#---------------------------------------------------------------------
7#
8# This script should be installed within the loginfo file of CVS
9# using the following line :
10#
11# ...
12#.cmtcvsinfos $CVSROOT/CVSROOT/cmt_buildcvsinfos.sh
13# ...
14#
15# and is used whenever one tries to import a module named .cmtcvsinfos/<module>
16#
17#---------------------------------------------------------------------
18
19#---------------------------------------------------------------------
20def CVSROOT () :
21    e = os.environ ['CVSROOT']
22    pos = e.find (':')
23    if pos == 0 :
24        e = e[1:]
25        pos = e.find (':')
26        e = e[pos+1:]
27
28    return (e)
29#---------------------------------------------------------------------
30   
31#------------------------------------------------------------
32def remove_dir (d):
33    if not os.path.exists (d) : return
34   
35    for f in os.listdir(d) :
36        name = d + '/' + f
37        if os.path.isdir (name) : remove_dir (name)
38        else :
39            os.chmod (name, 0777)
40            os.remove (name)
41
42    os.rmdir (d)
43#------------------------------------------------------------
44
45#------------------------------------------------------------
46def check_head (head, version) :
47    hlist = head.split ('.')
48    vlist = version.split ('.')
49    i = 0
50    for h in hlist :
51        if h != vlist[i] : return 0
52        i = i + 1
53       
54    return 1
55#------------------------------------------------------------
56
57#------------------------------------------------------------
58#    test :  v1 newer then v2
59#
60def check_newer (v1, v2) :
61    list1 = v1.split ('.')
62    if len(list1) == 0 : return 0
63   
64    list2 = v2.split ('.')
65    i = 0
66    for h in list1 :
67        if i > len(list2) : return 1
68        if h > list2[i] : return 1
69        i = i + 1
70       
71    return 0
72#------------------------------------------------------------
73
74#------------------------------------------------------------
75def get_tags (module_file) :
76    if not os.path.isdir (module_file) : return ('')
77   
78    tags = ''
79    test_file = ''
80    if os.path.exists (module_file + '/cmt/requirements,v') :
81        test_file = module_file + '/cmt/requirements,v'
82    elif os.path.exists (module_file + '/mgr/requirements,v') :
83        test_file = module_file + '/mgr/requirements,v'
84    else :
85        for f in os.listdir (module_file) :
86            if f[-2:] == ',v' :
87                test_file = module_file + '/' + f
88                break;
89
90    if test_file == '' : return ('')
91
92    started = 0
93    finished = 0
94    top = ''
95    toptag = ''
96    cvstags = ''
97   
98    f = open (test_file, 'r')
99    while 1 :
100        line = f.readline ()
101        line = line [:-1]
102        if len (line) == 0 : break
103
104        if not started :
105            if line.find ('symbols') >= 0 :
106                started = 1
107                finished = 0
108                pos = line.find ('symbols')
109                line = line[pos+7:]
110               
111        if not finished :
112            if line.find ('locks;') >= 0 :
113                finished = 1
114                break
115            else :
116                line = line.strip ()
117                n = line.count ('.')
118                if n == 1 or n == 3 or n == 5 :
119                    pos = line.find (':')
120                    if pos >= 0 :
121                        v = line[pos+1:]
122                        tag = line[:pos]
123                        if check_newer (v, top) == 1 : top = v
124                        tags += tag + ' '
125                        cvstags += v + ' '
126   
127    taglist = tags.split ()
128    ts = cvstags.split ()
129    tags = ''
130    i = 0
131    for t in ts :
132        tags += taglist[i]
133        if top == t : tags += '(t)'
134        tags += ' '
135        i = i + 1
136
137    f.close ()
138
139    return (tags)
140#------------------------------------------------------------
141
142#------------------------------------------------------------
143def get_branches (module_file) :
144    if not os.path.isdir (module_file) : return ('')
145    branches = ''
146    for branch in os.listdir (module_file) :
147        if branch == 'Attic' : continue
148        branch_file = module_file + '/' + branch
149        if os.path.isdir (branch_file) :
150            if not os.path.exists (branch_file + '/cmt/requirements,v') :
151                if not os.path.exists (branch_file + '/mgr/requirements,v') :
152                    branches += branch + ' '
153
154    return (branches)
155#------------------------------------------------------------
156
157#------------------------------------------------------------
158def get_subpackages (module_file) :
159    if not os.path.isdir (module_file) : return ('')
160    subpackages = ''
161    for branch in os.listdir (module_file) :
162        if branch == 'Attic' : continue
163        branch_file = module_file + '/' + branch
164        if os.path.isdir (branch_file) :
165            if os.path.exists (branch_file + '/cmt/requirements,v') :
166                subpackages += branch + ' '
167            elif os.path.exists (branch_file + '/mgr/requirements,v') :
168                subpackages += branch + ' '
169               
170    return (subpackages)
171#------------------------------------------------------------
172
173if os.path.exists (CVSROOT() + '/.cmtcvsinfos') :
174    remove_dir (CVSROOT() + '/.cmtcvsinfos')
175
176a = raw_input ()
177
178root = CVSROOT ()
179
180print ('a=' + a)
181
182pos = a.find ('.cmtcvsinfos/')
183
184if pos == -1 :
185    print ('error=syntax error')
186    sys.exit (1)
187
188module = a[pos+len('.cmtcvsinfos/'):]
189
190print ('module=[' + module + ']')
191
192errormsg = ''
193
194module_file = CVSROOT () + '/' + module
195
196print ('module_file=[' + module_file + ']')
197
198if not os.path.isdir (module_file) :
199    errormsg = '### Module ' + module + ' not found.'
200   
201tags = get_tags (module_file)
202branches = get_branches (module_file)
203subpackages = get_subpackages (module_file)
204
205if errormsg != '' :
206    print ('error=' + errormsg)
207
208taglist = tags.split ()
209tags_top = ''
210tags = ''
211for t in taglist :
212    pos = t.find ('(t)')
213    if pos >= 0 :
214        tags_top += t[:pos] + ' '
215    else :
216        tags += t + ' '
217
218print ('tags_top=' + tags_top)
219print ('tags=' + tags)
220print ('branches=' + branches)
221print ('subpackages=' + subpackages)
222
223sys.exit (1)
224
225
226
227
Note: See TracBrowser for help on using the repository browser.