source: sasview/prview/build_prview.py @ ec3959ab

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 ec3959ab was 731406c, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

PrView?: updated build script

  • Property mode set to 100644
File size: 9.3 KB
Line 
1#
2# Script to get source from SVN and build PrView
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#   - Inno Setup must be installed
13#   - py2exe must be installed
14#   - mingw must be installed
15#
16# In Mac:
17#   - py2app must be installed
18#   - macholib must be installed to use py2app
19#   - modulegraph must be installed to use py2app
20#
21# Usage:
22# python build_prview [command]
23# [command] can be any of the following:
24#   -h: lists the command line options
25#   -r: Builds a PrView using the released modules.
26#   -t: Builds PrView from the trunk.
27#   -i: Builds an installer from the release version.
28#   -n: Print out the dependencies for the release notes
29
30import os
31import sys
32import shutil
33import logging
34
35# Installation folder
36import time
37timestamp = int(time.time())
38CWD = os.getcwd()
39INSTALL_FOLDER = "install_%s" % str(timestamp)
40
41# On Windows, the python executable is not always on the path.
42# Use its most frequent location as the default.
43if sys.platform == 'win32':
44    PYTHON = "c:\python25\python"
45    LIB_FOLDER = "%s/%s" % (CWD, INSTALL_FOLDER)
46else:
47    PYTHON = 'python'
48
49logging.basicConfig(level=logging.INFO,
50                    format='%(asctime)s %(levelname)s %(message)s',
51                    filename='build_%s.log' % str(timestamp),
52                    filemode='w')
53
54SVN    = "svn"
55INNO   = "\"c:\Program Files\Inno Setup 5\ISCC\""
56
57# Release version 0.3.3
58DATALOADER = "0.2.7"
59GUICOMM    = "0.1.5"
60GUIFRAME   = "0.2.0"
61PRVIEW     = "0.3.3"
62PLOTTOOLS  = "0.1.9"
63UTIL       = "0.1.5"
64PR_INV = "0.2.5"
65
66# URLs for SVN repos
67DATALOADER_URL = "svn://danse.us/sans/releases/DataLoader-%s" % DATALOADER
68GUICOMM_URL = "svn://danse.us/sans/releases/guicomm-%s" % GUICOMM
69GUIFRAME_URL = "svn://danse.us/sans/releases/guiframe-%s" % GUIFRAME
70PLOTTOOLS_URL = "svn://danse.us/common/releases/plottools-%s/trunk" % PLOTTOOLS
71UTIL_URL = "svn://danse.us/common/releases/util-%s" % UTIL
72PRVIEW_URL = "svn://danse.us/sans/releases/prview-%s" % PRVIEW
73PR_INV_URL = "svn://danse.us/sans/releases/pr_inversion-%s" % PR_INV
74
75
76def check_system():
77    """
78        Checks that the system has the necessary modules.
79    """
80    try:
81        import wx
82    except:
83        logging.error("wxpython missing")
84   
85    try:
86        import matplotlib
87    except:
88        logging.error("matplotlib missing")
89       
90    try:
91        import numpy
92    except:
93        logging.error("numpy missing")
94       
95    try:
96        import scipy
97    except:
98        logging.error("scipy missing")
99       
100    if os.system("gcc -dumpversion")==1:
101        logging.error("missing mingw")
102
103def install_pkg(install_dir, setup_dir, url):
104    """
105        Check a package out and install it
106       
107        @param install_dir: directory to put the code in
108        @param setup_dir: relative location of the setup.py script
109        @param url: URL of the SVN repo
110    """
111    logging.info("Installing %s" % url)
112    try:
113        if not os.path.isdir(install_dir):
114            os.mkdir(install_dir)
115        os.chdir(install_dir)   
116        os.system("%s checkout -q %s" % (SVN, url))       
117        os.chdir(setup_dir)
118        if sys.platform == 'win32':
119            os.system("%s setup.py -q build -cmingw32" % PYTHON)
120            os.system("%s setup.py -q install --root \"%s\"" % (PYTHON, LIB_FOLDER))
121        else:
122            os.system("%s setup.py build" % PYTHON)
123            os.system("%s setup.py install --prefix ~/.local" % PYTHON)
124    except:
125        logging.error("Install failed for %s" % url)
126        logging.error(sys.exc_value)
127        raw_input("Press enter to continue\n")
128        sys.exit()
129   
130def checkout(release=False):
131    """
132        Check the PrView code out
133    """
134    wd = os.getcwd()
135   
136    os.chdir(wd)
137    if release:
138        install_pkg(".", "DataLoader-%s" % DATALOADER, DATALOADER_URL)
139    else:
140        install_pkg(".", "DataLoader", "svn://danse.us/sans/trunk/DataLoader")
141   
142    os.chdir(wd)
143    if release:
144        install_pkg(".", "guicomm-%s" % GUICOMM, GUICOMM_URL)
145    else:
146        install_pkg(".", "guicomm", "svn://danse.us/sans/trunk/guicomm")
147   
148    os.chdir(wd)
149    if release:
150        install_pkg(".", "guiframe-%s" % GUIFRAME, GUIFRAME_URL)
151    else:
152        install_pkg(".", "guiframe", "svn://danse.us/sans/trunk/guiframe")
153   
154    os.chdir(wd)
155    if release:
156        install_pkg("plottools-%s" % PLOTTOOLS, "trunk", PLOTTOOLS_URL)
157    else:
158        install_pkg("plottools", "trunk", "svn://danse.us/common/plottools/trunk")
159   
160    os.chdir(wd)
161    if release:
162        install_pkg(".", "util-%s" % UTIL, UTIL_URL)
163    else:
164        install_pkg(".", "util", "svn://danse.us/common/util")
165   
166    os.chdir(wd)
167    if release:
168        install_pkg(".", "pr_inversion-%s" % PR_INV, PR_INV_URL)
169    else:
170        install_pkg(".", "pr_inversion", "svn://danse.us/sans/trunk/pr_inversion")
171   
172    os.chdir(wd)
173    if release:
174        os.system("%s checkout -q %s" % (SVN, PRVIEW_URL))
175    else:
176        os.system("%s checkout -q svn://danse.us/sans/trunk/prview" % SVN)
177   
178def prepare(wipeout = False):
179    """
180        Prepare the build
181       
182        @param wipeout: If True, the DANSE modules in the standard site-packages will be
183        removed to avoid conflicts.
184    """
185    # Remove existing libraries
186    if wipeout == True:
187        logging.info("Deleting DANSES modules in site-packages")
188        from distutils.sysconfig import get_python_lib
189        libdir = get_python_lib()
190        old_dirs = [os.path.join(libdir, 'danse'),
191                    os.path.join(libdir, 'data_util'),
192                    os.path.join(libdir, 'DataLoader'),
193                    os.path.join(libdir, 'sans'),
194                    os.path.join(libdir, 'sans_extension'),
195                    ]
196        for d in old_dirs:
197            if os.path.isdir(d):
198                shutil.rmtree(d)
199       
200    # Create a fresh installation folder
201    if os.path.isdir(INSTALL_FOLDER):
202        shutil.rmtree(INSTALL_FOLDER)
203
204    os.mkdir(INSTALL_FOLDER)
205   
206    # Check that the dependencies are properly installed
207    check_system()   
208   
209    # Move to the installation folder
210    os.chdir(INSTALL_FOLDER)   
211
212def warning():
213    """
214        The build script will wipe out part of the site-packages.
215        Ask the user whether he wants to proceed.
216    """
217    print "WARNING!\n"
218    print "In order to build a clean version of PrView, this script"
219    print "deletes anything found under site-packages for the following"
220    print "modules:"
221    print "   - danse"
222    print "   - data_util"
223    print "   - DataLoader"
224    print "   - sans"
225    print "   - sans_extension\n"
226    answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]")
227    return answer.upper()=="Y"
228       
229if __name__ == "__main__": 
230    print "Build script for PrView %s" % PRVIEW
231   
232    if len(sys.argv)==1:
233        # If there is no argument, build the installer
234        sys.argv.append("-i")
235   
236    if len(sys.argv)>1:
237        # Help
238        if sys.argv[1]=="-h":
239            print "Usage:"
240            print "    python build_prview [command]\n"
241            print "[command] can be any of the following:"
242            print "    -h: lists the command line options"
243            print "    -r: Builds a PrView using the released modules"
244            print "    -t: Builds PrView from the trunk"
245            print "    -i: Builds an installer from the release version [Windows only]"       
246            print "    -n: Print out the dependencies for the release notes"
247        elif sys.argv[1]=="-n":
248            # Print out release URLs
249            print DATALOADER_URL
250            print GUICOMM_URL
251            print GUIFRAME_URL
252            print PLOTTOOLS_URL
253            print UTIL_URL
254            print PRVIEW_URL
255            print PR_INV_URL
256        else:
257            logging.info("Build script for PrView %s" % PRVIEW)
258                   
259            # Prepare installation folder
260            prepare(warning())
261           
262            # Check the command line argument
263            if sys.argv[1]=="-t":
264                logging.info("Building trunk version")
265                checkout()
266            elif sys.argv[1]=="-r":
267                logging.info("Building release version")
268                checkout(True)
269            elif sys.argv[1]=="-i":
270                logging.info("Building release version")
271                checkout(True)
272                if sys.platform=='win32':
273                    logging.info("Building Windows installer from release version")
274                    os.chdir("prview-%s" % (PRVIEW))
275                    os.system("%s setup_exe.py py2exe --extrapath \"%s\python25\lib\site-packages\"" % (PYTHON, LIB_FOLDER))
276                    os.system("%s/Q installer.iss" % INNO)
277                    shutil.copy2(os.path.join("Output","setupSansView.exe"), 
278                                 os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp)))
279                elif sys.platform=='darwin':
280                    logging.info("Building Mac application from release version")
281                    os.chdir("prview-%s" % (PRVIEW))
282                    os.system("%s setup_mac.py py2app" % PYTHON)                   
283                   
284    raw_input("Press enter to continue\n")
Note: See TracBrowser for help on using the repository browser.