source: sasview/prview/build_prview.py @ 19403da

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 19403da was e4193d9, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

prview: added better (user) default to build script

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