Changeset 45576


Ignore:
Timestamp:
Mar 5, 2011, 10:21:31 AM (13 years ago)
Author:
martinl
Message:

osgeo4w: grass.bat.tmpl added / grass.py updated for osgeo4w

Location:
grass/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/lib/init/grass.py

    r45387 r45576  
    44# MODULE:       GRASS initialization (Python)
    55# AUTHOR(S):    Original author unknown - probably CERL
    6 #               Andreas Lange - Germany - andreas.lange at rhein-main.de
    7 #               Huidae Cho - Korea - grass4u at gmail.com
    8 #               Justin Hickey - Thailand - jhickey at hpcc.nectec.or.th
    9 #               Markus Neteler - Germany/Italy - neteler at itc.it
    10 #               Hamish Bowman - New Zealand - hamish_b at yahoo,com
     6#               Andreas Lange <andreas.lange rhein-main.de>
     7#               Huidae Cho <grass4u gmail.com>
     8#               Justin Hickey <jhickey hpcc.nectec.or.th>
     9#               Markus Neteler <neteler osgeo.org>
     10#               Hamish Bowman <hamish_b yahoo,com>
    1111#               Converted to Python (based on init.sh) by Glynn Clements
    12 #               Martin Landa - Czech Republic - landa.martin at gmail.com
    13 # PURPOSE:      Sets up some environment variables.
    14 #               It also parses any remaining command line options for
    15 #               setting the GISDBASE, LOCATION, and/or MAPSET.
    16 #               Finally it starts GRASS with the appropriate user
     12#               Martin Landa <landa.martin gmail.com>
     13# PURPOSE:      Sets up environment variables, parses any remaining
     14#               command line options for setting the GISDBASE, LOCATION,
     15#               and/or MAPSET. Finally it starts GRASS with the appropriate user
    1716#               interface and cleans up after it is finished.
    18 # COPYRIGHT:    (C) 2000-2010 by the GRASS Development Team
     17# COPYRIGHT:    (C) 2000-2011 by the GRASS Development Team
    1918#
    2019#               This program is free software under the GNU General
     
    3332
    3433# Variables substituted during build process
    35 # Set the GISBASE variable
    36 gisbase = "@GISBASE@"
     34if os.environ.has_key('GISBASE'):
     35    gisbase = os.environ['GISBASE']
     36else:
     37    gisbase = "@GISBASE@"
    3738cmd_name = "@START_UP@"
    3839grass_version = "@GRASS_VERSION_NUMBER@"
    3940ld_library_path_var = '@LD_LIBRARY_PATH_VAR@'
    40 config_projshare = "@CONFIG_PROJSHARE@"
     41if os.environ.has_key('GRASS_PROJSHARE'):
     42    config_projshare = os.environ['GRASS_PROJSHARE']
     43else:
     44    config_projshare = "@CONFIG_PROJSHARE@"
    4145grass_config_dirname = "@GRASS_CONFIG_DIR@"
    4246
    4347gisbase = os.path.normpath(gisbase)
    4448
    45 ### i18N
     49# i18N
    4650import gettext
    4751gettext.install('grasslibs', os.path.join(gisbase, 'locale'), unicode=True)
     
    6872        pass
    6973
    70 def cleanup_dir(dir):
    71     if not dir:
     74def cleanup_dir(path):
     75    if not path:
    7276        return
    73 
    74     for root, dirs, files in os.walk(dir, topdown = False):
     77   
     78    for root, dirs, files in os.walk(path, topdown = False):
    7579        for name in files:
    76                 try_remove(os.path.join(root, name))
     80            try_remove(os.path.join(root, name))
    7781        for name in dirs:
    78                 try_rmdir(os.path.join(root, name))
    79 
     82            try_rmdir(os.path.join(root, name))
     83   
    8084def cleanup():
    8185    tmpdir, lockfile
     
    9195    sys.stderr.write(msg + "\n")
    9296    sys.stderr.flush()
    93    
     97
    9498def readfile(path):
    9599    f = open(path, 'r')
     
    201205    except:
    202206        s = None
    203 
     207   
    204208    # Copy the global grassrc file to the session grassrc file
    205209    if s:
    206210        writefile(gisrc, s)
    207 
     211   
    208212def read_gisrc():
    209213    kv = {}
     
    238242    if not grass_gui:
    239243        grass_gui = default_gui
    240 
     244   
    241245    if grass_gui == 'gui':
    242246        grass_gui = default_gui
     
    277281    path_prepend(gfile('scripts'), 'PATH')
    278282    path_prepend(gfile('bin'), 'PATH')
    279 
     283   
    280284    # Set PYTHONPATH to find GRASS Python modules
    281285    path_prepend(gfile('etc', 'python'), 'PYTHONPATH')
    282 
     286   
    283287    # Add .py (Python) to list of executable extensions to search for in MS-Windows PATH
    284288    if windows:
    285289        path_append('.PY', 'PATHEXT')
    286 
     290   
    287291def find_exe(pgm):
    288292    for dir in os.getenv('PATH').split(os.pathsep):
     
    304308            pager = "cat"
    305309        os.environ['GRASS_PAGER'] = pager
    306 
     310   
    307311    # GRASS_WISH
    308312    if not os.getenv('GRASS_WISH'):
    309313        os.environ['GRASS_WISH'] = "wish"
    310 
     314   
    311315    # GRASS_PYTHON
    312316    if not os.getenv('GRASS_PYTHON'):
     
    315319        else:
    316320            os.environ['GRASS_PYTHON'] = "python"
    317 
     321   
    318322    # GRASS_GNUPLOT
    319323    if not os.getenv('GRASS_GNUPLOT'):
    320324        os.environ['GRASS_GNUPLOT'] = "gnuplot -persist"
    321 
     325   
    322326    # GRASS_PROJSHARE
    323327    if not os.getenv('GRASS_PROJSHARE'):
    324328        os.environ['GRASS_PROJSHARE'] = config_projshare
    325 
     329       
    326330def set_browser():
    327331    # GRASS_HTML_BROWSER
     
    332336            browser = gfile('etc', "html_browser_mac.sh")
    333337            os.environ['GRASS_HTML_BROWSER_MACOSX'] = "-b com.apple.helpviewer"
    334 
     338       
    335339        if windows or cygwin:
    336340            # MinGW startup moved to into init.bat
     
    349353        os.environ['GRASS_HTML_BROWSER_MACOSX'] = "-b %s" % browser
    350354        browser = gfile('etc', "html_browser_mac.sh")
    351 
     355   
    352356    if not browser:
    353357        warning(_("Searched for a web browser, but none found"))
     
    368372        sys.stderr.write(line)
    369373    f.close()
    370 
     374   
    371375    sys.stderr.write("\n")
    372376    sys.stderr.write(_("Hit RETURN to continue"))
    373377    sys.stdin.readline()
    374 
     378   
    375379    #for convenience, define pwd as GISDBASE:
    376380    s = r"""GISDBASE: %s
     
    406410                sys.stdin.readline()
    407411                grass_gui = 'text'
    408 
     412   
    409413    else:
    410414        # Display a message if a graphical interface was expected
     
    417421            sys.stdin.readline()
    418422            grass_gui = 'text'
    419 
     423   
    420424    # Save the user interface variable in the grassrc file - choose a temporary
    421425    # file name that should not match another file
     
    429433    # Try non-interactive startup
    430434    l = None
    431 
     435   
    432436    if arg == '-':
    433437        if location:
     
    435439    else:
    436440        l = arg
    437 
     441   
    438442    if l:
    439443        if l == '.':
     
    441445        elif not os.path.isabs(l):
    442446            l = os.path.abspath(l)
    443 
     447       
    444448        l, mapset = os.path.split(l)
    445449        if not mapset:
     
    447451        l, location_name = os.path.split(l)
    448452        gisdbase = l
    449 
     453   
    450454    if gisdbase and location_name and mapset:
    451455        location = os.path.join(gisdbase, location_name, mapset)
    452 
     456       
    453457        if not os.access(os.path.join(location, "WIND"), os.R_OK):
    454458            if location_name == "PERMANENT":
     
    467471                else:
    468472                    fatal(_("<%s> is not a valid GRASS location") % location)
    469 
     473       
    470474        if os.access(gisrc, os.R_OK):
    471475            kv = read_gisrc()
    472476        else:
    473477            kv = {}
    474 
     478       
    475479        kv['GISDBASE'] = gisdbase
    476480        kv['LOCATION_NAME'] = location_name
     
    480484        fatal(_("GISDBASE, LOCATION_NAME and MAPSET variables not set properly.\n"
    481485                "Interactive startup needed."))
    482 
     486   
    483487def set_data():
    484488    # User selects LOCATION and MAPSET if not set
     
    494498            fatal(_("Invalid user interface specified - <%s>.\n"
    495499                    "Use the --help option to see valid interface names.") % grass_gui)
    496 
     500   
    497501def gui_startup():
    498502    if grass_gui == 'wxpython':
     
    510514                  "Hit RETURN to continue..."))
    511515        sys.stdin.readline()
    512 
     516       
    513517        os.execlp(cmd_name, "-text")
    514518        sys.exit(1)
     
    520524        fatal(_("Invalid return code from GUI startup script.\n"
    521525                "Please advise GRASS developers of this error."))
    522 
     526   
    523527def load_gisrc():
    524528    global gisdbase, location_name, mapset, location
     
    554558    else:
    555559        msg = _("Unable to properly access \"%s\"\nPlease notify system personel.") % lockfile
    556        
     560   
    557561    if msg:
    558562        if grass_gui == "wxpython":
     
    566570        message(_("Building user fontcap..."))
    567571        call(["g.mkfontcap"])
    568 
     572   
    569573def check_shell():
    570574    global sh, shellname
     
    590594        else:
    591595            shellname = "shell"
    592 
     596   
    593597    # check for SHELL
    594598    if not os.getenv('SHELL'):
    595599        fatal(_("The SHELL variable is not set"))
    596 
     600   
    597601def check_batch_job():
    598602    global batch_job
     
    616620            bj.wait()
    617621            message(_("Execution of '%s' finished.") % batch_job)
    618 
     622   
    619623def start_gui():
    620624    # Start the chosen GUI but ignore text
     
    635639        if not os.getenv('GRASS_BATCH_JOB') and not grass_debug:
    636640            call(["tput", "clear"])
    637 
     641   
    638642def show_banner():
    639643    sys.stderr.write(r"""
     
    669673       _("Help is available with the command:"),
    670674       _("See the licence terms with:")))
    671 
     675   
    672676    if grass_gui == 'wxpython':
    673677        message("%-41sg.gui wxpython" % _("If required, restart the GUI with:"))
    674678    else:
    675679        message("%-41sg.gui %s" % (_("Start the GUI with:"), default_gui))
    676 
     680   
    677681    message("%-41sexit" % _("When ready to quit enter:"))
    678682    message("")
     
    680684def csh_startup():
    681685    global exit_val
    682 
     686   
    683687    userhome = os.getenv('HOME')      # save original home
    684688    home = location
    685689    os.environ['HOME'] = home
    686 
     690   
    687691    cshrc = os.path.join(home, ".cshrc")
    688692    tcshrc = os.path.join(home, ".tcshrc")
    689693    try_remove(cshrc)
    690694    try_remove(tcshrc)
    691 
     695   
    692696    f = open(cshrc, 'w')
    693697    f.write("set home = %s" % userhome)
    694698    f.write("set history = 3000 savehist = 3000  noclobber ignoreeof")
    695699    f.write("set histfile = %s" % os.path.join(os.getenv('HOME'), ".history"))
    696 
     700   
    697701    f.write("set prompt = '\\")
    698702    f.write("Mapset <%s> in Location <%s> \\" % (mapset, location_name))
    699703    f.write("GRASS %s > '" % grass_version)
    700704    f.write("set BOGUS=``;unset BOGUS")
    701 
     705   
    702706    path = os.path.join(userhome, ".grass.cshrc")
    703707    if os.access(path, os.R_OK):
    704708        f.write(readfile(path))
    705 
     709   
    706710    mail_re = re.compile(r"^ *set  *mail *= *")
    707 
     711   
    708712    for filename in [".cshrc", ".tcshrc", ".login"]:
    709713        path = os.path.join(userhome, filename)
     
    714718                if mail_re.match(l):
    715719                    f.write(l)
    716 
     720   
    717721    path = os.getenv('PATH').split(':')
    718722    f.write("set path = ( %s ) " % ' '.join(path))
    719 
     723   
    720724    f.close()
    721725    writefile(tcshrc, readfile(cshrc))
    722 
     726   
    723727    exit_val = call([gfile("etc", "run"), os.getenv('SHELL')])
    724 
     728   
    725729    os.environ['HOME'] = userhome
    726 
     730   
    727731def bash_startup():
    728732    global exit_val
     
    776780        os.environ['PS1'] = "GRASS %s (%s):\w > " % (grass_version, location_name)
    777781        exit_val = call([gfile("etc", "run"), os.getenv('SHELL')])
    778 
     782   
    779783    if exit_val != 0:
    780784        fatal(_("Failed to start shell '%s'") % os.getenv('SHELL'))
     
    790794        message(_("Goodbye from GRASS GIS"))
    791795        message("")
    792 
     796   
    793797def clean_temp():
    794798    message(_("Cleaning up temporary files..."))
     
    796800    call([gfile("etc", "clean_temp")], stdout = nul, stderr = nul)
    797801    nul.close()
    798 
     802   
    799803def get_username():
    800804    global user
     
    817821        if not user:
    818822            user = "user_%d" % os.getuid()
    819 
     823   
    820824def parse_cmdline():
    821825    global args, grass_gui, create_new
     
    947951
    948952# Parsing argument to get LOCATION
    949 if args == []:
     953if not args:
    950954    # Try interactive startup
    951955    location = None
     
    993997    if grass_gui == "wxpython":
    994998        message(_("Launching '%s' GUI in the background, please wait...") % grass_gui)
    995    
     999
    9961000if sh in ['csh', 'tcsh']:
    9971001    csh_startup()
     
    10151019cleanup()
    10161020
    1017 #### after this point no more grass modules may be called ####
     1021# After this point no more grass modules may be called
    10181022
    10191023done_message()
  • grass/trunk/mswindows/osgeo4w/package.sh

    r45532 r45576  
    6565export VERSION=$MAJOR.$MINOR.$PATCH
    6666
    67 export GRASS_PYTHON=/c/OSGeo4W/apps/Python25
    68 export PYTHONHOME=/c/OSGeo4W/apps/Python25
     67export GRASS_PYTHON="/c/OSGeo4W/bin/python.exe"
     68export PYTHONHOME="/c/OSGeo4W/apps/Python25"
    6969
    7070if [ -f mswindows/osgeo4w/package.log ]; then
     
    135135cp mswindows/osgeo4w/config.h.switch $OSGEO4W_ROOT_MSYS/apps/grass/grass-$VERSION/include/grass/config.h
    136136cp mswindows/osgeo4w/config.h.vc $OSGEO4W_ROOT_MSYS/apps/grass/grass-$VERSION/include/grass
    137 sed -e "s#@VERSION@#$VERSION#g" -e "s#@OSGEO4W_ROOT@#$OSGEO4W_ROOT#g" \
     137sed -e "s#@OSGEO4W_ROOT_MSYS@#$OSGEO4W_ROOT_MSYS#g" -e "s#@VERSION@#$VERSION#g" -e "s#@POSTFIX@#$MAJOR$MINOR#g" \
     138    mswindows/osgeo4w/grass.tmpl >$OSGEO4W_ROOT_MSYS/bin/grass$MAJOR$MINOR
     139sed -e "s#@VERSION@#$VERSION#g" -e "s#@POSTFIX@#$MAJOR$MINOR#g" -e "s#@OSGEO4W_ROOT@#$OSGEO4W_ROOT#g" \
    138140    mswindows/osgeo4w/grass.bat.tmpl >$OSGEO4W_ROOT_MSYS/bin/grass$MAJOR$MINOR.bat
    139141sed -e "s#@VERSION@#$VERSION#g" -e "s#@OSGEO4W_ROOT_MSYS@#$OSGEO4W_ROOT#g" \
Note: See TracChangeset for help on using the changeset viewer.