[40f9745] | 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 | # Make sure svn.exe in on the path. You might need to log out and log back in again after installing SVN. |
---|
| 9 | # |
---|
| 10 | # Inno Setup must be installed |
---|
| 11 | # |
---|
| 12 | # py2exe must be installed |
---|
| 13 | # |
---|
[249bae9] | 14 | # mingw must be installed |
---|
| 15 | # |
---|
[40f9745] | 16 | # Usage: |
---|
| 17 | # python build_sansview [command] |
---|
| 18 | # [command] can be any of the following: |
---|
| 19 | # -h: lists the command line options |
---|
| 20 | # -r: Builds a SansView using the released modules. |
---|
| 21 | # -t: Builds SansView from the trunk. |
---|
| 22 | # -i: Builds an installer from the release version. |
---|
[249bae9] | 23 | # -n: Print out the dependencies for the release notes |
---|
[40f9745] | 24 | |
---|
| 25 | import os |
---|
| 26 | import shutil |
---|
[7b35808] | 27 | import logging |
---|
[40f9745] | 28 | |
---|
[7b35808] | 29 | # Installation folder |
---|
| 30 | import time |
---|
| 31 | timestamp = int(time.time()) |
---|
| 32 | INSTALL_FOLDER = "install_%s" % str(timestamp) |
---|
| 33 | |
---|
| 34 | logging.basicConfig(level=logging.INFO, |
---|
| 35 | format='%(asctime)s %(levelname)s %(message)s', |
---|
| 36 | filename='build_%s.log' % str(timestamp), |
---|
| 37 | filemode='w') |
---|
| 38 | |
---|
| 39 | CWD = os.getcwd() |
---|
[553d047] | 40 | PYTHON = "c:\python25\python" |
---|
[40f9745] | 41 | SVN = "svn" |
---|
| 42 | INNO = "\"c:\Program Files\Inno Setup 5\ISCC\"" |
---|
| 43 | |
---|
[6e5eb55] | 44 | # Release version 0.9.0 |
---|
[d9d68ba] | 45 | SANSMODELS = "0.4.3" |
---|
| 46 | DATALOADER = "0.2.3" |
---|
| 47 | GUICOMM = "0.1.2" |
---|
| 48 | GUIFRAME = "0.1.5" |
---|
| 49 | SANSVIEW = "0.9.0" |
---|
| 50 | PLOTTOOLS = "0.1.4" |
---|
| 51 | UTIL = "0.1.1" |
---|
| 52 | PARK = "1.2" |
---|
| 53 | PARK_INTEG = "0.1.1" |
---|
[249bae9] | 54 | |
---|
[7b35808] | 55 | # URLs for SVN repos |
---|
[249bae9] | 56 | SANSMODELS_URL = "svn://danse.us/sans/releases/sansmodels-%s" % SANSMODELS |
---|
| 57 | DATALOADER_URL = "svn://danse.us/sans/releases/DataLoader-%s" % DATALOADER |
---|
| 58 | GUICOMM_URL = "svn://danse.us/sans/releases/guicomm-%s" % GUICOMM |
---|
| 59 | GUIFRAME_URL = "svn://danse.us/sans/releases/guiframe-%s" % GUIFRAME |
---|
| 60 | PLOTTOOLS_URL = "svn://danse.us/common/releases/plottools-%s/trunk" % PLOTTOOLS |
---|
| 61 | UTIL_URL = "svn://danse.us/common/releases/util-%s" % UTIL |
---|
| 62 | SANSVIEW_URL = "svn://danse.us/sans/releases/sansview-%s" % SANSVIEW |
---|
[fa523d3] | 63 | PARK_INTEG_URL = "svn://danse.us/sans/releases/park_integration-%s" % PARK_INTEG |
---|
[d9d68ba] | 64 | PARK_URL = "svn://danse.us/park/releases/park-%s" % PARK |
---|
[40f9745] | 65 | |
---|
| 66 | |
---|
| 67 | def check_system(): |
---|
| 68 | """ |
---|
| 69 | Checks that the system has the necessary modules. |
---|
| 70 | """ |
---|
| 71 | try: |
---|
| 72 | import wx |
---|
| 73 | except: |
---|
[7b35808] | 74 | logging.error("wxpython missing") |
---|
[40f9745] | 75 | |
---|
| 76 | try: |
---|
| 77 | import matplotlib |
---|
| 78 | except: |
---|
[7b35808] | 79 | logging.error("matplotlib missing") |
---|
[40f9745] | 80 | |
---|
| 81 | try: |
---|
| 82 | import numpy |
---|
| 83 | except: |
---|
[7b35808] | 84 | logging.error("numpy missing") |
---|
[40f9745] | 85 | |
---|
| 86 | try: |
---|
| 87 | import scipy |
---|
| 88 | except: |
---|
[7b35808] | 89 | logging.error("scipy missing") |
---|
[40f9745] | 90 | |
---|
| 91 | if os.system("gcc -dumpversion")==1: |
---|
[7b35808] | 92 | logging.error("missing mingw") |
---|
[40f9745] | 93 | |
---|
| 94 | def install_pkg(install_dir, setup_dir, url): |
---|
| 95 | """ |
---|
| 96 | Check a package out and install it |
---|
| 97 | |
---|
| 98 | @param install_dir: directory to put the code in |
---|
| 99 | @param setup_dir: relative location of the setup.py script |
---|
| 100 | @param url: URL of the SVN repo |
---|
| 101 | """ |
---|
| 102 | if not os.path.isdir(install_dir): |
---|
| 103 | os.mkdir(install_dir) |
---|
| 104 | os.chdir(install_dir) |
---|
| 105 | os.system("%s checkout -q %s" % (SVN, url)) |
---|
| 106 | os.chdir(setup_dir) |
---|
[7b35808] | 107 | os.system("%s setup.py -q build -cmingw32" % PYTHON) |
---|
| 108 | os.system("%s setup.py -q install" % PYTHON) |
---|
[40f9745] | 109 | |
---|
| 110 | def checkout(release=False): |
---|
| 111 | """ |
---|
| 112 | Check the SansView code out |
---|
| 113 | """ |
---|
| 114 | wd = os.getcwd() |
---|
| 115 | |
---|
| 116 | os.chdir(wd) |
---|
| 117 | if release: |
---|
[249bae9] | 118 | install_pkg(".", "sansmodels-%s/src" % SANSMODELS, SANSMODELS_URL) |
---|
[40f9745] | 119 | else: |
---|
| 120 | install_pkg(".", "sansmodels/src", "svn://danse.us/sans/trunk/sansmodels") |
---|
| 121 | |
---|
| 122 | os.chdir(wd) |
---|
| 123 | if release: |
---|
[249bae9] | 124 | install_pkg(".", "DataLoader-%s" % DATALOADER, DATALOADER_URL) |
---|
[40f9745] | 125 | else: |
---|
| 126 | install_pkg(".", "DataLoader", "svn://danse.us/sans/trunk/DataLoader") |
---|
| 127 | |
---|
| 128 | os.chdir(wd) |
---|
| 129 | if release: |
---|
[249bae9] | 130 | install_pkg(".", "guicomm-%s" % GUICOMM, GUICOMM_URL) |
---|
[40f9745] | 131 | else: |
---|
| 132 | install_pkg(".", "guicomm", "svn://danse.us/sans/trunk/guicomm") |
---|
| 133 | |
---|
| 134 | os.chdir(wd) |
---|
| 135 | if release: |
---|
[249bae9] | 136 | install_pkg(".", "guiframe-%s" % GUIFRAME, GUIFRAME_URL) |
---|
[40f9745] | 137 | else: |
---|
| 138 | install_pkg(".", "guiframe", "svn://danse.us/sans/trunk/guiframe") |
---|
| 139 | |
---|
| 140 | os.chdir(wd) |
---|
| 141 | if release: |
---|
[249bae9] | 142 | install_pkg("plottools-%s" % PLOTTOOLS, "trunk", PLOTTOOLS_URL) |
---|
[40f9745] | 143 | else: |
---|
| 144 | install_pkg("plottools", "trunk", "svn://danse.us/common/plottools/trunk") |
---|
| 145 | |
---|
| 146 | os.chdir(wd) |
---|
| 147 | if release: |
---|
[249bae9] | 148 | install_pkg(".", "util-%s" % UTIL, UTIL_URL) |
---|
[40f9745] | 149 | else: |
---|
| 150 | install_pkg(".", "util", "svn://danse.us/common/util") |
---|
| 151 | |
---|
[fa523d3] | 152 | os.chdir(wd) |
---|
| 153 | if release: |
---|
| 154 | install_pkg(".", "park_integration-%s" % PARK_INTEG, PARK_INTEG_URL) |
---|
| 155 | else: |
---|
| 156 | install_pkg(".", "park_integration", "svn://danse.us/sans/trunk/park_integration") |
---|
| 157 | |
---|
[40f9745] | 158 | #TODO: need a release version of PARK |
---|
| 159 | os.chdir(wd) |
---|
| 160 | if release: |
---|
[249bae9] | 161 | install_pkg(".", "park-1.2", PARK_URL) |
---|
[40f9745] | 162 | else: |
---|
| 163 | install_pkg(".", "park-1.2", "svn://danse.us/park/branches/park-1.2") |
---|
| 164 | |
---|
| 165 | os.chdir(wd) |
---|
| 166 | if release: |
---|
[7b35808] | 167 | os.system("%s checkout -q %s" % (SVN, SANSVIEW_URL)) |
---|
[40f9745] | 168 | else: |
---|
[7b35808] | 169 | os.system("%s checkout -q svn://danse.us/sans/trunk/sansview" % SVN) |
---|
[40f9745] | 170 | |
---|
| 171 | def prepare(): |
---|
[7b35808] | 172 | """ |
---|
| 173 | Prepare the build |
---|
| 174 | """ |
---|
| 175 | # Remove existing libraries |
---|
| 176 | from distutils.sysconfig import get_python_lib |
---|
| 177 | libdir = get_python_lib() |
---|
| 178 | old_dirs = [os.path.join(libdir, 'danse'), |
---|
| 179 | os.path.join(libdir, 'data_util'), |
---|
| 180 | os.path.join(libdir, 'DataLoader'), |
---|
| 181 | os.path.join(libdir, 'park'), |
---|
| 182 | os.path.join(libdir, 'sans'), |
---|
| 183 | os.path.join(libdir, 'sans_extension'), |
---|
| 184 | ] |
---|
| 185 | for d in old_dirs: |
---|
| 186 | if os.path.isdir(d): |
---|
| 187 | shutil.rmtree(d) |
---|
[40f9745] | 188 | |
---|
[7b35808] | 189 | # Create a fresh installation folder |
---|
[40f9745] | 190 | if os.path.isdir(INSTALL_FOLDER): |
---|
| 191 | shutil.rmtree(INSTALL_FOLDER) |
---|
| 192 | |
---|
| 193 | os.mkdir(INSTALL_FOLDER) |
---|
| 194 | |
---|
| 195 | # Check that the dependencies are properly installed |
---|
| 196 | check_system() |
---|
| 197 | |
---|
| 198 | # Move to the installation folder |
---|
| 199 | os.chdir(INSTALL_FOLDER) |
---|
| 200 | |
---|
| 201 | if __name__ == "__main__": |
---|
| 202 | import sys |
---|
| 203 | |
---|
[6e2fe95] | 204 | print "Build script for SansView %s" % SANSVIEW |
---|
| 205 | |
---|
| 206 | if len(sys.argv)==1: |
---|
| 207 | # If there is no argument, build the installer |
---|
| 208 | sys.argv.append("-i") |
---|
| 209 | |
---|
[40f9745] | 210 | if len(sys.argv)>1: |
---|
[6e2fe95] | 211 | # Help |
---|
[40f9745] | 212 | if sys.argv[1]=="-h": |
---|
| 213 | print "Usage:" |
---|
| 214 | print " python build_sansview [command]\n" |
---|
| 215 | print "[command] can be any of the following:" |
---|
| 216 | print " -h: lists the command line options" |
---|
| 217 | print " -r: Builds a SansView using the released modules" |
---|
| 218 | print " -t: Builds SansView from the trunk" |
---|
| 219 | print " -i: Builds an installer from the release version" |
---|
[249bae9] | 220 | print " -n: Print out the dependencies for the release notes" |
---|
[fa523d3] | 221 | elif sys.argv[1]=="-n": |
---|
[6e2fe95] | 222 | # Print out release URLs |
---|
[249bae9] | 223 | print SANSMODELS_URL |
---|
| 224 | print DATALOADER_URL |
---|
| 225 | print GUICOMM_URL |
---|
| 226 | print GUIFRAME_URL |
---|
| 227 | print PLOTTOOLS_URL |
---|
| 228 | print UTIL_URL |
---|
[fa523d3] | 229 | print SANSVIEW_URL |
---|
[cd40805] | 230 | print PARK_INTEG_URL |
---|
[249bae9] | 231 | print PARK_URL |
---|
[40f9745] | 232 | else: |
---|
[7b35808] | 233 | logging.info("Build script for SansView %s" % SANSVIEW) |
---|
[40f9745] | 234 | # Prepare installation folder |
---|
| 235 | prepare() |
---|
| 236 | |
---|
| 237 | # Check the command line argument |
---|
| 238 | if sys.argv[1]=="-t": |
---|
[7b35808] | 239 | logging.info("Building trunk version") |
---|
[40f9745] | 240 | checkout() |
---|
| 241 | elif sys.argv[1]=="-r": |
---|
[7b35808] | 242 | logging.info("Building release version") |
---|
[40f9745] | 243 | checkout(True) |
---|
| 244 | elif sys.argv[1]=="-i": |
---|
[7b35808] | 245 | logging.info("Building release version") |
---|
[40f9745] | 246 | checkout(True) |
---|
[7b35808] | 247 | logging.info("Building installer from release version") |
---|
[40f9745] | 248 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
[7b35808] | 249 | os.system("%s setup_exe.py -q py2exe" % PYTHON) |
---|
| 250 | os.system("%s/Q installer.iss" % INNO) |
---|
| 251 | shutil.copy2(os.path.join("Output","setupSansView.exe"), |
---|
| 252 | os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp))) |
---|
| 253 | |
---|
[d9d68ba] | 254 | |
---|