[6367ec5] | 1 | # |
---|
| 2 | # Script for linux to setup all SansView internal packages (Not on sansview itself) |
---|
| 3 | # |
---|
| 4 | # Usage: |
---|
| 5 | # python setup_all.py |
---|
| 6 | |
---|
| 7 | import os |
---|
| 8 | import sys |
---|
| 9 | import shutil |
---|
| 10 | import logging |
---|
| 11 | |
---|
| 12 | # Installation folder |
---|
| 13 | import time |
---|
| 14 | timestamp = int(time.time()) |
---|
| 15 | CWD = os.getcwd() |
---|
| 16 | |
---|
| 17 | # On Windows, the python executable is not always on the path. |
---|
| 18 | # Use its most frequent location as the default. |
---|
| 19 | if sys.platform == 'win32': |
---|
| 20 | PYTHON = "c:\python25\python" |
---|
| 21 | |
---|
| 22 | else: |
---|
| 23 | PYTHON = 'python' |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | def check_system(): |
---|
| 27 | """ |
---|
| 28 | Checks that the system has the necessary modules. |
---|
| 29 | """ |
---|
| 30 | is_ok = True |
---|
[df83aa4] | 31 | msg = '' |
---|
[6367ec5] | 32 | try: |
---|
| 33 | import wx |
---|
| 34 | if not wx.__version__.count('2.8.11') and \ |
---|
| 35 | not wx.__version__.count('2.8.12'): |
---|
[df83aa4] | 36 | mesg = "wx: Recommending version 2.8.11 or 2.8.12" |
---|
| 37 | msg += mesg + "\n" |
---|
| 38 | print mesg |
---|
[6367ec5] | 39 | except: |
---|
| 40 | is_ok = False |
---|
[df83aa4] | 41 | mesg = "Error: wxpython 2.8.11 (12) missing" |
---|
| 42 | msg += mesg + "\n" |
---|
| 43 | print mesg |
---|
[6367ec5] | 44 | logging.error("wxpython missing") |
---|
| 45 | |
---|
| 46 | try: |
---|
| 47 | import matplotlib |
---|
| 48 | if not matplotlib.__version__.count('0.99.0') and \ |
---|
| 49 | not matplotlib.__version__.count('0.99.1'): |
---|
[df83aa4] | 50 | mesg = "matplotlib: Recommending version 0.99.0 or 0.99.1" |
---|
| 51 | msg += mesg + "\n" |
---|
| 52 | print mesg |
---|
[6367ec5] | 53 | except: |
---|
| 54 | is_ok = False |
---|
[df83aa4] | 55 | mesg = "Error: matplotlib 0.99.0 (1) missing" |
---|
| 56 | msg += mesg + "\n" |
---|
| 57 | print mesg |
---|
[6367ec5] | 58 | logging.error("matplotlib missing") |
---|
| 59 | |
---|
| 60 | try: |
---|
| 61 | import numpy |
---|
| 62 | if not numpy.__version__.count('1.4.1'): |
---|
[df83aa4] | 63 | mesg = "numpy: Recommending version 1.4.1" |
---|
| 64 | msg += mesg + "\n" |
---|
| 65 | print mesg |
---|
[6367ec5] | 66 | except: |
---|
| 67 | is_ok = False |
---|
[df83aa4] | 68 | mesg = "Error: numpy 1.4.1 missing" |
---|
| 69 | msg += mesg + "\n" |
---|
| 70 | print mesg |
---|
[6367ec5] | 71 | logging.error("numpy missing") |
---|
| 72 | |
---|
| 73 | try: |
---|
| 74 | import scipy |
---|
| 75 | if not scipy.__version__.count('0.7.2'): |
---|
[df83aa4] | 76 | mesg = "scipy: Recommending version 0.7.2" |
---|
| 77 | msg += mesg + "\n" |
---|
| 78 | print mesg |
---|
[6367ec5] | 79 | except: |
---|
| 80 | is_ok = False |
---|
[df83aa4] | 81 | mesg = "Error: scipy 0.7.2 missing" |
---|
| 82 | msg += mesg + "\n" |
---|
| 83 | print mesg |
---|
[6367ec5] | 84 | logging.error("scipy missing") |
---|
| 85 | |
---|
| 86 | try: |
---|
| 87 | import periodictable |
---|
| 88 | if not periodictable.__version__.count('1.3.0'): |
---|
[df83aa4] | 89 | mesg = "periodictable: Recommending version 1.3.0" |
---|
| 90 | msg += mesg + "\n" |
---|
| 91 | print mesg |
---|
[6367ec5] | 92 | except: |
---|
| 93 | print "Trying to install perodic table..." |
---|
| 94 | try: |
---|
| 95 | os.system("easy_install periodictable") |
---|
| 96 | print "installed periodictable" |
---|
| 97 | except: |
---|
| 98 | is_ok = False |
---|
[df83aa4] | 99 | mesg = "Error: periodictable missing" |
---|
| 100 | msg += mesg + "\n" |
---|
[6367ec5] | 101 | print "easy_install periodictable failed" |
---|
| 102 | logging.error("periodictable missing") |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | try: |
---|
| 106 | if sys.platform.count("win32")> 0: |
---|
| 107 | from wx.lib.pdfwin import PDFWindow |
---|
| 108 | except: |
---|
| 109 | is_ok = False |
---|
[df83aa4] | 110 | mesg = "comtypes missing" |
---|
| 111 | msg += mesg + "\n" |
---|
| 112 | print mesg |
---|
[6367ec5] | 113 | logging.error("comtypes missing") |
---|
| 114 | |
---|
| 115 | try: |
---|
| 116 | if sys.platform.count("win32")> 0: |
---|
| 117 | import win32com |
---|
| 118 | except: |
---|
| 119 | is_ok = False |
---|
[df83aa4] | 120 | mesg = "pywin32 missing" |
---|
| 121 | msg += mesg + "\n" |
---|
| 122 | print mesg |
---|
[6367ec5] | 123 | logging.error("pywin32 missing") |
---|
| 124 | |
---|
| 125 | try: |
---|
| 126 | import pyparsing |
---|
| 127 | except: |
---|
| 128 | try: |
---|
| 129 | os.system("easy_install pyparsing") |
---|
| 130 | print "installed pyparsing" |
---|
| 131 | except: |
---|
| 132 | is_ok = False |
---|
[df83aa4] | 133 | mesg = "pyparsing missing" |
---|
| 134 | msg += mesg + "\n" |
---|
| 135 | print mesg |
---|
[6367ec5] | 136 | print "easy_install pyparsing failed" |
---|
| 137 | logging.error("pyparsing missing") |
---|
| 138 | |
---|
| 139 | if os.system("gcc -dumpversion")==1: |
---|
| 140 | is_ok = False |
---|
[df83aa4] | 141 | mesg = "missing mingw/gcc" |
---|
| 142 | msg += mesg + "\n" |
---|
| 143 | print mesg |
---|
| 144 | logging.error("missing mingw/gcc") |
---|
[6367ec5] | 145 | |
---|
[df83aa4] | 146 | return is_ok, msg |
---|
[6367ec5] | 147 | |
---|
| 148 | |
---|
| 149 | def install_pkg(setup_dir): |
---|
| 150 | """ |
---|
| 151 | Check a package out and install it |
---|
| 152 | |
---|
| 153 | @param install_dir: directory to put the code in |
---|
| 154 | @param setup_dir: relative location of the setup.py script |
---|
| 155 | @param url: URL of the SVN repo |
---|
| 156 | """ |
---|
| 157 | #print "PYTHON, LIB_FOLDER=====",PYTHON |
---|
| 158 | #logging.info("Installing Pakages" ) |
---|
| 159 | try: |
---|
| 160 | os.chdir(setup_dir) |
---|
[df83aa4] | 161 | os.system("%s setup.py install" % PYTHON) |
---|
| 162 | print "Installation %s successful.." % setup_dir |
---|
[6367ec5] | 163 | except: |
---|
[df83aa4] | 164 | logging.error("Installation failed on %s"% setup_dir) |
---|
[6367ec5] | 165 | logging.error(sys.exc_value) |
---|
| 166 | raw_input("Press enter to continue\n") |
---|
| 167 | sys.exit() |
---|
| 168 | |
---|
| 169 | def install(release=False): |
---|
| 170 | """ |
---|
| 171 | Check the SansView code out |
---|
| 172 | """ |
---|
| 173 | wd = os.getcwd() |
---|
| 174 | os.chdir(wd) |
---|
[df83aa4] | 175 | for folder in os.listdir(wd): |
---|
| 176 | if os.path.isdir(os.path.join(wd, folder)): |
---|
| 177 | if folder.count('sansview') > 0: |
---|
| 178 | setup_dir = folder |
---|
| 179 | try: |
---|
| 180 | install_pkg(folder) |
---|
| 181 | except: |
---|
| 182 | pass |
---|
| 183 | os.chdir(wd) |
---|
[6367ec5] | 184 | |
---|
| 185 | |
---|
| 186 | # run sansview |
---|
| 187 | try: |
---|
| 188 | os.chdir(setup_dir) |
---|
| 189 | os.system("%s sansview.py" % PYTHON) |
---|
| 190 | except: |
---|
| 191 | pass |
---|
| 192 | |
---|
| 193 | # try to make the sansview dir writable to everyone |
---|
| 194 | os.chdir(wd) |
---|
| 195 | try: |
---|
| 196 | os.system("chmod 777 -R %s"% setup_dir) |
---|
| 197 | except: |
---|
| 198 | print "Could not give a permission to everyone for %s." % setup_dir |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | def prepare(wipeout = True): |
---|
| 202 | """ |
---|
| 203 | Prepare the build |
---|
| 204 | |
---|
| 205 | @param wipeout: If True, the DANSE modules in the standard site-packages will be |
---|
| 206 | removed to avoid conflicts. |
---|
| 207 | """ |
---|
| 208 | # Remove existing libraries |
---|
| 209 | if wipeout == True: |
---|
| 210 | |
---|
| 211 | logging.info("Deleting DANSES modules in site-packages") |
---|
| 212 | from distutils.sysconfig import get_python_lib |
---|
| 213 | libdir = get_python_lib() |
---|
| 214 | old_dirs = [os.path.join(libdir, 'danse'), |
---|
| 215 | os.path.join(libdir, 'data_util'), |
---|
| 216 | os.path.join(libdir, 'park'), |
---|
| 217 | os.path.join(libdir, 'sans'), |
---|
| 218 | ] |
---|
| 219 | for d in old_dirs: |
---|
| 220 | if os.path.isdir(d): |
---|
| 221 | shutil.rmtree(d) |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | if __name__ == "__main__": |
---|
| 225 | |
---|
[df83aa4] | 226 | is_ok, _msg = check_system() |
---|
| 227 | if is_ok: |
---|
[6367ec5] | 228 | if len(sys.argv)==1: |
---|
| 229 | # If there is no argument, build the installer |
---|
| 230 | sys.argv.append("-t") |
---|
| 231 | |
---|
| 232 | if len(sys.argv)>1: |
---|
| 233 | # Help |
---|
| 234 | if sys.argv[1]=="-h": |
---|
| 235 | print "Usage:" |
---|
| 236 | print " python build_sansview [command]\n" |
---|
| 237 | print "[command] can be any of the following:" |
---|
| 238 | print " -h: lists the command line options" |
---|
| 239 | print " -r: Builds a SansView using the released modules" |
---|
| 240 | print " -t: Builds SansView from the trunk" |
---|
| 241 | |
---|
| 242 | else: |
---|
[df83aa4] | 243 | logging.info("Build script for SansView") |
---|
[6367ec5] | 244 | print "Warning: This script will delete the previous SansView packages..." |
---|
| 245 | prepare() |
---|
| 246 | # Check the command line argument |
---|
| 247 | if sys.argv[1]=="-t": |
---|
| 248 | logging.info("Building from trunk version") |
---|
| 249 | install() |
---|
| 250 | else: |
---|
| 251 | logging.info("Building from release version") |
---|
| 252 | install(True) |
---|
| 253 | |
---|
| 254 | |
---|
[df83aa4] | 255 | print _msg |
---|
[6367ec5] | 256 | raw_input("Press enter to continue\n") |
---|
| 257 | |
---|
| 258 | else: |
---|
[df83aa4] | 259 | print _msg |
---|
[6367ec5] | 260 | raw_input("Press enter and install the missing packages before re-run this scripts.\n") |
---|