source: sasview/sansview/build_tar.py @ c6ccf852

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

new v#s

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