source: trunk/anuga_core/source/pypar_dist/create_release.py @ 8494

Last change on this file since 8494 was 8494, checked in by steve, 13 years ago

We are working on improvements to the parallel code which means we need to
add to the standard pypar distribution.

File size: 6.8 KB
Line 
1"""Create a release of pypar
2
3The release name will be compose of a major release code obtained from
4pypar.py as well as the subversion version number.
5For example
6
7pypar-2.0.2_39
8
9refers to pypar version 2.0.2 with subversion number 39.
10
11The release files will be store locally in ~ (home) and also
12copied to sourceforge where the release manager must log in
13and create the Release using the File Releases interface.
14
15This script assumes a Linux platform
16
17"""
18
19from os import sep, system, remove, popen, chdir, getcwd, listdir
20from os.path import join
21from tempfile import mktemp
22from sys import platform, stdout
23
24
25
26def get_revision_number():
27    """Get the version number of the SVN
28    NOTE: This requires that the command svn is on the system PATH
29    (simply aliasing svn to the binary will not work)
30    """
31
32    # Error msg
33    msg = 'Command "svn" is not '
34    msg += 'recognised on the system PATH.\n\n'
35    msg += 'Try to obtain the version info '
36    msg += 'by using the command: "svn info".\n'
37    msg += 'In this case, make sure svn is accessible on the system path. '
38    msg += 'Simply aliasing svn to the binary will not work. '
39     
40    try:
41        # The null stuff is so this section fails quitly.
42        # This could cause the svn info command to fail due to
43        # the redirection being bad on some platforms.
44        # If that occurs then change this code.
45        if platform[0:3] == 'win':
46            system('svn up')
47            fid = popen('svn info 2> null')
48        else:
49            system('svn up')           
50            fid = popen('svn info 2>/dev/null')
51       
52    except:
53        raise Exception(msg)
54    else:
55        #print 'Got version from svn'           
56        version_info = fid.read()
57     
58        if version_info == '':
59          raise Exception(msg)   
60        else:
61          pass
62          print 'Got version from file'
63
64           
65    for line in version_info.split('\n'):
66        if line.startswith('Revision:'):
67            break
68
69    fields = line.split(':')
70    msg = 'Keyword "Revision" was not found anywhere in text: %s'\
71          %version_info
72    assert fields[0].startswith('Revision'), msg           
73
74    try:
75        revision_number = int(fields[1])
76    except:
77        msg = 'Revision number must be an integer. I got %s' %fields[1]
78        msg += 'Check that the command svn is on the system path' 
79        raise Exception(msg)               
80       
81    return revision_number
82
83
84
85if __name__ == '__main__':
86 
87    if platform == 'win32':
88        msg = 'This script is not written for Windows.'+\
89              'Please run it on a Unix platform'
90        raise Exception, msg
91
92    # Get version number from file __metadat__
93    # This can't be imported because source is a package
94    # and mpiext needs to be compiled before anything can
95    # be imported.
96    # Instead we read it manually (until a better solution is found)
97
98    fid = open('source/__metadata__.py')
99    major_revision = None
100    for line in fid.readlines():
101        if line.startswith('__version__'):
102            i = line.find('=')
103            major_revision = str(line[i+1:].strip())[1:-1]
104           
105    if major_revision is None:
106        raise 'No version was found'
107
108   
109
110    # line separator
111    lsep = '----------------------------------------------------------------------'
112
113    # Get svn revision number and create
114    # file with version info for release.
115    # This will mean that the version currently checked out is
116    # the one which will be released.
117
118    svn_revision = get_revision_number()
119    revision = '%s_%s' %(major_revision, svn_revision)
120    print 'Creating pypar revision %s' %revision
121
122    distro_filename = 'pypar-%s.tgz' %revision
123
124   
125   
126    # Create area directory
127    release_name = 'pypar_%s' %revision
128    release_dir = '~/%s' %release_name
129    s = 'mkdir %s' %release_dir
130    try:
131        print s   
132        system(s)
133    except:
134        pass
135
136
137    # Export a clean directory tree from the working copy to a temporary dir
138    tmp_dir = mktemp()
139    s = 'mkdir %s' %tmp_dir
140    print s   
141    system(s)
142   
143    distro_dir = join(tmp_dir, release_name) 
144    s = 'mkdir %s' %distro_dir
145    print s   
146    system(s)   
147
148   
149   
150
151    #-----------------------------
152    # Get pypar source
153    s = 'svn export -r %d source %s/source' %(svn_revision,
154                                              distro_dir) 
155    print s
156    system(s)
157   
158    #-----------------------------
159    # Copy license file to top dir   
160    s = 'cp %s/source/LICENSE %s' %(distro_dir, distro_dir)     
161    print s
162    system(s)   
163   
164   
165    #-----------------------------
166    # Get demos
167    s = 'svn export -r %d demos %s/demos' %(svn_revision,
168                                            distro_dir) 
169    print s
170    system(s)
171
172   
173    #-----------------------------
174    # Get documentation
175    s = 'svn export -r %d documentation %s/documentation' %(svn_revision,
176                                                            distro_dir) 
177    print s
178    system(s)
179   
180
181
182    # Zip everything up
183    s = 'cd %s; tar cvfz %s *' %(tmp_dir, distro_filename)
184    print s
185    system(s)
186
187    # Move distro to release area
188    s = '/bin/mv %s/*.tgz %s' %(tmp_dir, release_dir) 
189    print s
190    system(s)
191
192    # Clean up
193    s = '/bin/rm -rf %s/pypar' %(tmp_dir) 
194    print s
195    system(s)
196
197
198    #-----------------------------
199
200    print 'Done'
201    print
202    print
203    print lsep
204    print 'The release files are in %s:' %release_dir
205    system('ls -la %s' %release_dir)
206    print lsep
207    print
208    print
209
210    answer = raw_input('Do you want to upload this to sourceforge? Y/N [Y]')
211    if answer.lower() != 'n':
212       
213        #------------------------------
214        print 'Uploading to sourceforge'
215
216
217        import os, os.path
218        release_dir = os.path.expanduser(release_dir)
219        os.chdir(release_dir)
220        print 'Reading from', os.getcwd()
221
222        s = 'rsync -avP -e ssh *.tgz uniomni@frs.sourceforge.net:uploads/'
223        print s
224        os.system(s)
225
226        #from ftplib import FTP
227        #ftp = FTP('upload.sourceforge.net')
228        #print ftp.login() # Anonymous
229        #print ftp.cwd('incoming')
230        #
231        #for filename in os.listdir('.'):
232        #    print 'Uploading %s... ' %filename,
233        #    stdout.flush()
234        #
235        #    fid=open(filename, 'rb')
236        #    print ftp.storbinary('STOR %s' %filename, fid)
237        #    fid.close()
238        #
239        #print 'FTP done'
240        #print ftp.quit()
241
242        print
243        print lsep
244        print '    ********************* NOTE *************************'
245        print lsep
246        print 'To complete this release you must log into'
247        print 'http://sourceforge.net/projects/pypar as admin'
248        print 'and complete the process by selecting File Releases '
249        print 'in the admin menu there.'
250        print lsep
251        print
252        print
253       
254
255
256
257
Note: See TracBrowser for help on using the repository browser.