source: sasview/prview/scripts/build_prview.py @ dc65f8c

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 dc65f8c was f9660dc, checked in by Jae Cho <jhjcho@…>, 13 years ago

updated path

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