Changeset 45576
- Timestamp:
- Mar 5, 2011, 10:21:31 AM (13 years ago)
- Location:
- grass/trunk
- Files:
-
- 1 added
- 2 edited
-
lib/init/grass.py (modified) (38 diffs)
-
mswindows/osgeo4w/grass.bat.tmpl (added)
-
mswindows/osgeo4w/package.sh (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
grass/trunk/lib/init/grass.py
r45387 r45576 4 4 # MODULE: GRASS initialization (Python) 5 5 # AUTHOR(S): Original author unknown - probably CERL 6 # Andreas Lange - Germany - andreas.lange at rhein-main.de7 # Huidae Cho - Korea - grass4u at gmail.com8 # Justin Hickey - Thailand - jhickey at hpcc.nectec.or.th9 # Markus Neteler - Germany/Italy - neteler at itc.it10 # Hamish Bowman - New Zealand - hamish_b at yahoo,com6 # 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> 11 11 # 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 17 16 # interface and cleans up after it is finished. 18 # COPYRIGHT: (C) 2000-201 0by the GRASS Development Team17 # COPYRIGHT: (C) 2000-2011 by the GRASS Development Team 19 18 # 20 19 # This program is free software under the GNU General … … 33 32 34 33 # Variables substituted during build process 35 # Set the GISBASE variable 36 gisbase = "@GISBASE@" 34 if os.environ.has_key('GISBASE'): 35 gisbase = os.environ['GISBASE'] 36 else: 37 gisbase = "@GISBASE@" 37 38 cmd_name = "@START_UP@" 38 39 grass_version = "@GRASS_VERSION_NUMBER@" 39 40 ld_library_path_var = '@LD_LIBRARY_PATH_VAR@' 40 config_projshare = "@CONFIG_PROJSHARE@" 41 if os.environ.has_key('GRASS_PROJSHARE'): 42 config_projshare = os.environ['GRASS_PROJSHARE'] 43 else: 44 config_projshare = "@CONFIG_PROJSHARE@" 41 45 grass_config_dirname = "@GRASS_CONFIG_DIR@" 42 46 43 47 gisbase = os.path.normpath(gisbase) 44 48 45 # ##i18N49 # i18N 46 50 import gettext 47 51 gettext.install('grasslibs', os.path.join(gisbase, 'locale'), unicode=True) … … 68 72 pass 69 73 70 def cleanup_dir( dir):71 if not dir:74 def cleanup_dir(path): 75 if not path: 72 76 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): 75 79 for name in files: 76 try_remove(os.path.join(root, name))80 try_remove(os.path.join(root, name)) 77 81 for name in dirs: 78 try_rmdir(os.path.join(root, name))79 82 try_rmdir(os.path.join(root, name)) 83 80 84 def cleanup(): 81 85 tmpdir, lockfile … … 91 95 sys.stderr.write(msg + "\n") 92 96 sys.stderr.flush() 93 97 94 98 def readfile(path): 95 99 f = open(path, 'r') … … 201 205 except: 202 206 s = None 203 207 204 208 # Copy the global grassrc file to the session grassrc file 205 209 if s: 206 210 writefile(gisrc, s) 207 211 208 212 def read_gisrc(): 209 213 kv = {} … … 238 242 if not grass_gui: 239 243 grass_gui = default_gui 240 244 241 245 if grass_gui == 'gui': 242 246 grass_gui = default_gui … … 277 281 path_prepend(gfile('scripts'), 'PATH') 278 282 path_prepend(gfile('bin'), 'PATH') 279 283 280 284 # Set PYTHONPATH to find GRASS Python modules 281 285 path_prepend(gfile('etc', 'python'), 'PYTHONPATH') 282 286 283 287 # Add .py (Python) to list of executable extensions to search for in MS-Windows PATH 284 288 if windows: 285 289 path_append('.PY', 'PATHEXT') 286 290 287 291 def find_exe(pgm): 288 292 for dir in os.getenv('PATH').split(os.pathsep): … … 304 308 pager = "cat" 305 309 os.environ['GRASS_PAGER'] = pager 306 310 307 311 # GRASS_WISH 308 312 if not os.getenv('GRASS_WISH'): 309 313 os.environ['GRASS_WISH'] = "wish" 310 314 311 315 # GRASS_PYTHON 312 316 if not os.getenv('GRASS_PYTHON'): … … 315 319 else: 316 320 os.environ['GRASS_PYTHON'] = "python" 317 321 318 322 # GRASS_GNUPLOT 319 323 if not os.getenv('GRASS_GNUPLOT'): 320 324 os.environ['GRASS_GNUPLOT'] = "gnuplot -persist" 321 325 322 326 # GRASS_PROJSHARE 323 327 if not os.getenv('GRASS_PROJSHARE'): 324 328 os.environ['GRASS_PROJSHARE'] = config_projshare 325 329 326 330 def set_browser(): 327 331 # GRASS_HTML_BROWSER … … 332 336 browser = gfile('etc', "html_browser_mac.sh") 333 337 os.environ['GRASS_HTML_BROWSER_MACOSX'] = "-b com.apple.helpviewer" 334 338 335 339 if windows or cygwin: 336 340 # MinGW startup moved to into init.bat … … 349 353 os.environ['GRASS_HTML_BROWSER_MACOSX'] = "-b %s" % browser 350 354 browser = gfile('etc', "html_browser_mac.sh") 351 355 352 356 if not browser: 353 357 warning(_("Searched for a web browser, but none found")) … … 368 372 sys.stderr.write(line) 369 373 f.close() 370 374 371 375 sys.stderr.write("\n") 372 376 sys.stderr.write(_("Hit RETURN to continue")) 373 377 sys.stdin.readline() 374 378 375 379 #for convenience, define pwd as GISDBASE: 376 380 s = r"""GISDBASE: %s … … 406 410 sys.stdin.readline() 407 411 grass_gui = 'text' 408 412 409 413 else: 410 414 # Display a message if a graphical interface was expected … … 417 421 sys.stdin.readline() 418 422 grass_gui = 'text' 419 423 420 424 # Save the user interface variable in the grassrc file - choose a temporary 421 425 # file name that should not match another file … … 429 433 # Try non-interactive startup 430 434 l = None 431 435 432 436 if arg == '-': 433 437 if location: … … 435 439 else: 436 440 l = arg 437 441 438 442 if l: 439 443 if l == '.': … … 441 445 elif not os.path.isabs(l): 442 446 l = os.path.abspath(l) 443 447 444 448 l, mapset = os.path.split(l) 445 449 if not mapset: … … 447 451 l, location_name = os.path.split(l) 448 452 gisdbase = l 449 453 450 454 if gisdbase and location_name and mapset: 451 455 location = os.path.join(gisdbase, location_name, mapset) 452 456 453 457 if not os.access(os.path.join(location, "WIND"), os.R_OK): 454 458 if location_name == "PERMANENT": … … 467 471 else: 468 472 fatal(_("<%s> is not a valid GRASS location") % location) 469 473 470 474 if os.access(gisrc, os.R_OK): 471 475 kv = read_gisrc() 472 476 else: 473 477 kv = {} 474 478 475 479 kv['GISDBASE'] = gisdbase 476 480 kv['LOCATION_NAME'] = location_name … … 480 484 fatal(_("GISDBASE, LOCATION_NAME and MAPSET variables not set properly.\n" 481 485 "Interactive startup needed.")) 482 486 483 487 def set_data(): 484 488 # User selects LOCATION and MAPSET if not set … … 494 498 fatal(_("Invalid user interface specified - <%s>.\n" 495 499 "Use the --help option to see valid interface names.") % grass_gui) 496 500 497 501 def gui_startup(): 498 502 if grass_gui == 'wxpython': … … 510 514 "Hit RETURN to continue...")) 511 515 sys.stdin.readline() 512 516 513 517 os.execlp(cmd_name, "-text") 514 518 sys.exit(1) … … 520 524 fatal(_("Invalid return code from GUI startup script.\n" 521 525 "Please advise GRASS developers of this error.")) 522 526 523 527 def load_gisrc(): 524 528 global gisdbase, location_name, mapset, location … … 554 558 else: 555 559 msg = _("Unable to properly access \"%s\"\nPlease notify system personel.") % lockfile 556 560 557 561 if msg: 558 562 if grass_gui == "wxpython": … … 566 570 message(_("Building user fontcap...")) 567 571 call(["g.mkfontcap"]) 568 572 569 573 def check_shell(): 570 574 global sh, shellname … … 590 594 else: 591 595 shellname = "shell" 592 596 593 597 # check for SHELL 594 598 if not os.getenv('SHELL'): 595 599 fatal(_("The SHELL variable is not set")) 596 600 597 601 def check_batch_job(): 598 602 global batch_job … … 616 620 bj.wait() 617 621 message(_("Execution of '%s' finished.") % batch_job) 618 622 619 623 def start_gui(): 620 624 # Start the chosen GUI but ignore text … … 635 639 if not os.getenv('GRASS_BATCH_JOB') and not grass_debug: 636 640 call(["tput", "clear"]) 637 641 638 642 def show_banner(): 639 643 sys.stderr.write(r""" … … 669 673 _("Help is available with the command:"), 670 674 _("See the licence terms with:"))) 671 675 672 676 if grass_gui == 'wxpython': 673 677 message("%-41sg.gui wxpython" % _("If required, restart the GUI with:")) 674 678 else: 675 679 message("%-41sg.gui %s" % (_("Start the GUI with:"), default_gui)) 676 680 677 681 message("%-41sexit" % _("When ready to quit enter:")) 678 682 message("") … … 680 684 def csh_startup(): 681 685 global exit_val 682 686 683 687 userhome = os.getenv('HOME') # save original home 684 688 home = location 685 689 os.environ['HOME'] = home 686 690 687 691 cshrc = os.path.join(home, ".cshrc") 688 692 tcshrc = os.path.join(home, ".tcshrc") 689 693 try_remove(cshrc) 690 694 try_remove(tcshrc) 691 695 692 696 f = open(cshrc, 'w') 693 697 f.write("set home = %s" % userhome) 694 698 f.write("set history = 3000 savehist = 3000 noclobber ignoreeof") 695 699 f.write("set histfile = %s" % os.path.join(os.getenv('HOME'), ".history")) 696 700 697 701 f.write("set prompt = '\\") 698 702 f.write("Mapset <%s> in Location <%s> \\" % (mapset, location_name)) 699 703 f.write("GRASS %s > '" % grass_version) 700 704 f.write("set BOGUS=``;unset BOGUS") 701 705 702 706 path = os.path.join(userhome, ".grass.cshrc") 703 707 if os.access(path, os.R_OK): 704 708 f.write(readfile(path)) 705 709 706 710 mail_re = re.compile(r"^ *set *mail *= *") 707 711 708 712 for filename in [".cshrc", ".tcshrc", ".login"]: 709 713 path = os.path.join(userhome, filename) … … 714 718 if mail_re.match(l): 715 719 f.write(l) 716 720 717 721 path = os.getenv('PATH').split(':') 718 722 f.write("set path = ( %s ) " % ' '.join(path)) 719 723 720 724 f.close() 721 725 writefile(tcshrc, readfile(cshrc)) 722 726 723 727 exit_val = call([gfile("etc", "run"), os.getenv('SHELL')]) 724 728 725 729 os.environ['HOME'] = userhome 726 730 727 731 def bash_startup(): 728 732 global exit_val … … 776 780 os.environ['PS1'] = "GRASS %s (%s):\w > " % (grass_version, location_name) 777 781 exit_val = call([gfile("etc", "run"), os.getenv('SHELL')]) 778 782 779 783 if exit_val != 0: 780 784 fatal(_("Failed to start shell '%s'") % os.getenv('SHELL')) … … 790 794 message(_("Goodbye from GRASS GIS")) 791 795 message("") 792 796 793 797 def clean_temp(): 794 798 message(_("Cleaning up temporary files...")) … … 796 800 call([gfile("etc", "clean_temp")], stdout = nul, stderr = nul) 797 801 nul.close() 798 802 799 803 def get_username(): 800 804 global user … … 817 821 if not user: 818 822 user = "user_%d" % os.getuid() 819 823 820 824 def parse_cmdline(): 821 825 global args, grass_gui, create_new … … 947 951 948 952 # Parsing argument to get LOCATION 949 if args == []:953 if not args: 950 954 # Try interactive startup 951 955 location = None … … 993 997 if grass_gui == "wxpython": 994 998 message(_("Launching '%s' GUI in the background, please wait...") % grass_gui) 995 999 996 1000 if sh in ['csh', 'tcsh']: 997 1001 csh_startup() … … 1015 1019 cleanup() 1016 1020 1017 # ### after this point no more grass modules may be called ####1021 # After this point no more grass modules may be called 1018 1022 1019 1023 done_message() -
grass/trunk/mswindows/osgeo4w/package.sh
r45532 r45576 65 65 export VERSION=$MAJOR.$MINOR.$PATCH 66 66 67 export GRASS_PYTHON= /c/OSGeo4W/apps/Python2568 export PYTHONHOME= /c/OSGeo4W/apps/Python2567 export GRASS_PYTHON="/c/OSGeo4W/bin/python.exe" 68 export PYTHONHOME="/c/OSGeo4W/apps/Python25" 69 69 70 70 if [ -f mswindows/osgeo4w/package.log ]; then … … 135 135 cp mswindows/osgeo4w/config.h.switch $OSGEO4W_ROOT_MSYS/apps/grass/grass-$VERSION/include/grass/config.h 136 136 cp 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" \ 137 sed -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 139 sed -e "s#@VERSION@#$VERSION#g" -e "s#@POSTFIX@#$MAJOR$MINOR#g" -e "s#@OSGEO4W_ROOT@#$OSGEO4W_ROOT#g" \ 138 140 mswindows/osgeo4w/grass.bat.tmpl >$OSGEO4W_ROOT_MSYS/bin/grass$MAJOR$MINOR.bat 139 141 sed -e "s#@VERSION@#$VERSION#g" -e "s#@OSGEO4W_ROOT_MSYS@#$OSGEO4W_ROOT#g" \
Note:
See TracChangeset
for help on using the changeset viewer.
