source: sasview/sansview/build_tar.py @ ea8de94

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

build python/sansview package via source (for linux tar ball)

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