source: sasview/sansview/build_tar.py @ e594bb0

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

add folder writable

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