source: sasview/sansview/build_sansview.py @ 3bc6090

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 3bc6090 was 3bc6090, checked in by Jae Cho <jhjcho@…>, 13 years ago

uses build number and date for build sansview in welcome and about

  • Property mode set to 100644
File size: 13.5 KB
Line 
1#
2# Script to get source from SVN and build SansView
3#
4# Read the release notes to make ensure that the required software is installed.
5#
6# SVN must be installed:
7# http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91
8#
9#
10# On Windows:
11#   - make sure svn.exe in on the path. You might need to log out and log back in again after installing SVN.
12#
13#   - Inno Setup must be installed
14#
15#   - py2exe must be installed
16#
17#   - mingw must be installed
18#
19# On Mac:
20#   - py2app must be installed
21#   - macholib must be installed to use py2app
22#   - modulegraph must be installed to use py2app
23#
24# Usage:
25# python build_sansview [command]
26# [command] can be any of the following:
27#   -h: lists the command line options
28#   -r: Builds a SansView using the released modules.
29#   -t: Builds SansView from the trubuild_sank.
30#   -i: Builds a Windows installer from the release version.
31#   -n: Print out the dependencies for the release notes
32
33import os
34import sys
35import shutil
36import logging
37
38# Installation folder
39import time
40timestamp = int(time.time())
41CWD    = os.getcwd()
42INSTALL_FOLDER = "install_%s" % str(timestamp)
43
44# On Windows, the python executable is not always on the path.
45# Use its most frequent location as the default.
46if sys.platform == 'win32':
47    PYTHON = "c:\python25\python"
48    LIB_FOLDER = "%s/%s" % (CWD, INSTALL_FOLDER)
49else:
50    PYTHON = 'python'
51
52logging.basicConfig(level=logging.INFO,
53                    format='%(asctime)s %(levelname)s %(message)s',
54                    filename='build_%s.log' % str(timestamp),
55                    filemode='w')
56
57SVN    = "svn"
58INNO   = "\"c:\Program Files\Inno Setup 5\ISCC\""
59
60# Release version 1.9
61SANSMODELS = "0.9.1"
62DATALOADER = "0.9"
63GUIFRAME   = "0.9.1"
64SANSVIEW   = "1.9.1"
65PLOTTOOLS  = "0.9.1"
66UTIL       = "0.9.1"
67PARK       = "1.2.1"
68PARK_INTEG = "0.9.1"
69PRVIEW     = "0.9.1"
70PR_INV     = "0.9"
71CALCULATOR = "0.9.1"
72CALC_VIEW  = "0.9"
73INVARIANT  = "0.9.1"
74INV_VIEW   = "0.9"
75FIT_VIEW   = "0.9.1"
76
77# URLs for SVN repos
78SANSMODELS_URL = "svn://danse.us/sans/releases/sansmodels-%s" % SANSMODELS
79DATALOADER_URL = "svn://danse.us/sans/releases/sansdataloader-%s" % DATALOADER
80GUIFRAME_URL = "svn://danse.us/sans/releases/sansguiframe-%s" % GUIFRAME
81PLOTTOOLS_URL = "svn://danse.us/common/releases/plottools-%s" % PLOTTOOLS
82UTIL_URL = "svn://danse.us/common/releases/util-%s" % UTIL
83SANSVIEW_URL = "svn://danse.us/sans/releases/sansview-%s" % SANSVIEW
84FIT_URL = "svn://danse.us/sans/releases/fittingview-%s" % FIT_VIEW
85PARK_INTEG_URL = "svn://danse.us/sans/releases/park_integration-%s" % PARK_INTEG
86PARK_URL = "svn://danse.us/park/releases/park-%s" % PARK
87PRVIEW_URL = "svn://danse.us/sans/releases/inversionview-%s" % PRVIEW
88PR_INV_URL = "svn://danse.us/sans/releases/pr_inversion-%s" % PR_INV
89CALC_URL = "svn://danse.us/sans/releases/sanscalculator-%s" % CALCULATOR
90CALC_VIEW_URL = "svn://danse.us/sans/releases/calculatorview-%s" % CALC_VIEW
91INV_URL = "svn://danse.us/sans/releases/sansinvariant-%s" % INVARIANT
92INV_VIEW_URL = "svn://danse.us/sans/releases/invariantview-%s" % INV_VIEW
93
94def check_system():
95    """
96        Checks that the system has the necessary modules.
97    """
98    try:
99        import wx
100    except:
101        logging.error("wxpython missing")
102   
103    try:
104        import matplotlib
105    except:
106        logging.error("matplotlib missing")
107       
108    try:
109        import numpy
110    except:
111        logging.error("numpy missing")
112       
113    try:
114        import scipy
115    except:
116        logging.error("scipy missing")
117
118    try:
119        import periodictable
120    except:
121        logging.error("periodictable missing")
122       
123    if os.system("gcc -dumpversion")==1:
124        logging.error("missing mingw")
125
126def install_pkg(install_dir, setup_dir, url):
127    """
128        Check a package out and install it
129       
130        @param install_dir: directory to put the code in
131        @param setup_dir: relative location of the setup.py script
132        @param url: URL of the SVN repo
133    """
134    print "PYTHON, LIB_FOLDER=====",PYTHON, LIB_FOLDER
135    logging.info("Installing %s" % url)
136    try:
137        if not os.path.isdir(install_dir):
138            os.mkdir(install_dir)
139        os.chdir(install_dir)
140        build_num = os.path.basename(os.getcwd())   
141        os.system("%s checkout -q %s" % (SVN, url))       
142        os.chdir(setup_dir)
143        if setup_dir.count('sansview') > 0:
144            conf_file = open('local_config.py', 'rw')
145            conf = conf_file.read()
146            conf = '__build__ = %s %s \n'% (build_num, time.localtime()) +\
147                     conf
148            conf_file.write(conf)
149            conf_file.close()
150            print "install_dir", build_num,'__build__ = %s %s \n'% (build_num, time.localtime())
151        if sys.platform == 'win32':
152            os.system("%s setup.py -q build -cmingw32" % PYTHON)
153            os.system("%s setup.py -q install --root \"%s\"" % (PYTHON, LIB_FOLDER))
154        else:
155            os.system("%s setup.py build" % PYTHON)
156            os.system("%s setup.py install --prefix ~/.local" % PYTHON)
157    except:
158        logging.error("Install failed for %s" % url)
159        logging.error(sys.exc_value)
160        raw_input("Press enter to continue\n")
161        sys.exit()
162   
163def checkout(release=False):
164    """
165        Check the SansView code out
166    """
167    wd = os.getcwd()
168   
169    os.chdir(wd)
170    if release:
171        install_pkg(".", "sansdataloader-%s" % DATALOADER, DATALOADER_URL)
172    else:
173        install_pkg(".", "sansdataloader", "svn://danse.us/sans/trunk/sansdataloader")
174   
175    os.chdir(wd)
176    if release:
177        install_pkg(".", "sansmodels-%s" % SANSMODELS, SANSMODELS_URL)
178    else:
179        install_pkg(".", "sansmodels", "svn://danse.us/sans/trunk/sansmodels")
180   
181    os.chdir(wd)
182    if release:
183        install_pkg(".", "sansguiframe-%s" % GUIFRAME, GUIFRAME_URL)
184    else:
185        install_pkg(".", "sansguiframe", "svn://danse.us/sans/trunk/sansguiframe")
186   
187    os.chdir(wd)
188    if release:
189        install_pkg(".", "plottools-%s" % PLOTTOOLS, PLOTTOOLS_URL)
190    else:
191        install_pkg(".", "plottools", "svn://danse.us/common/plottools")
192   
193    os.chdir(wd)
194    if release:
195        install_pkg(".", "util-%s" % UTIL, UTIL_URL)
196    else:
197        install_pkg(".", "util", "svn://danse.us/common/util")
198   
199    os.chdir(wd)
200    if release:
201        install_pkg(".", "park_integration-%s" % PARK_INTEG, PARK_INTEG_URL)
202    else:
203        install_pkg(".", "park_integration", "svn://danse.us/sans/trunk/park_integration")
204   
205    os.chdir(wd)
206    if release:
207        install_pkg(".", "inversionview-%s" % PRVIEW, PRVIEW_URL)
208    else:
209        install_pkg(".", "inversionview", "svn://danse.us/sans/trunk/inversionview")
210   
211    os.chdir(wd)
212    if release:
213        install_pkg(".", "pr_inversion-%s" % PR_INV, PR_INV_URL)
214    else:
215        install_pkg(".", "pr_inversion", "svn://danse.us/sans/trunk/pr_inversion")
216   
217    os.chdir(wd)
218    if release:
219        install_pkg(".", "sansinvariant-%s" % INVARIANT, INV_URL)
220    else:
221        install_pkg(".", "sansinvariant", "svn://danse.us/sans/trunk/sansinvariant")
222   
223    os.chdir(wd)
224    if release:
225        install_pkg(".", "invariantview-%s" % INV_VIEW, INV_VIEW_URL)
226    else:
227        install_pkg(".", "invariantview", "svn://danse.us/sans/trunk/invariantview")
228   
229    os.chdir(wd)
230    if release:
231        install_pkg(".", "calculatorview-%s" % CALC_VIEW, CALC_VIEW_URL)
232    else:
233        install_pkg(".", "calculatorview", "svn://danse.us/sans/trunk/calculatorview")
234   
235    os.chdir(wd)
236    if release:
237        install_pkg(".", "sanscalculator-%s" % CALCULATOR, CALC_URL)
238    else:
239        install_pkg(".", "sanscalculator", "svn://danse.us/sans/trunk/sanscalculator")
240
241
242    os.chdir(wd)
243    if release:
244        install_pkg(".", "park-%s" % PARK, PARK_URL)
245    else:
246        install_pkg(".", "park-1.2", "svn://danse.us/park/branches/park-1.2")
247       
248    os.chdir(wd)
249    if release:
250        install_pkg(".", "fittingview-%s" % FIT_VIEW, FIT_URL)
251    else:
252        install_pkg(".", "fittingview", "svn://danse.us/sans/trunk/fittingview")
253           
254    os.chdir(wd)
255    if release:
256        os.system("%s checkout -q %s" % (SVN, SANSVIEW_URL))
257    else:
258        os.system("%s checkout -q svn://danse.us/sans/trunk/sansview" % SVN)
259    # put build number to local_config
260    try:
261        build_num = os.path.basename(wd).split('_')[1] 
262        if sys.argv[1]=="-r":
263            sansview_folder = "sansview-%s" % (SANSVIEW) 
264        else:
265            sansview_folder = "sansview"   
266        os.chdir(sansview_folder)
267        if os.getcwd().count('sansview') > 0:
268            conf_file = open('local_config.py', 'r')
269            conf = ''
270            import datetime
271            for line in conf_file.readlines():
272                conf += line
273                if line.count('__version__'):
274                    conf += "__build__ = '%s-%s' \n"% (build_num, datetime.date.today())
275            conf_file.close()
276            conf_file = open('local_config.py', 'w')
277            conf_file.write(conf)
278            conf_file.close()
279    except:
280        pass
281    os.chdir(wd)
282   
283def prepare(wipeout = False):
284    """
285        Prepare the build
286       
287        @param wipeout: If True, the DANSE modules in the standard site-packages will be
288        removed to avoid conflicts.
289    """
290    # Remove existing libraries
291    if wipeout == True:
292        logging.info("Deleting DANSES modules in site-packages")
293        from distutils.sysconfig import get_python_lib
294        libdir = get_python_lib()
295        old_dirs = [os.path.join(libdir, 'danse'),
296                    os.path.join(libdir, 'data_util'),
297                    os.path.join(libdir, 'park'),
298                    os.path.join(libdir, 'sans'),
299                    ]
300        for d in old_dirs:
301            if os.path.isdir(d):
302                shutil.rmtree(d)
303       
304    # Create a fresh installation folder
305    if os.path.isdir(INSTALL_FOLDER):
306        shutil.rmtree(INSTALL_FOLDER)
307
308    os.mkdir(INSTALL_FOLDER)
309   
310    # Check that the dependencies are properly installed
311    check_system()   
312   
313    # Move to the installation folder
314    os.chdir(INSTALL_FOLDER)   
315
316def warning():
317    """
318        The build script will wipe out part of the site-packages.
319        Ask the user whether he wants to proceed.
320    """
321    print "WARNING!\n"
322    print "In order to build a clean version of SansView, this script"
323    print "deletes anything found under site-packages for the following"
324    print "modules:"
325    print "   - danse"
326    print "   - data_util"
327    print "   - DataLoader"
328    print "   - park"
329    print "   - sans"
330    print "   - sans_extension\n"
331    answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]")
332    return answer.upper()=="Y"
333       
334if __name__ == "__main__": 
335   
336    if len(sys.argv)==1:
337        # If there is no argument, build the installer
338        sys.argv.append("-i")
339       
340    if len(sys.argv)>1:
341        # Help
342        if sys.argv[1]=="-h":
343            print "Usage:"
344            print "    python build_sansview [command]\n"
345            print "[command] can be any of the following:"
346            print "    -h: lists the command line options"
347            print "    -r: Builds a SansView using the released modules"
348            print "    -t: Builds SansView from the trunk"
349            print "    -i: Builds an installer from the release version [Windows only]"       
350            print "    -n: Print out the dependencies for the release notes"
351        elif sys.argv[1]=="-n":
352            # Print out release URLs
353            print SANSMODELS_URL
354            print DATALOADER_URL
355            print GUIFRAME_URL
356            print PLOTTOOLS_URL
357            print UTIL_URL
358            print SANSVIEW_URL
359            print PARK_INTEG_URL
360            print PARK_URL
361            print PRVIEW
362            print PR_INV
363            print FIT_URL
364        else:
365            logging.info("Build script for SansView %s" % SANSVIEW)
366                   
367            # Prepare installation folder
368            prepare(warning())
369           
370            # Check the command line argument
371            if sys.argv[1]=="-t":
372                logging.info("Building trunk version")
373                checkout()
374            elif sys.argv[1]=="-r":
375                logging.info("Building release version")
376                checkout(True)
377            elif sys.argv[1]=="-i":
378                logging.info("Building release version")
379                checkout(True)
380                if sys.platform=='win32':
381                    logging.info("Building Windows installer from release version")
382                    os.chdir("sansview-%s" % (SANSVIEW))
383                    os.system("%s setup_exe.py py2exe --extrapath \"%s\python25\lib\site-packages\"" % (PYTHON, LIB_FOLDER))
384                    os.system("%s/Q installer.iss" % INNO)
385                    shutil.copy2(os.path.join("Output","setupSansView.exe"), 
386                                 os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp)))
387                elif sys.platform=='darwin':
388                    logging.info("Building Mac application from release version")
389                    os.chdir("sansview-%s" % (SANSVIEW))
390                    os.system("%s setup_mac.py py2app" % PYTHON)                   
391                   
392    raw_input("Press enter to continue\n")
393   
Note: See TracBrowser for help on using the repository browser.