Changeset 3910


Ignore:
Timestamp:
Apr 19, 2019 1:02:23 PM (4 years ago)
Author:
toby
Message:

new packaging including GSAS-II files

Location:
install
Files:
14 added
1 edited

Legend:

Unmodified
Added
Removed
  • install/bootstrap.py

    r3515 r3910  
    22# Installs GSAS-II from network using subversion and creates platform-specific shortcuts.
    33# works for Mac & Linux & Windows
     4from __future__ import division, print_function
    45import os, stat, sys, platform, subprocess, datetime
    56
     
    78g2home = 'https://subversion.xray.aps.anl.gov/pyGSAS/'
    89path2GSAS2 = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
     10
     11skipInstallSteps = False
     12skipDownloadSteps = False
     13skipProxy = False
     14help = False
     15allBinaries = False
     16for a in sys.argv[1:]:
     17    if 'noinstall' in a.lower():
     18        skipInstallSteps = True
     19    elif 'nonet' in a.lower():
     20        skipDownloadSteps = True
     21        skipProxy = True
     22    elif 'noproxy' in a.lower():
     23        skipProxy = True
     24    elif 'help' in a.lower():
     25        help = True
     26    elif 'allbin' in a.lower() or 'server' in a.lower():
     27        allBinaries = True
     28    else:
     29        help = True
     30
     31if help:
     32    print('''
     33  bootstrap.py options:
     34
     35    --noinstall skip post-install, such as creating run shortcuts
     36    --noproxy   do not ask for proxy information
     37    --server    load all binary versions
     38    --allbin    load all binary versions (same as --server)
     39    --help      this message
     40    --nonet     skip steps requiring internet
     41
     42''')
     43    sys.exit()
     44
    945now = str(datetime.datetime.now())
    1046print('Running bootstrap from {} at {}\n\tId: {}'.format(path2GSAS2,now,version))
     
    1248fp.write('Running bootstrap from {} at {}\n\tId: {}\n'.format(path2GSAS2,now,version))
    1349fp.close()
     50       
    1451################################################################################
    1552################################################################################
     
    170207print('Checking python packages...')
    171208missing = []
    172 for pkg in ['numpy','scipy','matplotlib','wx',]:
     209for pkg in ['numpy','scipy','matplotlib','wx','OpenGL',]:
    173210    try:
    174211        exec('import '+pkg)
     
    187224        exec('import '+pkg)
    188225    sys.exit()
    189 try:
    190     import OpenGL
    191     install_with_easyinstall = None
    192 except:
    193     try:                 
    194             from setuptools.command import easy_install                 
    195     except ImportError:
    196         print('You are missing the OpenGL Python package. This can be ')
    197         print('installed by this script if the setuptools package is installed')
    198         print('Please install either OpenGL (pyopengl) or setuptools')
    199         print("package and try running this again.")
     226# try:
     227#     import OpenGL
     228#     install_with_easyinstall = None
     229# except:
     230#     try:               
     231#           from setuptools.command import easy_install                 
     232#     except ImportError:
     233#         print('You are missing the OpenGL Python package. This can be ')
     234#         print('installed by this script if the setuptools package is installed')
     235#         print('Please install either OpenGL (pyopengl) or setuptools')
     236#         print("package and try running this again.")
     237#         sys.exit()
     238#     print("Missing the OpenGL Python package. Will attempt to install this later.")
     239#     def install_with_easyinstall(package):             
     240#         try:                   
     241#             print("trying system-wide ")               
     242#             easy_install.main(['-f',os.path.split(__file__)[0],package])               
     243#             return             
     244#         except:               
     245#             pass               
     246#         try:                   
     247#             print("trying user level ")               
     248#             easy_install.main(['-f',os.path.split(__file__)[0],'--user',package])             
     249#             return             
     250#         except:               
     251#             print("\nInstall of "+package+" failed. Error traceback follows:")
     252#             import traceback                   
     253#             print(traceback.format_exc())
     254#             sys.exit()
     255
     256if not skipDownloadSteps:
     257    host = None
     258    port = '80'
     259    print('\nChecking for subversion...')
     260    svn = whichsvn() # resets host & port if proxyinfo.txt is found
     261    if not svn:
     262        print("Sorry, subversion (svn) could not be found on your system.")
     263        print("Please install this or place in path and rerun this.")
     264        #raise Exception('Subversion (svn) not found')
    200265        sys.exit()
    201     print("Missing the OpenGL Python package. Will attempt to install this later.")
    202     def install_with_easyinstall(package):               
    203         try:             
    204             print("trying system-wide ")                 
    205             easy_install.main(['-f',os.path.split(__file__)[0],package])                 
    206             return               
    207         except:                 
    208             pass                 
    209         try:             
    210             print("trying user level ")                 
    211             easy_install.main(['-f',os.path.split(__file__)[0],'--user',package])               
    212             return               
    213         except:                 
    214             print("\nInstall of "+package+" failed. Error traceback follows:")
    215             import traceback             
    216             print(traceback.format_exc())
    217             sys.exit()
    218 
    219 host = None
    220 port = '80'
    221 print('\nChecking for subversion...')
    222 svn = whichsvn() # resets host & port if proxyinfo.txt is found
    223 if not svn:
    224     print("Sorry, subversion (svn) could not be found on your system.")
    225     print("Please install this or place in path and rerun this.")
    226     #raise Exception('Subversion (svn) not found')
    227     sys.exit()
    228 print(' found svn image: '+svn)
    229 
    230 if install_with_easyinstall:             
    231     print('\nInstalling PyOpenGL. Lots of warnings will follow... ')
    232     install_with_easyinstall('PyOpenGl')                 
    233     print('done.')
     266    print(' found svn image: '+svn)
     267
     268#if install_with_easyinstall:           
     269#    print('\nInstalling PyOpenGL. Lots of warnings will follow... ')
     270#    install_with_easyinstall('PyOpenGl')               
     271#    print('done.')
    234272   
    235273print('Ready to bootstrap GSAS-II from repository\n\t'+g2home+'\nto '+path2GSAS2)
     
    272310# get proxy from user, if terminal available
    273311try:
    274     if host:
     312    if skipProxy:
     313        host = ""
     314    elif host:
    275315        ans = getinput("Enter the proxy address (type none to remove) ["+host+"]: ").strip()
    276316        if ans.lower() == "none": host = ""
     
    300340    fp.close()
    301341
    302 # patch: switch GSAS-II location if linked to XOR server (removed May/June 2017)
    303 cmd = [svn, 'info']
    304 p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    305 res,err = p.communicate()
    306 if '.xor.' in str(res):
    307     print('Switching previous install with .xor. download location to\n\thttps://subversion.xray.aps.anl.gov/pyGSAS')
    308     cmd = [svn, 'switch','--relocate','https://subversion.xor.aps.anl.gov/pyGSAS',
    309            'https://subversion.xray.aps.anl.gov/pyGSAS']
    310     if proxycmds: cmd += proxycmds
     342if not skipDownloadSteps:
     343    # patch: switch GSAS-II location if linked to XOR server (relocated May/June 2017)
     344    cmd = [svn, 'info']
    311345    p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    312346    res,err = p.communicate()
    313     if err:
    314         print('Please report this error to toby@anl.gov:')
    315         print(err)
    316         print(res)
    317 # patch: switch GSAS-II location if switched to 2frame version (removed August 2017)
    318 if '2frame' in str(res):
    319     print('Switching previous 2frame install to trunk\n\thttps://subversion.xray.aps.anl.gov/pyGSAS')
    320     cmd = [svn, 'switch',g2home + '/trunk',path2GSAS2,
    321            '--non-interactive','--trust-server-cert',
    322            '--accept','theirs-conflict','--force','--ignore-ancestry']
    323     if proxycmds: cmd += proxycmds
    324     p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    325     res,err = p.communicate()
    326     if err:
    327         print('Please report this error to toby@anl.gov:')
    328         print(err)
    329         print(res)
    330 
    331 print('\n'+75*'*')
    332 print('Now preparing to install GSAS-II')
    333 tryagain = True
    334 err = False
    335 firstPass = 0
    336 while(tryagain):
    337     tryagain = False
    338     if err:
    339         print('Retrying after a cleanup...')
    340         cmd = [svn, 'cleanup', path2GSAS2]
     347    if '.xor.' in str(res):
     348        print('Switching previous install with .xor. download location to\n\thttps://subversion.xray.aps.anl.gov/pyGSAS')
     349        cmd = [svn, 'switch','--relocate','https://subversion.xor.aps.anl.gov/pyGSAS',
     350               'https://subversion.xray.aps.anl.gov/pyGSAS']
     351        if proxycmds: cmd += proxycmds
     352        p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     353        res,err = p.communicate()
     354        if err:
     355            print('Please report this error to toby@anl.gov:')
     356            print(err)
     357            print(res)
     358    # patch: switch GSAS-II location if switched to 2frame version (removed August 2017)
     359    if '2frame' in str(res):
     360        print('Switching previous 2frame install to trunk\n\thttps://subversion.xray.aps.anl.gov/pyGSAS')
     361        cmd = [svn, 'switch',g2home + '/trunk',path2GSAS2,
     362               '--non-interactive','--trust-server-cert',
     363               '--accept','theirs-conflict','--force','--ignore-ancestry']
     364        if proxycmds: cmd += proxycmds
     365        p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
     366        res,err = p.communicate()
     367        if err:
     368            print('Please report this error to toby@anl.gov:')
     369            print(err)
     370            print(res)
     371
     372    print('\n'+75*'*')
     373    print('Now preparing to install GSAS-II')
     374    tryagain = True
     375    err = False
     376    firstPass = 0
     377    while(tryagain):
     378        tryagain = False
     379        if err:
     380            print('Retrying after a cleanup...')
     381            cmd = [svn, 'cleanup', path2GSAS2]
     382            s = subprocess.Popen(cmd,stderr=subprocess.PIPE)
     383            out,err = s.communicate()   
     384            if err:
     385                print('subversion returned an error:')
     386                print(out)
     387                print(err)
     388        cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2, '--non-interactive', '--trust-server-cert']
     389        if proxycmds: cmd += proxycmds
     390        msg = 'svn load command: '
     391        for item in cmd: msg += " "+item
     392        print(msg)
    341393        s = subprocess.Popen(cmd,stderr=subprocess.PIPE)
    342         out,err = s.communicate()   
     394        print('\nsubversion output:')
     395        out,err = s.communicate()
    343396        if err:
    344397            print('subversion returned an error:')
    345398            print(out)
    346399            print(err)
    347     cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2, '--non-interactive', '--trust-server-cert']
    348     if proxycmds: cmd += proxycmds
    349     msg = 'svn load command: '
    350     for item in cmd: msg += " "+item
    351     print(msg)
    352     s = subprocess.Popen(cmd,stderr=subprocess.PIPE)
    353     print('\nsubversion output:')
    354     out,err = s.communicate()
     400            if firstPass == 0: tryagain = True
     401        firstPass += 1
    355402    if err:
    356         print('subversion returned an error:')
    357         print(out)
    358         print(err)
    359         if firstPass == 0: tryagain = True
    360     firstPass += 1
    361 if err:
    362     print('Retrying with a command for older svn version...')
    363     cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2]
    364     if proxycmds: cmd += proxycmds
    365     msg = ""
    366     for item in cmd: msg += " " + item
    367     print(msg)
    368     s = subprocess.Popen(cmd,stderr=subprocess.PIPE)
    369     out,err = s.communicate()
    370     if err:
    371         print('subversion returned an error:')
    372         print(err)
    373         print('  *** GSAS-II failed to be installed. A likely reason is a network access')
    374         print('  *** problem, most commonly because you need to use a network proxy. Please')
    375         print('  *** check with a network administrator or use http://www.whatismyproxy.com/\n')
    376         sys.exit()
    377 print('\n'+75*'*')
     403        print('Retrying with a command for older svn version...')
     404        cmd = [svn, 'co', g2home+ 'trunk/', path2GSAS2]
     405        if proxycmds: cmd += proxycmds
     406        msg = ""
     407        for item in cmd: msg += " " + item
     408        print(msg)
     409        s = subprocess.Popen(cmd,stderr=subprocess.PIPE)
     410        out,err = s.communicate()
     411        if err:
     412            print('subversion returned an error:')
     413            print(err)
     414            print('  *** GSAS-II failed to be installed. A likely reason is a network access')
     415            print('  *** problem, most commonly because you need to use a network proxy. Please')
     416            print('  *** check with a network administrator or use http://www.whatismyproxy.com/\n')
     417            sys.exit()
     418    print('\n'+75*'*')
    378419
    379420try:
     
    388429    sys.exit()
    389430
    390 for a in sys.argv[1:]:
    391     if 'allbin' in a.lower() or 'server' in a.lower():
    392         print('Loading all binaries with command...')
    393         if not GSASIIpath.svnSwitchDir('AllBinaries','',g2home+ 'Binaries/',None,True):
    394             print('Binary load failed')
    395             sys.exit()
    396         break
     431if allBinaries and skipDownloadSteps:
     432    print('Loading all binaries with command...')
     433    if not GSASIIpath.svnSwitchDir('AllBinaries','',g2home+ 'Binaries/',None,True):
     434        print('Binary load failed')
     435        sys.exit()
    397436else:
    398437    GSASIIpath.DownloadG2Binaries(g2home)
     
    405444try:
    406445    import GSASIIpath
    407     GSASIIpath.SetBinaryPath()
     446    GSASIIpath.SetBinaryPath(loadBinary=False)
    408447    import pyspg
    409448    import histogram2d
     
    413452    pyspg.sgforpy('P -1')
    414453    print('==OK==')
    415 except:
    416     pass
     454except Exception as err:
     455    print(err)
    417456"""
    418457p = subprocess.Popen([sys.executable,'-c',script],stdout=subprocess.PIPE,stderr=subprocess.PIPE,
     
    423462    print('Failed when testing the GSAS-II compiled files. GSAS-II will not run')
    424463    print('without correcting this.\n\nError message:')
    425     #print(res)
    426     print(err)
     464    if res:
     465        print(res.decode())
     466    if err:
     467        print(err.decode())
    427468    #print('\nAttempting to open a web page on compiling GSAS-II...')
    428469    print('Please see web page\nhttps://subversion.xray.aps.anl.gov/trac/pyGSAS/wiki/CompileGSASII')
     
    441482#===========================================================================
    442483# import all .py files so that .pyc files get created
    443 print('Byte-compiling all .py files...')
    444 import compileall
    445 compileall.compile_dir(path2GSAS2,quiet=True)
    446 print('done')
     484if not skipInstallSteps:
     485    print('Byte-compiling all .py files...')
     486    import compileall
     487    compileall.compile_dir(path2GSAS2,quiet=True)
     488    print('done')
    447489#===========================================================================
    448490# platform-dependent stuff
     
    452494        with open(file) as source_file:
    453495            exec(source_file.read())
     496
     497if skipInstallSteps:
     498    pass
     499#===========================================================================
    454500# on Windows, make a batch file with Python and GSAS-II location hard-coded
    455 if sys.platform.startswith('win') and os.path.exists(
     501elif sys.platform.startswith('win') and os.path.exists(
    456502    os.path.join(path2GSAS2,"makeBat.py")):
    457503    execfile(os.path.join(path2GSAS2,"makeBat.py"))
Note: See TracChangeset for help on using the changeset viewer.