source: sasview/sansview/build_sansview.py @ f5bdb4a

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 f5bdb4a was 36ec964, checked in by Jae Cho <jhjcho@…>, 14 years ago

new build

  • Property mode set to 100644
File size: 12.2 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.3.1
61SANSMODELS = "0.4.7"
62DATALOADER = "0.2.7"
63GUIFRAME   = "0.2.0"
64SANSVIEW   = "1.3.1"
65PLOTTOOLS  = "0.1.9"
66UTIL       = "0.1.5"
67PARK       = "1.2.1"
68PARK_INTEG = "0.1.5"
69PRVIEW     = "0.3.3"
70PR_INV     = "0.2.5"
71CALCULATOR = "0.1.1"
72CALC_VIEW  = "0.1.1"
73INVARIANT  = "0.1.1"
74INV_VIEW   = "0.1.1"
75ELEMENTS = "1.2"
76
77# URLs for SVN repos
78SANSMODELS_URL = "svn://danse.us/sans/releases/sansmodels-%s" % SANSMODELS
79DATALOADER_URL = "svn://danse.us/sans/releases/DataLoader-%s" % DATALOADER
80GUIFRAME_URL = "svn://danse.us/sans/releases/guiframe-%s" % GUIFRAME
81PLOTTOOLS_URL = "svn://danse.us/common/releases/plottools-%s/trunk" % PLOTTOOLS
82UTIL_URL = "svn://danse.us/common/releases/util-%s" % UTIL
83SANSVIEW_URL = "svn://danse.us/sans/releases/sansview-%s" % SANSVIEW
84PARK_INTEG_URL = "svn://danse.us/sans/releases/park_integration-%s" % PARK_INTEG
85PARK_URL = "svn://danse.us/park/releases/park-%s" % PARK
86PRVIEW_URL = "svn://danse.us/sans/releases/prview-%s" % PRVIEW
87PR_INV_URL = "svn://danse.us/sans/releases/pr_inversion-%s" % PR_INV
88CALC_URL = "svn://danse.us/sans/releases/calculator-%s" % CALCULATOR
89CALC_VIEW_URL = "svn://danse.us/sans/releases/calculatorview-%s" % CALC_VIEW
90INV_URL = "svn://danse.us/sans/releases/Invariant-%s" % INVARIANT
91INV_VIEW_URL = "svn://danse.us/sans/releases/invariantview-%s" % INV_VIEW
92ELEMENTS_URL = "svn://danse.us/common/elements/releases/elements-%s" % ELEMENTS
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    if os.system("gcc -dumpversion")==1:
119        logging.error("missing mingw")
120
121def install_pkg(install_dir, setup_dir, url):
122    """
123        Check a package out and install it
124       
125        @param install_dir: directory to put the code in
126        @param setup_dir: relative location of the setup.py script
127        @param url: URL of the SVN repo
128    """
129    logging.info("Installing %s" % url)
130    try:
131        if not os.path.isdir(install_dir):
132            os.mkdir(install_dir)
133        os.chdir(install_dir)   
134        os.system("%s checkout -q %s" % (SVN, url))       
135        os.chdir(setup_dir)
136        if sys.platform == 'win32':
137            os.system("%s setup.py -q build -cmingw32" % PYTHON)
138            os.system("%s setup.py -q install --root \"%s\"" % (PYTHON, LIB_FOLDER))
139        else:
140            os.system("%s setup.py build" % PYTHON)
141            os.system("%s setup.py install --prefix ~/.local" % PYTHON)
142    except:
143        logging.error("Install failed for %s" % url)
144        logging.error(sys.exc_value)
145        raw_input("Press enter to continue\n")
146        sys.exit()
147   
148def checkout(release=False):
149    """
150        Check the SansView code out
151    """
152    wd = os.getcwd()
153   
154    os.chdir(wd)
155    if release:
156        install_pkg(".", "DataLoader-%s" % DATALOADER, DATALOADER_URL)
157    else:
158        install_pkg(".", "DataLoader", "svn://danse.us/sans/trunk/DataLoader")
159   
160    os.chdir(wd)
161    if release:
162        install_pkg(".", "sansmodels-%s/src" % SANSMODELS, SANSMODELS_URL)
163    else:
164        install_pkg(".", "sansmodels/src", "svn://danse.us/sans/trunk/sansmodels")
165   
166    os.chdir(wd)
167    if release:
168        install_pkg(".", "guiframe-%s" % GUIFRAME, GUIFRAME_URL)
169    else:
170        install_pkg(".", "guiframe", "svn://danse.us/sans/trunk/guiframe")
171   
172    os.chdir(wd)
173    if release:
174        install_pkg("plottools-%s" % PLOTTOOLS, "trunk", PLOTTOOLS_URL)
175    else:
176        install_pkg("plottools", "trunk", "svn://danse.us/common/plottools/trunk")
177   
178    os.chdir(wd)
179    if release:
180        install_pkg(".", "util-%s" % UTIL, UTIL_URL)
181    else:
182        install_pkg(".", "util", "svn://danse.us/common/util")
183   
184    os.chdir(wd)
185    if release:
186        install_pkg(".", "park_integration-%s" % PARK_INTEG, PARK_INTEG_URL)
187    else:
188        install_pkg(".", "park_integration", "svn://danse.us/sans/trunk/park_integration")
189   
190    os.chdir(wd)
191    if release:
192        install_pkg(".", "prview-%s" % PRVIEW, PRVIEW_URL)
193    else:
194        install_pkg(".", "prview", "svn://danse.us/sans/trunk/prview")
195   
196    os.chdir(wd)
197    if release:
198        install_pkg(".", "pr_inversion-%s" % PR_INV, PR_INV_URL)
199    else:
200        install_pkg(".", "pr_inversion", "svn://danse.us/sans/trunk/pr_inversion")
201   
202    os.chdir(wd)
203    if release:
204        install_pkg(".", "Invariant-%s" % INVARIANT, INV_URL)
205    else:
206        install_pkg(".", "Invariant", "svn://danse.us/sans/trunk/Invariant")
207   
208    os.chdir(wd)
209    if release:
210        install_pkg(".", "invariantview-%s" % INV_VIEW, INV_VIEW_URL)
211    else:
212        install_pkg(".", "invariantview", "svn://danse.us/sans/trunk/invariantview")
213   
214    os.chdir(wd)
215    if release:
216        install_pkg(".", "calculatorview-%s" % CALC_VIEW, CALC_VIEW_URL)
217    else:
218        install_pkg(".", "calculatorview", "svn://danse.us/sans/trunk/calculatorview")
219   
220    os.chdir(wd)
221    if release:
222        install_pkg(".", "calculator-%s" % CALCULATOR, CALC_URL)
223    else:
224        install_pkg(".", "calculator", "svn://danse.us/sans/trunk/calculator")
225
226    os.chdir(wd)
227    if release:
228        install_pkg(".", "elements-%s" % ELEMENTS, ELEMENTS_URL)
229    else:
230        install_pkg("elements", "trunk", "svn://danse.us/common/elements/trunk")
231
232    os.chdir(wd)
233    if release:
234        install_pkg(".", "park-%s" % PARK, PARK_URL)
235    else:
236        install_pkg(".", "park-1.2", "svn://danse.us/park/branches/park-1.2")
237   
238    os.chdir(wd)
239    if release:
240        os.system("%s checkout -q %s" % (SVN, SANSVIEW_URL))
241    else:
242        os.system("%s checkout -q svn://danse.us/sans/trunk/sansview" % SVN)
243   
244def prepare(wipeout = False):
245    """
246        Prepare the build
247       
248        @param wipeout: If True, the DANSE modules in the standard site-packages will be
249        removed to avoid conflicts.
250    """
251    # Remove existing libraries
252    if wipeout == True:
253        logging.info("Deleting DANSES modules in site-packages")
254        from distutils.sysconfig import get_python_lib
255        libdir = get_python_lib()
256        old_dirs = [os.path.join(libdir, 'danse'),
257                    os.path.join(libdir, 'data_util'),
258                    os.path.join(libdir, 'DataLoader'),
259                    os.path.join(libdir, 'park'),
260                    os.path.join(libdir, 'sans'),
261                    os.path.join(libdir, 'sans_extension'),
262                    ]
263        for d in old_dirs:
264            if os.path.isdir(d):
265                shutil.rmtree(d)
266       
267    # Create a fresh installation folder
268    if os.path.isdir(INSTALL_FOLDER):
269        shutil.rmtree(INSTALL_FOLDER)
270
271    os.mkdir(INSTALL_FOLDER)
272   
273    # Check that the dependencies are properly installed
274    check_system()   
275   
276    # Move to the installation folder
277    os.chdir(INSTALL_FOLDER)   
278
279def warning():
280    """
281        The build script will wipe out part of the site-packages.
282        Ask the user whether he wants to proceed.
283    """
284    print "WARNING!\n"
285    print "In order to build a clean version of SansView, this script"
286    print "deletes anything found under site-packages for the following"
287    print "modules:"
288    print "   - danse"
289    print "   - data_util"
290    print "   - DataLoader"
291    print "   - park"
292    print "   - sans"
293    print "   - sans_extension\n"
294    answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]")
295    return answer.upper()=="Y"
296       
297if __name__ == "__main__": 
298    print "Build script for SansView %s" % SANSVIEW
299   
300    if len(sys.argv)==1:
301        # If there is no argument, build the installer
302        sys.argv.append("-i")
303       
304    if len(sys.argv)>1:
305        # Help
306        if sys.argv[1]=="-h":
307            print "Usage:"
308            print "    python build_sansview [command]\n"
309            print "[command] can be any of the following:"
310            print "    -h: lists the command line options"
311            print "    -r: Builds a SansView using the released modules"
312            print "    -t: Builds SansView from the trunk"
313            print "    -i: Builds an installer from the release version [Windows only]"       
314            print "    -n: Print out the dependencies for the release notes"
315        elif sys.argv[1]=="-n":
316            # Print out release URLs
317            print SANSMODELS_URL
318            print DATALOADER_URL
319            print GUIFRAME_URL
320            print PLOTTOOLS_URL
321            print UTIL_URL
322            print SANSVIEW_URL
323            print PARK_INTEG_URL
324            print PARK_URL
325            print PRVIEW
326            print PR_INV
327        else:
328            logging.info("Build script for SansView %s" % SANSVIEW)
329                   
330            # Prepare installation folder
331            prepare(warning())
332           
333            # Check the command line argument
334            if sys.argv[1]=="-t":
335                logging.info("Building trunk version")
336                checkout()
337            elif sys.argv[1]=="-r":
338                logging.info("Building release version")
339                checkout(True)
340            elif sys.argv[1]=="-i":
341                logging.info("Building release version")
342                checkout(True)
343                if sys.platform=='win32':
344                    logging.info("Building Windows installer from release version")
345                    os.chdir("sansview-%s" % (SANSVIEW))
346                    os.system("%s setup_exe.py py2exe --extrapath \"%s\python25\lib\site-packages\"" % (PYTHON, LIB_FOLDER))
347                    os.system("%s/Q installer.iss" % INNO)
348                    shutil.copy2(os.path.join("Output","setupSansView.exe"), 
349                                 os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp)))
350                elif sys.platform=='darwin':
351                    logging.info("Building Mac application from release version")
352                    os.chdir("sansview-%s" % (SANSVIEW))
353                    os.system("%s setup_mac.py py2app" % PYTHON)                   
354                   
355    raw_input("Press enter to continue\n")
356   
Note: See TracBrowser for help on using the repository browser.