source: sasview/sansview/build_tar.py @ 53fc5ad9

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 53fc5ad9 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: 15.4 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            if sys.platform == 'darwin':
320                os.system("chmod -R g+w %s"% sansview_foler) 
321            else:
322                os.system("chmod 777 -R %s"% sansview_foler)
323        except:
324            pass
325        os.chdir(sansview_folder)
326        if os.getcwd().count('sansview') > 0:
327            conf_file = open('local_config.py', 'r')
328            conf = ''
329            import datetime
330            for line in conf_file.readlines():
331                if line.count('__build__'):
332                    conf += "__build__ = '%s-%s' \n"% (build_num, datetime.date.today())
333                else:
334                    conf += line
335            conf_file.close()
336            conf_file = open('local_config.py', 'w')
337            conf_file.write(conf)
338            conf_file.close()
339    except:
340        pass
341   
342    os.chdir(wd)
343   
344def prepare(wipeout = False):
345    """
346        Prepare the build
347       
348        @param wipeout: If True, the DANSE modules in the standard site-packages will be
349        removed to avoid conflicts.
350    """
351    # Remove existing libraries
352    if wipeout == True:
353        logging.info("Deleting DANSES modules in site-packages")
354        from distutils.sysconfig import get_python_lib
355        libdir = get_python_lib()
356        old_dirs = [os.path.join(libdir, 'danse'),
357                    os.path.join(libdir, 'data_util'),
358                    os.path.join(libdir, 'park'),
359                    os.path.join(libdir, 'sans'),
360                    ]
361        for d in old_dirs:
362            if os.path.isdir(d):
363                shutil.rmtree(d)
364       
365    # Create a fresh installation folder
366    if os.path.isdir(INSTALL_FOLDER):
367        shutil.rmtree(INSTALL_FOLDER)
368
369    os.mkdir(INSTALL_FOLDER)
370   
371    # Check that the dependencies are properly installed
372    if not check_system():
373        raise "Please install the above missing packages first..." 
374   
375    # Move to the installation folder
376    os.chdir(INSTALL_FOLDER)   
377
378def warning():
379    """
380        The build script will wipe out part of the site-packages.
381        Ask the user whether he wants to proceed.
382    """
383    print "WARNING!\n"
384    print "In order to build a clean version of SansView, this script"
385    print "deletes anything found under site-packages for the following"
386    print "modules:"
387    print "   - danse"
388    print "   - data_util"
389    print "   - DataLoader"
390    print "   - park"
391    print "   - sans"
392    print "   - sans_extension\n"
393    answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]")
394    return answer.upper()=="Y"
395       
396if __name__ == "__main__": 
397   
398    if len(sys.argv)==1:
399        # If there is no argument, build the installer
400        sys.argv.append("-i")
401       
402    if len(sys.argv)>1:
403        # Help
404        if sys.argv[1]=="-h":
405            print "Usage:"
406            print "    python build_sansview [command]\n"
407            print "[command] can be any of the following:"
408            print "    -h: lists the command line options"
409            print "    -r: Builds a SansView using the released modules"
410            print "    -t: Builds SansView from the trunk"
411            print "    -i: Builds an installer from the release version [Windows only]"       
412            print "    -n: Print out the dependencies for the release notes"
413        elif sys.argv[1]=="-n":
414            # Print out release URLs
415            print SANSMODELS_URL
416            print DATALOADER_URL
417            print GUIFRAME_URL
418            print PLOTTOOLS_URL
419            print UTIL_URL
420            print SANSVIEW_URL
421            print PARK_INTEG_URL
422            print PARK_URL
423            print PRVIEW
424            print PR_INV
425            print FIT_URL
426        else:
427            logging.info("Build script for SansView %s" % SANSVIEW)
428                   
429            # Prepare installation folder
430            prepare(warning())
431           
432            # Check the command line argument
433            if sys.argv[1]=="-t":
434                logging.info("Building trunk version")
435                checkout()
436            elif sys.argv[1]=="-r":
437                logging.info("Building release version")
438                checkout(True)
439            elif sys.argv[1]=="-i":
440                logging.info("Building release version")
441                checkout(True)
442                if sys.platform=='win32':
443                    logging.info("Building Windows installer from release version")
444                    os.chdir("sansview-%s" % (SANSVIEW))
445                    os.system("%s setup_exe.py py2exe --extrapath \"%s\python25\lib\site-packages\"" % (PYTHON, LIB_FOLDER))
446                    os.system("%s/Q installer.iss" % INNO)
447                    shutil.copy2(os.path.join("Output","setupSansView.exe"), 
448                                 os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp)))
449                elif sys.platform=='darwin':
450                    logging.info("Building Mac application from release version")
451                    os.chdir("sansview-%s" % (SANSVIEW))
452                    os.system("%s setup_mac.py py2app" % PYTHON)                   
453                   
454    raw_input("Press enter to continue\n")
455   
Note: See TracBrowser for help on using the repository browser.