[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 | # |
---|
| 9 | # |
---|
[b81af72] | 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. |
---|
[40f9745] | 12 | # |
---|
[b81af72] | 13 | # - Inno Setup must be installed |
---|
| 14 | # |
---|
| 15 | # - py2exe must be installed |
---|
| 16 | # |
---|
| 17 | # - mingw must be installed |
---|
[249bae9] | 18 | # |
---|
[db7b92e] | 19 | # On Mac: |
---|
[ee370db] | 20 | # - py2app must be installed |
---|
| 21 | # - macholib must be installed to use py2app |
---|
| 22 | # - modulegraph must be installed to use py2app |
---|
[db7b92e] | 23 | # |
---|
[40f9745] | 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. |
---|
[a0288ff] | 29 | # -t: Builds SansView from the trubuild_sank. |
---|
[b81af72] | 30 | # -i: Builds a Windows installer from the release version. |
---|
[249bae9] | 31 | # -n: Print out the dependencies for the release notes |
---|
[40f9745] | 32 | |
---|
| 33 | import os |
---|
[138ac69] | 34 | import sys |
---|
[40f9745] | 35 | import shutil |
---|
[7b35808] | 36 | import logging |
---|
[40f9745] | 37 | |
---|
[7b35808] | 38 | # Installation folder |
---|
| 39 | import time |
---|
| 40 | timestamp = int(time.time()) |
---|
[d3d955e] | 41 | CWD = os.getcwd() |
---|
[7b35808] | 42 | INSTALL_FOLDER = "install_%s" % str(timestamp) |
---|
[138ac69] | 43 | |
---|
| 44 | # On Windows, the python executable is not always on the path. |
---|
| 45 | # Use its most frequent location as the default. |
---|
| 46 | if sys.platform == 'win32': |
---|
| 47 | PYTHON = "c:\python25\python" |
---|
[db7b92e] | 48 | LIB_FOLDER = "%s/%s" % (CWD, INSTALL_FOLDER) |
---|
[138ac69] | 49 | else: |
---|
| 50 | PYTHON = 'python' |
---|
| 51 | |
---|
[db7b92e] | 52 | logging.basicConfig(level=logging.INFO, |
---|
| 53 | format='%(asctime)s %(levelname)s %(message)s', |
---|
| 54 | filename='build_%s.log' % str(timestamp), |
---|
| 55 | filemode='w') |
---|
| 56 | |
---|
[40f9745] | 57 | SVN = "svn" |
---|
| 58 | INNO = "\"c:\Program Files\Inno Setup 5\ISCC\"" |
---|
| 59 | |
---|
[6fcec8a] | 60 | # Release version 1.9 |
---|
[4356634] | 61 | SANSMODELS = "0.9.1" |
---|
[6fcec8a] | 62 | DATALOADER = "0.9" |
---|
[4356634] | 63 | GUIFRAME = "0.9.1" |
---|
| 64 | SANSVIEW = "1.9.1" |
---|
| 65 | PLOTTOOLS = "0.9.1" |
---|
| 66 | UTIL = "0.9.1" |
---|
[f17e082] | 67 | PARK = "1.2.1" |
---|
[4356634] | 68 | PARK_INTEG = "0.9.1" |
---|
| 69 | PRVIEW = "0.9.1" |
---|
[6fcec8a] | 70 | PR_INV = "0.9" |
---|
[4356634] | 71 | CALCULATOR = "0.9.1" |
---|
[6fcec8a] | 72 | CALC_VIEW = "0.9" |
---|
[4356634] | 73 | INVARIANT = "0.9.1" |
---|
[6fcec8a] | 74 | INV_VIEW = "0.9" |
---|
[d54f1b0] | 75 | FIT_VIEW = "0.9.1" |
---|
[249bae9] | 76 | |
---|
[7b35808] | 77 | # URLs for SVN repos |
---|
[249bae9] | 78 | SANSMODELS_URL = "svn://danse.us/sans/releases/sansmodels-%s" % SANSMODELS |
---|
[d54f1b0] | 79 | DATALOADER_URL = "svn://danse.us/sans/releases/sansdataloader-%s" % DATALOADER |
---|
[6b9af19] | 80 | GUIFRAME_URL = "svn://danse.us/sans/releases/sansguiframe-%s" % GUIFRAME |
---|
[249bae9] | 81 | PLOTTOOLS_URL = "svn://danse.us/common/releases/plottools-%s/trunk" % PLOTTOOLS |
---|
| 82 | UTIL_URL = "svn://danse.us/common/releases/util-%s" % UTIL |
---|
| 83 | SANSVIEW_URL = "svn://danse.us/sans/releases/sansview-%s" % SANSVIEW |
---|
[d54f1b0] | 84 | FIT_URL = "svn://danse.us/sans/releases/fittingview-%s" % FIT_VIEW |
---|
[fa523d3] | 85 | PARK_INTEG_URL = "svn://danse.us/sans/releases/park_integration-%s" % PARK_INTEG |
---|
[d9d68ba] | 86 | PARK_URL = "svn://danse.us/park/releases/park-%s" % PARK |
---|
[d54f1b0] | 87 | PRVIEW_URL = "svn://danse.us/sans/releases/inversionview-%s" % PRVIEW |
---|
[b81af72] | 88 | PR_INV_URL = "svn://danse.us/sans/releases/pr_inversion-%s" % PR_INV |
---|
[d54f1b0] | 89 | CALC_URL = "svn://danse.us/sans/releases/sanscalculator-%s" % CALCULATOR |
---|
[d3d955e] | 90 | CALC_VIEW_URL = "svn://danse.us/sans/releases/calculatorview-%s" % CALC_VIEW |
---|
[d54f1b0] | 91 | INV_URL = "svn://danse.us/sans/releases/sansinvariant-%s" % INVARIANT |
---|
[d3d955e] | 92 | INV_VIEW_URL = "svn://danse.us/sans/releases/invariantview-%s" % INV_VIEW |
---|
[40f9745] | 93 | |
---|
| 94 | def check_system(): |
---|
| 95 | """ |
---|
| 96 | Checks that the system has the necessary modules. |
---|
| 97 | """ |
---|
| 98 | try: |
---|
| 99 | import wx |
---|
| 100 | except: |
---|
[7b35808] | 101 | logging.error("wxpython missing") |
---|
[40f9745] | 102 | |
---|
| 103 | try: |
---|
| 104 | import matplotlib |
---|
| 105 | except: |
---|
[7b35808] | 106 | logging.error("matplotlib missing") |
---|
[40f9745] | 107 | |
---|
| 108 | try: |
---|
| 109 | import numpy |
---|
| 110 | except: |
---|
[7b35808] | 111 | logging.error("numpy missing") |
---|
[40f9745] | 112 | |
---|
| 113 | try: |
---|
| 114 | import scipy |
---|
| 115 | except: |
---|
[7b35808] | 116 | logging.error("scipy missing") |
---|
[24fe25d] | 117 | |
---|
| 118 | try: |
---|
| 119 | import periodictable |
---|
| 120 | except: |
---|
| 121 | logging.error("periodictable missing") |
---|
[40f9745] | 122 | |
---|
| 123 | if os.system("gcc -dumpversion")==1: |
---|
[7b35808] | 124 | logging.error("missing mingw") |
---|
[40f9745] | 125 | |
---|
| 126 | def install_pkg(install_dir, setup_dir, url): |
---|
| 127 | """ |
---|
| 128 | Check a package out and install it |
---|
| 129 | |
---|
| 130 | @param install_dir: directory to put the code in |
---|
| 131 | @param setup_dir: relative location of the setup.py script |
---|
| 132 | @param url: URL of the SVN repo |
---|
| 133 | """ |
---|
[d3d955e] | 134 | logging.info("Installing %s" % url) |
---|
| 135 | try: |
---|
| 136 | if not os.path.isdir(install_dir): |
---|
| 137 | os.mkdir(install_dir) |
---|
| 138 | os.chdir(install_dir) |
---|
| 139 | os.system("%s checkout -q %s" % (SVN, url)) |
---|
| 140 | os.chdir(setup_dir) |
---|
| 141 | if sys.platform == 'win32': |
---|
| 142 | os.system("%s setup.py -q build -cmingw32" % PYTHON) |
---|
[db7b92e] | 143 | os.system("%s setup.py -q install --root \"%s\"" % (PYTHON, LIB_FOLDER)) |
---|
[d3d955e] | 144 | else: |
---|
[db7b92e] | 145 | os.system("%s setup.py build" % PYTHON) |
---|
| 146 | os.system("%s setup.py install --prefix ~/.local" % PYTHON) |
---|
[d3d955e] | 147 | except: |
---|
| 148 | logging.error("Install failed for %s" % url) |
---|
| 149 | logging.error(sys.exc_value) |
---|
| 150 | raw_input("Press enter to continue\n") |
---|
| 151 | sys.exit() |
---|
[40f9745] | 152 | |
---|
| 153 | def checkout(release=False): |
---|
| 154 | """ |
---|
| 155 | Check the SansView code out |
---|
| 156 | """ |
---|
| 157 | wd = os.getcwd() |
---|
| 158 | |
---|
| 159 | os.chdir(wd) |
---|
| 160 | if release: |
---|
[d54f1b0] | 161 | install_pkg(".", "sansdataloader-%s" % DATALOADER, DATALOADER_URL) |
---|
[40f9745] | 162 | else: |
---|
[d54f1b0] | 163 | install_pkg(".", "sansdataloader", "svn://danse.us/sans/trunk/sansdataloader") |
---|
[40f9745] | 164 | |
---|
| 165 | os.chdir(wd) |
---|
| 166 | if release: |
---|
[db7b92e] | 167 | install_pkg(".", "sansmodels-%s/src" % SANSMODELS, SANSMODELS_URL) |
---|
[40f9745] | 168 | else: |
---|
[db7b92e] | 169 | install_pkg(".", "sansmodels/src", "svn://danse.us/sans/trunk/sansmodels") |
---|
[40f9745] | 170 | |
---|
| 171 | os.chdir(wd) |
---|
| 172 | if release: |
---|
[d54f1b0] | 173 | install_pkg(".", "sansguiframe-%s" % GUIFRAME, GUIFRAME_URL) |
---|
[40f9745] | 174 | else: |
---|
[d54f1b0] | 175 | install_pkg(".", "sansguiframe", "svn://danse.us/sans/trunk/sansguiframe") |
---|
[40f9745] | 176 | |
---|
| 177 | os.chdir(wd) |
---|
| 178 | if release: |
---|
[249bae9] | 179 | install_pkg("plottools-%s" % PLOTTOOLS, "trunk", PLOTTOOLS_URL) |
---|
[40f9745] | 180 | else: |
---|
| 181 | install_pkg("plottools", "trunk", "svn://danse.us/common/plottools/trunk") |
---|
| 182 | |
---|
| 183 | os.chdir(wd) |
---|
| 184 | if release: |
---|
[249bae9] | 185 | install_pkg(".", "util-%s" % UTIL, UTIL_URL) |
---|
[40f9745] | 186 | else: |
---|
| 187 | install_pkg(".", "util", "svn://danse.us/common/util") |
---|
| 188 | |
---|
[fa523d3] | 189 | os.chdir(wd) |
---|
| 190 | if release: |
---|
| 191 | install_pkg(".", "park_integration-%s" % PARK_INTEG, PARK_INTEG_URL) |
---|
| 192 | else: |
---|
| 193 | install_pkg(".", "park_integration", "svn://danse.us/sans/trunk/park_integration") |
---|
| 194 | |
---|
[b81af72] | 195 | os.chdir(wd) |
---|
| 196 | if release: |
---|
[d54f1b0] | 197 | install_pkg(".", "inversionview-%s" % PRVIEW, PRVIEW_URL) |
---|
[b81af72] | 198 | else: |
---|
[d54f1b0] | 199 | install_pkg(".", "prview", "svn://danse.us/sans/trunk/inversionview") |
---|
[b81af72] | 200 | |
---|
| 201 | os.chdir(wd) |
---|
| 202 | if release: |
---|
| 203 | install_pkg(".", "pr_inversion-%s" % PR_INV, PR_INV_URL) |
---|
| 204 | else: |
---|
| 205 | install_pkg(".", "pr_inversion", "svn://danse.us/sans/trunk/pr_inversion") |
---|
| 206 | |
---|
[d1b43cd] | 207 | os.chdir(wd) |
---|
| 208 | if release: |
---|
[d54f1b0] | 209 | install_pkg(".", "sansinvariant-%s" % INVARIANT, INV_URL) |
---|
[d1b43cd] | 210 | else: |
---|
[d54f1b0] | 211 | install_pkg(".", "Invariant", "svn://danse.us/sans/trunk/sansinvariant") |
---|
[d1b43cd] | 212 | |
---|
| 213 | os.chdir(wd) |
---|
| 214 | if release: |
---|
[d3d955e] | 215 | install_pkg(".", "invariantview-%s" % INV_VIEW, INV_VIEW_URL) |
---|
[d1b43cd] | 216 | else: |
---|
| 217 | install_pkg(".", "invariantview", "svn://danse.us/sans/trunk/invariantview") |
---|
| 218 | |
---|
| 219 | os.chdir(wd) |
---|
| 220 | if release: |
---|
[d3d955e] | 221 | install_pkg(".", "calculatorview-%s" % CALC_VIEW, CALC_VIEW_URL) |
---|
[d1b43cd] | 222 | else: |
---|
| 223 | install_pkg(".", "calculatorview", "svn://danse.us/sans/trunk/calculatorview") |
---|
| 224 | |
---|
| 225 | os.chdir(wd) |
---|
| 226 | if release: |
---|
[d54f1b0] | 227 | install_pkg(".", "sanscalculator-%s" % CALCULATOR, CALC_URL) |
---|
[d1b43cd] | 228 | else: |
---|
[d54f1b0] | 229 | install_pkg(".", "sanscalculator", "svn://danse.us/sans/trunk/sanscalculator") |
---|
[d1b43cd] | 230 | |
---|
[d3d955e] | 231 | |
---|
[40f9745] | 232 | os.chdir(wd) |
---|
| 233 | if release: |
---|
[5353e1c] | 234 | install_pkg(".", "park-%s" % PARK, PARK_URL) |
---|
[40f9745] | 235 | else: |
---|
| 236 | install_pkg(".", "park-1.2", "svn://danse.us/park/branches/park-1.2") |
---|
[d54f1b0] | 237 | |
---|
| 238 | os.chdir(wd) |
---|
| 239 | if release: |
---|
| 240 | os.system(".", "fittingview-%s" % FIT_VIEW, FIT_URL) |
---|
| 241 | else: |
---|
| 242 | os.system(".", "fittingview", "svn://danse.us/sans/trunk/fittingview") |
---|
| 243 | |
---|
[40f9745] | 244 | os.chdir(wd) |
---|
| 245 | if release: |
---|
[7b35808] | 246 | os.system("%s checkout -q %s" % (SVN, SANSVIEW_URL)) |
---|
[40f9745] | 247 | else: |
---|
[7b35808] | 248 | os.system("%s checkout -q svn://danse.us/sans/trunk/sansview" % SVN) |
---|
[40f9745] | 249 | |
---|
[b81cf5c] | 250 | def prepare(wipeout = False): |
---|
[7b35808] | 251 | """ |
---|
| 252 | Prepare the build |
---|
[d3d955e] | 253 | |
---|
| 254 | @param wipeout: If True, the DANSE modules in the standard site-packages will be |
---|
| 255 | removed to avoid conflicts. |
---|
[7b35808] | 256 | """ |
---|
| 257 | # Remove existing libraries |
---|
[b81cf5c] | 258 | if wipeout == True: |
---|
[d3d955e] | 259 | logging.info("Deleting DANSES modules in site-packages") |
---|
[b81cf5c] | 260 | from distutils.sysconfig import get_python_lib |
---|
| 261 | libdir = get_python_lib() |
---|
| 262 | old_dirs = [os.path.join(libdir, 'danse'), |
---|
| 263 | os.path.join(libdir, 'data_util'), |
---|
| 264 | os.path.join(libdir, 'DataLoader'), |
---|
| 265 | os.path.join(libdir, 'park'), |
---|
| 266 | os.path.join(libdir, 'sans'), |
---|
| 267 | os.path.join(libdir, 'sans_extension'), |
---|
| 268 | ] |
---|
| 269 | for d in old_dirs: |
---|
| 270 | if os.path.isdir(d): |
---|
| 271 | shutil.rmtree(d) |
---|
| 272 | |
---|
[7b35808] | 273 | # Create a fresh installation folder |
---|
[40f9745] | 274 | if os.path.isdir(INSTALL_FOLDER): |
---|
| 275 | shutil.rmtree(INSTALL_FOLDER) |
---|
| 276 | |
---|
| 277 | os.mkdir(INSTALL_FOLDER) |
---|
| 278 | |
---|
| 279 | # Check that the dependencies are properly installed |
---|
| 280 | check_system() |
---|
| 281 | |
---|
| 282 | # Move to the installation folder |
---|
| 283 | os.chdir(INSTALL_FOLDER) |
---|
| 284 | |
---|
[531a811c] | 285 | def warning(): |
---|
| 286 | """ |
---|
| 287 | The build script will wipe out part of the site-packages. |
---|
| 288 | Ask the user whether he wants to proceed. |
---|
| 289 | """ |
---|
[b81cf5c] | 290 | print "WARNING!\n" |
---|
[531a811c] | 291 | print "In order to build a clean version of SansView, this script" |
---|
| 292 | print "deletes anything found under site-packages for the following" |
---|
| 293 | print "modules:" |
---|
| 294 | print " - danse" |
---|
| 295 | print " - data_util" |
---|
| 296 | print " - DataLoader" |
---|
| 297 | print " - park" |
---|
| 298 | print " - sans" |
---|
| 299 | print " - sans_extension\n" |
---|
[b81cf5c] | 300 | answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]") |
---|
[531a811c] | 301 | return answer.upper()=="Y" |
---|
| 302 | |
---|
[40f9745] | 303 | if __name__ == "__main__": |
---|
[6e2fe95] | 304 | print "Build script for SansView %s" % SANSVIEW |
---|
| 305 | |
---|
| 306 | if len(sys.argv)==1: |
---|
| 307 | # If there is no argument, build the installer |
---|
| 308 | sys.argv.append("-i") |
---|
| 309 | |
---|
[40f9745] | 310 | if len(sys.argv)>1: |
---|
[6e2fe95] | 311 | # Help |
---|
[40f9745] | 312 | if sys.argv[1]=="-h": |
---|
| 313 | print "Usage:" |
---|
| 314 | print " python build_sansview [command]\n" |
---|
| 315 | print "[command] can be any of the following:" |
---|
| 316 | print " -h: lists the command line options" |
---|
| 317 | print " -r: Builds a SansView using the released modules" |
---|
| 318 | print " -t: Builds SansView from the trunk" |
---|
[138ac69] | 319 | print " -i: Builds an installer from the release version [Windows only]" |
---|
[249bae9] | 320 | print " -n: Print out the dependencies for the release notes" |
---|
[fa523d3] | 321 | elif sys.argv[1]=="-n": |
---|
[6e2fe95] | 322 | # Print out release URLs |
---|
[249bae9] | 323 | print SANSMODELS_URL |
---|
| 324 | print DATALOADER_URL |
---|
| 325 | print GUIFRAME_URL |
---|
| 326 | print PLOTTOOLS_URL |
---|
| 327 | print UTIL_URL |
---|
[fa523d3] | 328 | print SANSVIEW_URL |
---|
[cd40805] | 329 | print PARK_INTEG_URL |
---|
[249bae9] | 330 | print PARK_URL |
---|
[b81af72] | 331 | print PRVIEW |
---|
| 332 | print PR_INV |
---|
[d54f1b0] | 333 | print FIT_URL |
---|
[40f9745] | 334 | else: |
---|
[7b35808] | 335 | logging.info("Build script for SansView %s" % SANSVIEW) |
---|
[b81cf5c] | 336 | |
---|
[40f9745] | 337 | # Prepare installation folder |
---|
[b81cf5c] | 338 | prepare(warning()) |
---|
[40f9745] | 339 | |
---|
| 340 | # Check the command line argument |
---|
| 341 | if sys.argv[1]=="-t": |
---|
[7b35808] | 342 | logging.info("Building trunk version") |
---|
[40f9745] | 343 | checkout() |
---|
| 344 | elif sys.argv[1]=="-r": |
---|
[7b35808] | 345 | logging.info("Building release version") |
---|
[40f9745] | 346 | checkout(True) |
---|
| 347 | elif sys.argv[1]=="-i": |
---|
[7b35808] | 348 | logging.info("Building release version") |
---|
[40f9745] | 349 | checkout(True) |
---|
[138ac69] | 350 | if sys.platform=='win32': |
---|
[db7b92e] | 351 | logging.info("Building Windows installer from release version") |
---|
[138ac69] | 352 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
[db7b92e] | 353 | os.system("%s setup_exe.py py2exe --extrapath \"%s\python25\lib\site-packages\"" % (PYTHON, LIB_FOLDER)) |
---|
[138ac69] | 354 | os.system("%s/Q installer.iss" % INNO) |
---|
| 355 | shutil.copy2(os.path.join("Output","setupSansView.exe"), |
---|
| 356 | os.path.join(CWD, "setupSansView_%s.exe" % str(timestamp))) |
---|
[5353e1c] | 357 | elif sys.platform=='darwin': |
---|
[db7b92e] | 358 | logging.info("Building Mac application from release version") |
---|
| 359 | os.chdir("sansview-%s" % (SANSVIEW)) |
---|
| 360 | os.system("%s setup_mac.py py2app" % PYTHON) |
---|
[138ac69] | 361 | |
---|
[d3d955e] | 362 | raw_input("Press enter to continue\n") |
---|
[d9d68ba] | 363 | |
---|