[807560b] | 1 | # |
---|
| 2 | # Script to get source from SVN and build PrView |
---|
| 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 | # - Inno Setup must be installed |
---|
| 13 | # - py2exe must be installed |
---|
| 14 | # - mingw must be installed |
---|
| 15 | # |
---|
| 16 | # In Mac: |
---|
| 17 | # - py2app must be installed |
---|
| 18 | # - macholib must be installed to use py2app |
---|
| 19 | # - modulegraph must be installed to use py2app |
---|
| 20 | # |
---|
| 21 | # Usage: |
---|
| 22 | # python build_prview [command] |
---|
| 23 | # [command] can be any of the following: |
---|
| 24 | # -h: lists the command line options |
---|
| 25 | # -r: Builds a PrView using the released modules. |
---|
| 26 | # -t: Builds PrView from the trunk. |
---|
| 27 | # -i: Builds an installer from the release version. |
---|
| 28 | # -n: Print out the dependencies for the release notes |
---|
| 29 | |
---|
| 30 | import os |
---|
| 31 | import sys |
---|
| 32 | import shutil |
---|
| 33 | import logging |
---|
| 34 | |
---|
| 35 | # Installation folder |
---|
| 36 | import time |
---|
| 37 | timestamp = int(time.time()) |
---|
| 38 | CWD = os.getcwd() |
---|
| 39 | INSTALL_FOLDER = "install_%s" % str(timestamp) |
---|
| 40 | |
---|
| 41 | # On Windows, the python executable is not always on the path. |
---|
| 42 | # Use its most frequent location as the default. |
---|
| 43 | if sys.platform == 'win32': |
---|
| 44 | PYTHON = "c:\python25\python" |
---|
| 45 | LIB_FOLDER = "%s/%s" % (CWD, INSTALL_FOLDER) |
---|
| 46 | else: |
---|
| 47 | PYTHON = 'python' |
---|
| 48 | |
---|
| 49 | logging.basicConfig(level=logging.INFO, |
---|
| 50 | format='%(asctime)s %(levelname)s %(message)s', |
---|
| 51 | filename='build_%s.log' % str(timestamp), |
---|
| 52 | filemode='w') |
---|
| 53 | |
---|
| 54 | SVN = "svn" |
---|
| 55 | INNO = "\"c:\Program Files\Inno Setup 5\ISCC\"" |
---|
| 56 | |
---|
| 57 | # Release version 0.3.3 |
---|
| 58 | DATALOADER = "0.2.7" |
---|
| 59 | GUICOMM = "0.1.5" |
---|
| 60 | GUIFRAME = "0.2.0" |
---|
| 61 | PRVIEW = "0.3.3" |
---|
| 62 | PLOTTOOLS = "0.1.9" |
---|
| 63 | UTIL = "0.1.5" |
---|
| 64 | INV_VIEW = "0.2.5" |
---|
| 65 | PR_INV = "0.2.5" |
---|
| 66 | |
---|
| 67 | # URLs for SVN repos |
---|
| 68 | DATALOADER_URL = "svn://danse.us/sans/releases/sansdataloader-%s" % DATALOADER |
---|
| 69 | GUIFRAME_URL = "svn://danse.us/sans/releases/sansguiframe-%s" % GUIFRAME |
---|
| 70 | PLOTTOOLS_URL = "svn://danse.us/common/releases/plottools-%s/trunk" % PLOTTOOLS |
---|
| 71 | UTIL_URL = "svn://danse.us/common/releases/util-%s" % UTIL |
---|
| 72 | INV_VIEW_URL = "svn://danse.us/sans/releases/inversionview-%s" % INV_VIEW |
---|
| 73 | PRVIEW_URL = "svn://danse.us/sans/releases/prview-%s" % PRVIEW |
---|
| 74 | PR_INV_URL = "svn://danse.us/sans/releases/pr_inversion-%s" % PR_INV |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | def check_system(): |
---|
| 78 | """ |
---|
| 79 | Checks that the system has the necessary modules. |
---|
| 80 | """ |
---|
| 81 | try: |
---|
| 82 | import wx |
---|
| 83 | except: |
---|
| 84 | logging.error("wxpython missing") |
---|
| 85 | |
---|
| 86 | try: |
---|
| 87 | import matplotlib |
---|
| 88 | except: |
---|
| 89 | logging.error("matplotlib missing") |
---|
| 90 | |
---|
| 91 | try: |
---|
| 92 | import numpy |
---|
| 93 | except: |
---|
| 94 | logging.error("numpy missing") |
---|
| 95 | |
---|
| 96 | try: |
---|
| 97 | import scipy |
---|
| 98 | except: |
---|
| 99 | logging.error("scipy missing") |
---|
| 100 | |
---|
| 101 | if os.system("gcc -dumpversion")==1: |
---|
| 102 | logging.error("missing mingw") |
---|
| 103 | |
---|
| 104 | def install_pkg(install_dir, setup_dir, url): |
---|
| 105 | """ |
---|
| 106 | Check a package out and install it |
---|
| 107 | |
---|
| 108 | @param install_dir: directory to put the code in |
---|
| 109 | @param setup_dir: relative location of the setup.py script |
---|
| 110 | @param url: URL of the SVN repo |
---|
| 111 | """ |
---|
| 112 | logging.info("Installing %s" % url) |
---|
| 113 | try: |
---|
| 114 | if not os.path.isdir(install_dir): |
---|
| 115 | os.mkdir(install_dir) |
---|
| 116 | os.chdir(install_dir) |
---|
| 117 | os.system("%s checkout -q %s" % (SVN, url)) |
---|
| 118 | os.chdir(setup_dir) |
---|
| 119 | if sys.platform == 'win32': |
---|
| 120 | os.system("%s setup.py -q build -cmingw32" % PYTHON) |
---|
| 121 | os.system("%s setup.py -q install --root \"%s\"" % (PYTHON, LIB_FOLDER)) |
---|
| 122 | else: |
---|
| 123 | os.system("%s setup.py build" % PYTHON) |
---|
| 124 | os.system("%s setup.py install --prefix ~/.local" % PYTHON) |
---|
| 125 | except: |
---|
| 126 | logging.error("Install failed for %s" % url) |
---|
| 127 | logging.error(sys.exc_value) |
---|
| 128 | raw_input("Press enter to continue\n") |
---|
| 129 | sys.exit() |
---|
| 130 | |
---|
| 131 | def checkout(release=False): |
---|
| 132 | """ |
---|
| 133 | Check the PrView code out |
---|
| 134 | """ |
---|
| 135 | wd = os.getcwd() |
---|
| 136 | |
---|
| 137 | os.chdir(wd) |
---|
| 138 | if release: |
---|
| 139 | install_pkg(".", "sansdataloader-%s" % DATALOADER, DATALOADER_URL) |
---|
| 140 | else: |
---|
| 141 | install_pkg(".", "sansdataloader", "svn://danse.us/sans/trunk/sansdataloader") |
---|
| 142 | |
---|
| 143 | os.chdir(wd) |
---|
| 144 | if release: |
---|
| 145 | install_pkg(".", "sansguiframe-%s" % GUIFRAME, GUIFRAME_URL) |
---|
| 146 | else: |
---|
| 147 | install_pkg(".", "sansguiframe", "svn://danse.us/sans/trunk/sansguiframe") |
---|
| 148 | |
---|
| 149 | os.chdir(wd) |
---|
| 150 | if release: |
---|
| 151 | install_pkg(".", "inversionview-%s" % INV_VIEW, INV_VIEW_URL) |
---|
| 152 | else: |
---|
| 153 | install_pkg(".", "inversionview", "svn://danse.us/sans/trunk/inversionview") |
---|
| 154 | |
---|
| 155 | os.chdir(wd) |
---|
| 156 | if release: |
---|
| 157 | install_pkg("plottools-%s" % PLOTTOOLS, "trunk", PLOTTOOLS_URL) |
---|
| 158 | else: |
---|
| 159 | install_pkg("plottools", "trunk", "svn://danse.us/common/plottools/trunk") |
---|
| 160 | |
---|
| 161 | os.chdir(wd) |
---|
| 162 | if release: |
---|
| 163 | install_pkg(".", "util-%s" % UTIL, UTIL_URL) |
---|
| 164 | else: |
---|
| 165 | install_pkg(".", "util", "svn://danse.us/common/util") |
---|
| 166 | |
---|
| 167 | os.chdir(wd) |
---|
| 168 | if release: |
---|
| 169 | install_pkg(".", "pr_inversion-%s" % PR_INV, PR_INV_URL) |
---|
| 170 | else: |
---|
| 171 | install_pkg(".", "pr_inversion", "svn://danse.us/sans/trunk/pr_inversion") |
---|
| 172 | |
---|
| 173 | os.chdir(wd) |
---|
| 174 | if release: |
---|
| 175 | os.system("%s checkout -q %s" % (SVN, PRVIEW_URL)) |
---|
| 176 | else: |
---|
| 177 | os.system("%s checkout -q svn://danse.us/sans/trunk/prview" % SVN) |
---|
| 178 | |
---|
| 179 | def prepare(wipeout = False): |
---|
| 180 | """ |
---|
| 181 | Prepare the build |
---|
| 182 | |
---|
| 183 | @param wipeout: If True, the DANSE modules in the standard site-packages will be |
---|
| 184 | removed to avoid conflicts. |
---|
| 185 | """ |
---|
| 186 | # Remove existing libraries |
---|
| 187 | if wipeout == True: |
---|
| 188 | logging.info("Deleting DANSES modules in site-packages") |
---|
| 189 | from distutils.sysconfig import get_python_lib |
---|
| 190 | libdir = get_python_lib() |
---|
| 191 | old_dirs = [os.path.join(libdir, 'danse'), |
---|
| 192 | os.path.join(libdir, 'data_util'), |
---|
| 193 | os.path.join(libdir, 'sansdataloader'), |
---|
| 194 | os.path.join(libdir, 'sans'), |
---|
| 195 | os.path.join(libdir, 'sans_extension'), |
---|
| 196 | ] |
---|
| 197 | for d in old_dirs: |
---|
| 198 | if os.path.isdir(d): |
---|
| 199 | shutil.rmtree(d) |
---|
| 200 | |
---|
| 201 | # Create a fresh installation folder |
---|
| 202 | if os.path.isdir(INSTALL_FOLDER): |
---|
| 203 | shutil.rmtree(INSTALL_FOLDER) |
---|
| 204 | |
---|
| 205 | os.mkdir(INSTALL_FOLDER) |
---|
| 206 | |
---|
| 207 | # Check that the dependencies are properly installed |
---|
| 208 | check_system() |
---|
| 209 | |
---|
| 210 | # Move to the installation folder |
---|
| 211 | os.chdir(INSTALL_FOLDER) |
---|
| 212 | |
---|
| 213 | def warning(): |
---|
| 214 | """ |
---|
| 215 | The build script will wipe out part of the site-packages. |
---|
| 216 | Ask the user whether he wants to proceed. |
---|
| 217 | """ |
---|
| 218 | print "WARNING!\n" |
---|
| 219 | print "In order to build a clean version of PrView, this script" |
---|
| 220 | print "deletes anything found under site-packages for the following" |
---|
| 221 | print "modules:" |
---|
| 222 | print " - danse" |
---|
| 223 | print " - data_util" |
---|
| 224 | print " - sansdataloader" |
---|
| 225 | print " - sans" |
---|
| 226 | print " - sans_extension\n" |
---|
| 227 | answer = raw_input("Do you want to delete those modules [Y] or continue with a dirty installation [N]? [Y|N]") |
---|
| 228 | return answer.upper()=="Y" |
---|
| 229 | |
---|
| 230 | if __name__ == "__main__": |
---|
| 231 | print "Build script for PrView %s" % PRVIEW |
---|
| 232 | |
---|
| 233 | if len(sys.argv)==1: |
---|
| 234 | # If there is no argument, build the installer |
---|
| 235 | sys.argv.append("-i") |
---|
| 236 | |
---|
| 237 | if len(sys.argv)>1: |
---|
| 238 | # Help |
---|
| 239 | if sys.argv[1]=="-h": |
---|
| 240 | print "Usage:" |
---|
| 241 | print " python build_prview [command]\n" |
---|
| 242 | print "[command] can be any of the following:" |
---|
| 243 | print " -h: lists the command line options" |
---|
| 244 | print " -r: Builds a PrView using the released modules" |
---|
| 245 | print " -t: Builds PrView from the trunk" |
---|
| 246 | print " -i: Builds an installer from the release version [Windows only]" |
---|
| 247 | print " -n: Print out the dependencies for the release notes" |
---|
| 248 | elif sys.argv[1]=="-n": |
---|
| 249 | # Print out release URLs |
---|
| 250 | print DATALOADER_URL |
---|
| 251 | print GUIFRAME_URL |
---|
| 252 | print PLOTTOOLS_URL |
---|
| 253 | print UTIL_URL |
---|
| 254 | print PRVIEW_URL |
---|
| 255 | print INV_VIEW_URL |
---|
| 256 | print PR_INV_URL |
---|
| 257 | else: |
---|
| 258 | logging.info("Build script for PrView %s" % PRVIEW) |
---|
| 259 | |
---|
| 260 | # Prepare installation folder |
---|
| 261 | prepare(warning()) |
---|
| 262 | |
---|
| 263 | # Check the command line argument |
---|
| 264 | if sys.argv[1]=="-t": |
---|
| 265 | logging.info("Building trunk version") |
---|
| 266 | checkout() |
---|
| 267 | elif sys.argv[1]=="-r": |
---|
| 268 | logging.info("Building release version") |
---|
| 269 | checkout(True) |
---|
| 270 | elif sys.argv[1]=="-i": |
---|
| 271 | logging.info("Building release version") |
---|
| 272 | checkout(True) |
---|
| 273 | if sys.platform=='win32': |
---|
| 274 | logging.info("Building Windows installer from release version") |
---|
| 275 | os.chdir("prview-%s" % (PRVIEW)) |
---|
| 276 | os.system("%s setup_exe.py py2exe --extrapath \"%s\python25\lib\site-packages\"" % (PYTHON, LIB_FOLDER)) |
---|
| 277 | os.system("%s/Q installer.iss" % INNO) |
---|
| 278 | shutil.copy2(os.path.join("Output","setupPrView.exe"), |
---|
| 279 | os.path.join(CWD, "setupPrView_%s.exe" % str(timestamp))) |
---|
| 280 | elif sys.platform=='darwin': |
---|
| 281 | logging.info("Building Mac application from release version") |
---|
| 282 | os.chdir("prview-%s" % (PRVIEW)) |
---|
| 283 | os.system("%s setup_mac.py py2app" % PYTHON) |
---|
| 284 | |
---|
| 285 | raw_input("Press enter to continue\n") |
---|