source: sasview/sansview/build_sansview.py @ a86e69b

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

fixed change sansview folder mod to w+r

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