source: sasview/sansview/build_sansview.py @ 20d91bd

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 20d91bd was 391c480, checked in by Jae Cho <jhjcho@…>, 13 years ago

correct v# for park

  • Property mode set to 100644
File size: 15.6 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.
46# Select the appropriate python version to use.
47if sys.version_info >= (3, 0) or sys.version_info < (2, 5):
48    print "*** This script only works with Python 2.5, 2.6, or 2.7."
49    sys.exit()
50elif sys.version_info > (2, 6):
51    P_version = 27
52elif sys.version_info > (2, 5):
53    P_version = 26
54else:
55    P_version = 25
56   
57if sys.platform == 'win32':
58    PYTHON = "c:\python%s\python"% str(P_version)
59    LIB_FOLDER = "%s/%s" % (CWD, INSTALL_FOLDER)
60else:
61    PYTHON = 'python'
62
63logging.basicConfig(level=logging.INFO,
64                    format='%(asctime)s %(levelname)s %(message)s',
65                    filename='build_%s.log' % str(timestamp),
66                    filemode='w')
67
68SVN    = "svn"
69INNO   = "\"c:\Program Files\Inno Setup 5\ISCC\""
70
71# Release version 2.0
72SANSMODELS = "1.0.0"
73DATALOADER = "1.0.0"
74GUIFRAME   = "1.0.1"
75SANSVIEW   = "2.0.1"
76PLOTTOOLS  = "1.0.0"
77UTIL       = "1.0.0"
78PARK       = "1.2.1"
79PARK_INTEG = "1.0.1"
80PRVIEW     = "1.0.0"
81PR_INV     = "1.0.0"
82CALCULATOR = "1.0.0"
83CALC_VIEW  = "1.0.0"
84INVARIANT  = "1.0.0"
85INV_VIEW   = "1.0.0"
86FIT_VIEW   = "1.0.1"
87
88# URLs for SVN repos
89SANSMODELS_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/sansmodels-%s" % SANSMODELS
90DATALOADER_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/sansdataloader-%s" % DATALOADER
91GUIFRAME_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/sansguiframe-%s" % GUIFRAME
92PLOTTOOLS_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/common-releases/plottools-%s" % PLOTTOOLS
93UTIL_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/common-releases/util-%s" % UTIL
94SANSVIEW_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/sansview-%s" % SANSVIEW
95FIT_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/fittingview-%s" % FIT_VIEW
96PARK_INTEG_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/park_integration-%s" % PARK_INTEG
97PARK_URL = "svn://danse.us/park/releases/park-%s" % PARK
98PRVIEW_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/inversionview-%s" % PRVIEW
99PR_INV_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/pr_inversion-%s" % PR_INV
100CALC_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/sanscalculator-%s" % CALCULATOR
101CALC_VIEW_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/calculatorview-%s" % CALC_VIEW
102INV_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/sansinvariant-%s" % INVARIANT
103INV_VIEW_URL = "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/releases/invariantview-%s" % INV_VIEW
104
105def check_system():
106    """
107        Checks that the system has the necessary modules.
108    """
109    try:
110        import wx
111    except:
112        logging.error("wxpython missing")
113   
114    try:
115        import matplotlib
116    except:
117        logging.error("matplotlib missing")
118       
119    try:
120        import numpy
121    except:
122        logging.error("numpy missing")
123       
124    try:
125        import scipy
126    except:
127        logging.error("scipy missing")
128
129    try:
130        import periodictable
131    except:
132        logging.error("periodictable missing")
133       
134    if os.system("gcc -dumpversion")==1:
135        logging.error("missing mingw")
136
137def install_pkg(install_dir, setup_dir, url):
138    """
139        Check a package out and install it
140       
141        @param install_dir: directory to put the code in
142        @param setup_dir: relative location of the setup.py script
143        @param url: URL of the SVN repo
144    """
145    #print "PYTHON, LIB_FOLDER=====",PYTHON, LIB_FOLDER
146    logging.info("Installing %s" % url)
147    try:
148        if not os.path.isdir(install_dir):
149            os.mkdir(install_dir)
150        os.chdir(install_dir)
151        build_num = os.path.basename(os.getcwd())   
152        os.system("%s checkout -q %s" % (SVN, url))       
153        os.chdir(setup_dir)
154        if setup_dir.count('sansview') > 0:
155            conf_file = open('local_config.py', 'rw')
156            conf = conf_file.read()
157            conf = '__build__ = %s %s \n'% (build_num, time.localtime()) +\
158                     conf
159            conf_file.write(conf)
160            conf_file.close()
161            print "install_dir", build_num,'__build__ = %s %s \n'% (build_num, time.localtime())
162        if sys.platform == 'win32':
163            os.system("%s setup.py -q build -cmingw32" % PYTHON)
164            os.system("%s setup.py -q install --root \"%s\"" % (PYTHON, LIB_FOLDER))
165        else:
166            os.system("%s setup.py build" % PYTHON)
167            os.system("%s setup.py install --prefix ~/.local" % PYTHON)
168    except:
169        logging.error("Install failed for %s" % url)
170        logging.error(sys.exc_value)
171        raw_input("Press enter to continue\n")
172        sys.exit()
173   
174def checkout(release=False):
175    """
176        Check the SansView code out
177    """
178    wd = os.getcwd()
179   
180    os.chdir(wd)
181    if release:
182        install_pkg(".", "sansdataloader-%s" % DATALOADER, DATALOADER_URL)
183    else:
184        install_pkg(".", "sansdataloader", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/sansdataloader")
185   
186    os.chdir(wd)
187    if release:
188        install_pkg(".", "sansmodels-%s" % SANSMODELS, SANSMODELS_URL)
189    else:
190        install_pkg(".", "sansmodels", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/sansmodels")
191   
192    os.chdir(wd)
193    if release:
194        install_pkg(".", "sansguiframe-%s" % GUIFRAME, GUIFRAME_URL)
195    else:
196        install_pkg(".", "sansguiframe", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/sansguiframe")
197   
198    os.chdir(wd)
199    if release:
200        install_pkg(".", "plottools-%s" % PLOTTOOLS, PLOTTOOLS_URL)
201    else:
202        install_pkg(".", "plottools", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/plottools")
203   
204    os.chdir(wd)
205    if release:
206        install_pkg(".", "sansutil-%s" % UTIL, UTIL_URL)
207    else:
208        install_pkg(".", "sansutil", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/sansutil")
209   
210    os.chdir(wd)
211    if release:
212        install_pkg(".", "park_integration-%s" % PARK_INTEG, PARK_INTEG_URL)
213    else:
214        install_pkg(".", "park_integration", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/park_integration")
215   
216    os.chdir(wd)
217    if release:
218        install_pkg(".", "inversionview-%s" % PRVIEW, PRVIEW_URL)
219    else:
220        install_pkg(".", "inversionview", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/inversionview")
221   
222    os.chdir(wd)
223    if release:
224        install_pkg(".", "pr_inversion-%s" % PR_INV, PR_INV_URL)
225    else:
226        install_pkg(".", "pr_inversion", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/pr_inversion")
227   
228    os.chdir(wd)
229    if release:
230        install_pkg(".", "sansinvariant-%s" % INVARIANT, INV_URL)
231    else:
232        install_pkg(".", "sansinvariant", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/sansinvariant")
233   
234    os.chdir(wd)
235    if release:
236        install_pkg(".", "invariantview-%s" % INV_VIEW, INV_VIEW_URL)
237    else:
238        install_pkg(".", "invariantview", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/invariantview")
239   
240    os.chdir(wd)
241    if release:
242        install_pkg(".", "calculatorview-%s" % CALC_VIEW, CALC_VIEW_URL)
243    else:
244        install_pkg(".", "calculatorview", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/calculatorview")
245   
246    os.chdir(wd)
247    if release:
248        install_pkg(".", "sanscalculator-%s" % CALCULATOR, CALC_URL)
249    else:
250        install_pkg(".", "sanscalculator", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/sanscalculator")
251
252
253    os.chdir(wd)
254    if release:
255        install_pkg(".", "park-%s" % PARK, PARK_URL)
256    else:
257        install_pkg(".", "park-1.2.1", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/park-1.2.1")
258       
259    os.chdir(wd)
260    if release:
261        install_pkg(".", "fittingview-%s" % FIT_VIEW, FIT_URL)
262    else:
263        install_pkg(".", "fittingview", "https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/fittingview")
264           
265    os.chdir(wd)
266    if release:
267        os.system("%s checkout -q %s" % (SVN, SANSVIEW_URL))
268    else:
269        os.system("%s checkout -q https://sansviewproject.svn.sourceforge.net/svnroot/sansviewproject/trunk/sansview" % SVN)
270    # put build number to local_config
271    try:
272        build_num = os.path.basename(wd).split('_')[1] 
273        if sys.argv[1]=="-r":
274            sansview_folder = "sansview-%s" % (SANSVIEW) 
275        else:
276            sansview_folder = "sansview" 
277        # try to make the sansview dir writable
278        try:
279            if sys.platform == 'darwin':
280                os.system("chmod -R g+w %s"% sansview_foler) 
281            else:
282                os.system("chmod 777 -R %s"% sansview_foler)
283        except:
284            pass
285        os.chdir(sansview_folder)
286        if os.getcwd().count('sansview') > 0:
287            conf_file = open('local_config.py', 'r')
288            conf = ''
289            import datetime
290            for line in conf_file.readlines():
291                if line.count('__build__'):
292                    conf += "__build__ = '%s-%s' \n"% (build_num, datetime.date.today())
293                else:
294                    conf += line
295            conf_file.close()
296            conf_file = open('local_config.py', 'w')
297            conf_file.write(conf)
298            conf_file.close()
299    except:
300        pass
301    os.chdir(wd)
302   
303def prepare(wipeout = False):
304    """
305        Prepare the build
306       
307        @param wipeout: If True, the DANSE modules in the standard site-packages will be
308        removed to avoid conflicts.
309    """
310    # Remove existing libraries
311    if wipeout == True:
312        logging.info("Deleting DANSES modules in site-packages")
313        from distutils.sysconfig import get_python_lib
314        libdir = get_python_lib()
315        old_dirs = [os.path.join(libdir, 'danse'),
316                    os.path.join(libdir, 'data_util'),
317                    os.path.join(libdir, 'park'),
318                    os.path.join(libdir, 'sans'),
319                    ]
320        for d in old_dirs:
321            if os.path.isdir(d):
322                shutil.rmtree(d)
323       
324    # Create a fresh installation folder
325    if os.path.isdir(INSTALL_FOLDER):
326        shutil.rmtree(INSTALL_FOLDER)
327
328    os.mkdir(INSTALL_FOLDER)
329   
330    # Check that the dependencies are properly installed
331    check_system()   
332   
333    # Move to the installation folder
334    os.chdir(INSTALL_FOLDER)   
335
336def warning():
337    """
338        The build script will wipe out part of the site-packages.
339        Ask the user whether he wants to proceed.
340    """
341    print "WARNING!\n"
342    print "In order to build a clean version of SansView, this script"
343    print "deletes anything found under site-packages for the following"
344    print "modules:"
345    print "   - danse"
346    print "   - data_util"
347    print "   - DataLoader"
348    print "   - park"
349    print "   - sans"
350    print "   - sans_extension\n"
351    answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]")
352    return answer.upper()=="Y"
353       
354if __name__ == "__main__": 
355   
356    if len(sys.argv)==1:
357        # If there is no argument, build the installer
358        sys.argv.append("-i")
359       
360    if len(sys.argv)>1:
361        # Help
362        if sys.argv[1]=="-h":
363            print "Usage:"
364            print "    python build_sansview [command]\n"
365            print "[command] can be any of the following:"
366            print "    -h: lists the command line options"
367            print "    -r: Builds a SansView using the released modules"
368            print "    -t: Builds SansView from the trunk"
369            print "    -i: Builds an installer from the release version [Windows only]"       
370            print "    -n: Print out the dependencies for the release notes"
371        elif sys.argv[1]=="-n":
372            # Print out release URLs
373            print SANSMODELS_URL
374            print DATALOADER_URL
375            print GUIFRAME_URL
376            print PLOTTOOLS_URL
377            print UTIL_URL
378            print SANSVIEW_URL
379            print PARK_INTEG_URL
380            print PARK_URL
381            print PRVIEW
382            print PR_INV
383            print FIT_URL
384        else:
385            logging.info("Build script for SansView %s" % SANSVIEW)
386                   
387            # Prepare installation folder
388            prepare(warning())
389           
390            # Check the command line argument
391            if sys.argv[1]=="-t":
392                logging.info("Building trunk version")
393                checkout()
394            elif sys.argv[1]=="-r":
395                logging.info("Building release version")
396                checkout(True)
397            elif sys.argv[1]=="-i":
398                logging.info("Building release version")
399                checkout(True)
400                if sys.platform=='win32':
401                    logging.info("Building Windows installer from release version")
402                    os.chdir("sansview-%s" % (SANSVIEW))
403                    os.system("%s setup_exe.py py2exe --extrapath \"%s\python25\lib\site-packages\"" % (PYTHON, LIB_FOLDER))
404                    os.system("%s/Q installer.iss" % INNO)
405                    shutil.copy2(os.path.join("Output","setupSansView.exe"), 
406                                 os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp)))
407                elif sys.platform=='darwin':
408                    logging.info("Building Mac application from release version")
409                    os.chdir("sansview-%s" % (SANSVIEW))
410                    os.system("%s setup_mac.py py2app" % PYTHON)                   
411                   
412    raw_input("Press enter to continue\n")
413   
Note: See TracBrowser for help on using the repository browser.