source: cmtpacman/HEAD/scripts/create_kit.py @ 61

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

From CVS to SVN

File size: 7.9 KB
Line 
1
2# -*- coding: iso-8859-1 -*-
3
4import os
5import sys
6import string
7import popen2
8import stat
9import re
10import time
11from os import path
12import getopt
13import tempfile
14import signal
15import cmt
16
17tempprefix = ''
18tempfile1 = ''
19tempfile2 = ''
20tempcopydir = ''
21tempcmtusercontext = ''
22patch_requirements = ''
23
24release = ''
25cyclefile = ''
26patch_dir = ''
27minimal = False
28pacman_only = False
29platform = ''
30platform_suffix = ''
31override = False
32do_source_kit = False
33url = ''
34
35pacman_base = ''
36cache_dir = ''
37kits_dir = ''
38
39patch_requirements = ''
40
41here = ''
42
43cmt = cmt.CMT ()
44
45def get_project (cmtpath):
46    if cmtpath != '':
47        rr = os.path.basename (cmtpath)
48        pr = os.path.dirname (cmtpath)
49        pr = os.path.basename (pr)
50        return os.path.join (pr, rr)
51
52def cleanup ():
53    print 'Cleanup'
54    cmt.removedirs (tempprefix)
55
56def build_pacman (url, package, version, cmtpath, project_id, is_internal):
57    #print url, package, version, cmtpath, project_id, is_internal
58
59    source = '../kits'
60
61    # External packages (those with export_paths) are split into two kits:
62    # o The internal part, which follows the naming convention for internal packages
63    # o The external part, which only refers to the package version (no mention of
64    #   the project)
65
66    # Naming cnvention:
67    #  external packages : <package>-<version>-<platform>
68    #  internal packages : <projectid>/<package>-<platform>
69
70    if not is_internal:
71        # first build the pacman file for the external stuff
72
73        if native_version == None:
74            #vv=`echo ${version} | sed -e 's#'^${package}-'##'`
75            vv = ''
76        else:
77            vv = native_version
78            download_filename="${package}-${vv}${platform_suffix}"
79        download_filename = package + '-' + vv + platform_suffix
80
81        pacman_filename = download_filename + '.pacman'
82
83        print 'build_pacman> Create pacman file for external stuff ' + pacman_filename
84
85        pacman_file_version = get_pacman_file_version (os.path.join (cache_dir, pacman_filename))
86
87        #if test -f ${cache_dir}/${pacman_filename};  then
88        # mv ${cache_dir}/${pacman_filename} ${cache_dir}/${pacman_filename}.bak
89        # if test ! $? = 0; then
90        #   print 'create_kit> failed to rename ' + cache_dir + '/' + pacman_filename + ' to ' + cache_dir + '/' + pacman_filename' + '.bak'
91        # exit 1
92
93    # write pacman file
94
95
96
97    # end build_pacman
98
99def usage ():
100    print "Make a distribution kit for a CMT package"
101    print "Usage: create_kit.sh [ <option> ... ] <pacman-cache>"
102    print " where option can be:"
103    print "  -r|--release <release-id>  : specify the release id"
104    print "  -c|--cycles <cycles-file>  : specify the cycles file"
105    print "  -P|--patches <patch-dir>   : specify a directory for patches "
106    print "  -m|--minimal               : only store CMT files into the tar ball"
107    print "  -O|--pacman_only           : do not generate the tar ball"
108    print "  -p|--platform <platform>   : specify a platform suffix"
109    print "  -o|--override              : override the existing tar balls"
110    print "  -s|--source                : generate the source kit"
111    print "Typical/example usage:"
112    print "  cmt broadcast create_kit.sh -release 6.3.0 -cycles ${DEP}/cycles.txt /tmp "
113    # end usage
114
115#----------------------------------------------------
116# Main
117#----------------------------------------------------
118def main ():
119
120    print time.strftime ('%c')
121
122    pwd = os.getcwd ()
123
124    try:
125        opts, args = getopt.getopt (sys.argv[1:] , 'r:c:P:mOp:osu:', ['release=', 'cycles=', 'patches=', 'minimal', 'pacman_only', 'platform=', 'override', 'source', 'url='])
126
127    except getopt.GetoptError:
128        # print help information and exit:
129        usage()
130        sys.exit(2)
131
132    for o,a in opts:
133        if o in ('-r', '--release'):
134            release = a
135        if o in ('-c', '--cycles'):
136            cyclefile = a
137        if o in ('-P', '--patches'):
138            patch_dir = a
139        if o in ('-m', '--minimal'):
140            minimal = True
141        if o in ('-O', '--pacman_only'):
142            pacman_only = True
143        if o in ('-p', '--platform'):
144            platform = a
145        if o in ('-o', '--override'):
146            override = True
147        if o in ('-s', '--source'):
148            do_source_kit = True
149        if o in ('-u', '--url'):
150            url = a
151
152    for a in args:
153        pacman_base = os.path.normpath (a)
154        cache_dir = os.path.join (pacman_base, os.path.normpath ('cache'))
155        kits_dir = os.path.join (pacman_base, os.path.normpath ('kits'))
156
157    #---------------
158    # Prepare the target pacman cache
159    #
160
161    if not os.path.isdir (cache_dir):
162        print 'Creating ' + cache_dir
163        os.makedirs (cache_dir)
164
165    if not os.path.isdir (kits_dir):
166        print 'Creating ' + kits_dir
167        os.makedirs (kits_dir)
168
169    here = os.path.dirname (sys.argv[0])
170    if here == '':
171        here = os.getcwd ()
172
173    print 'here=' + here
174
175    #---------------
176    # Prepare temporary file management
177    #
178
179    #signal.signal (0, cleanup)
180    #signal.signal (1, cleanup)
181    #signal.signal (2, cleanup)
182    #signal.signal (15, cleanup)
183
184    tempprefix = 'CMT' + str(os.getpid ())
185    print 'tempprefix=' + tempprefix
186
187    tempfile1 = os.path.join (tempprefix, 't')
188    tempfile2 = os.path.join (tempprefix, 'u')
189    tempcopydir = os.path.join (tempprefix, 'c')
190    tempcmtusercontext = os.path.join (tempprefix, 'd')
191
192    cleanup ()
193
194    os.makedirs (tempprefix)
195
196    #---------------
197    # Prepare the CMT and package context
198    #
199
200    h = cmt.do ('show pwd')
201    root = os.path.dirname (h)
202
203    cmtversion = cmt.do ('version')
204
205    version = cmt.macro_value ('version')
206    if version == 'v*':
207        version = 'v1'
208
209    print 'cmtversion=' + cmtversion
210    print 'version' + version
211
212    package = cmt.macro_value ('package')
213    if package != '':
214        package = os.path.normpath (package)
215       
216    cmtpath = cmt.macro_value (package + '_cmtpath')
217    if cmtpath != '':
218        cmtpath = os.path.normpath (cmtpath)
219
220    offset = cmt.macro_value (package + '_offset')
221    if offset != '':
222        offset = os.path.normpath (offset)
223
224    print 'package=' + package
225    print 'cmtpath=' + cmtpath
226    print 'offset=' + offset
227
228    project = cmt.macro_value (package + '_project')
229    print 'package_project=' + project
230
231    release = cmt.macro_value (package + '_project_release')
232    print 'package_project_release=' + release
233   
234    print 'CMTPATH=' + cmt.macro_value ('CMTPATH')
235
236    if cmtpath == '':
237        cmtpath = os.path.normpath (cmt.macro_value (package + '_root'))
238        cmtpath = os.path.dirname (cmtpath)
239        cmtpath = os.path.dirname (cmtpath)
240
241    print '# Working on ' + package + ' ' + version + ' ' + offset + ' in ' + cmtpath + ' project ' + project + ' ' + release
242
243    cleanup ()
244    sys.exit (0)
245
246    #---------------
247    # Prepare the patch structure
248    #
249
250    if options.patch_dir != None:
251        if os.path.isdir (os.path.join (options.patch_dir, project_id)):
252            print 'create_kit> ' + options.patch_dir + '/' + project_id
253            os.makedirs (tempcmtusercontext)
254            os.putenv ('CMTUSERCONTEXT', tempcmtusercontext)
255            patch_requirements = os.path.join (tempcmtusercontext, os.path.normpath ('requirements'))
256            f = open (patch_requirements, 'w+')
257           
258    #---------------
259    # Prepare the detection of external packages
260    #
261
262    native_version = cmt.macro_value (package + '_native_version')
263    export_paths = cmt.macro_value (package + '_export_paths')
264
265    is_internal = export_paths == None
266
267    if options.do_source_kit:
268        is_internal = True
269           
270    #---------------
271    # Prepare the temporary copies
272    #
273
274    os.makedirs (tempcopydir)
275    copycmd = 'ln -s'
276
277    #---------------
278    # Generate the pacman file
279    #
280
281    build_pacman (options.url, package, version, cmtpath, project_id, is_internal)
282
283    #---------------
284    #
285    #
286
287    cleanup ()
288
289if __name__ == '__main__':
290    main()
291
Note: See TracBrowser for help on using the repository browser.