source: sasview/sansview/scripts/build_sansview.py @ 19aa896

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 19aa896 was 6b9af19, checked in by Gervaise Alina <gervyh@…>, 13 years ago

rename sansguiframe

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