grass.py 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. #!/usr/bin/env python
  2. #############################################################################
  3. #
  4. # MODULE: GRASS initialization (Python)
  5. # AUTHOR(S): Original author unknown - probably CERL
  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>
  11. # Converted to Python (based on init.sh) by Glynn Clements
  12. # Martin Landa <landa.martin gmail.com>
  13. # Luca Delucchi <lucadeluge@gmail.com>
  14. # PURPOSE: Sets up environment variables, parses any remaining
  15. # command line options for setting the GISDBASE, LOCATION,
  16. # and/or MAPSET. Finally it starts GRASS with the appropriate user
  17. # interface and cleans up after it is finished.
  18. # COPYRIGHT: (C) 2000-2013 by the GRASS Development Team
  19. #
  20. # This program is free software under the GNU General
  21. # Public License (>=v2). Read the file COPYING that
  22. # comes with GRASS for details.
  23. #
  24. #############################################################################
  25. import sys
  26. import os
  27. import atexit
  28. import string
  29. import subprocess
  30. import re
  31. import platform
  32. import tempfile
  33. # Variables substituted during build process
  34. if os.environ.has_key('GISBASE'):
  35. gisbase = os.environ['GISBASE']
  36. else:
  37. gisbase = "@GISBASE@"
  38. cmd_name = "@START_UP@"
  39. grass_version = "@GRASS_VERSION_NUMBER@"
  40. ld_library_path_var = '@LD_LIBRARY_PATH_VAR@'
  41. if os.environ.has_key('GRASS_PROJSHARE'):
  42. config_projshare = os.environ['GRASS_PROJSHARE']
  43. else:
  44. config_projshare = "@CONFIG_PROJSHARE@"
  45. # configuration directory
  46. grass_env_file = None # see check_shell()
  47. if sys.platform == 'win32':
  48. grass_config_dirname = "GRASS7"
  49. grass_config_dir = os.path.join(os.getenv('APPDATA'), grass_config_dirname)
  50. else:
  51. grass_config_dirname = ".grass7"
  52. grass_config_dir = os.path.join(os.getenv('HOME'), grass_config_dirname)
  53. gisbase = os.path.normpath(gisbase)
  54. # i18N
  55. import gettext
  56. gettext.install('grasslibs', os.path.join(gisbase, 'locale'), unicode = True)
  57. tmpdir = None
  58. lockfile = None
  59. remove_lockfile = True
  60. location = None
  61. create_new = None
  62. grass_gui = None
  63. def warning(text):
  64. sys.stderr.write(_("WARNING") + ': ' + text + os.linesep)
  65. def try_remove(path):
  66. try:
  67. os.remove(path)
  68. except:
  69. pass
  70. def try_rmdir(path):
  71. try:
  72. os.rmdir(path)
  73. except:
  74. pass
  75. def clean_env():
  76. env_curr = read_gisrc()
  77. env_new = {}
  78. for k,v in env_curr.iteritems():
  79. if 'MONITOR' not in k:
  80. env_new[k] = v
  81. write_gisrc(env_new)
  82. def cleanup_dir(path):
  83. if not path:
  84. return
  85. for root, dirs, files in os.walk(path, topdown = False):
  86. for name in files:
  87. try_remove(os.path.join(root, name))
  88. for name in dirs:
  89. try_rmdir(os.path.join(root, name))
  90. def cleanup():
  91. tmpdir, lockfile, remove_lockfile
  92. # all exits after setting up tmp dirs (system/location) should
  93. # also tidy it up
  94. cleanup_dir(tmpdir)
  95. try_rmdir(tmpdir)
  96. if location:
  97. tmpdir_loc = os.path.join(location, ".tmp")
  98. cleanup_dir(tmpdir_loc)
  99. try_rmdir(tmpdir_loc)
  100. # remove lock-file if requested
  101. if lockfile and remove_lockfile:
  102. try_remove(lockfile)
  103. def fatal(msg):
  104. sys.exit(msg)
  105. def message(msg):
  106. sys.stderr.write(msg + "\n")
  107. sys.stderr.flush()
  108. def readfile(path):
  109. f = open(path, 'r')
  110. s = f.read()
  111. f.close()
  112. return s
  113. def writefile(path, s):
  114. f = open(path, 'w')
  115. f.write(s)
  116. f.close()
  117. def call(cmd, **kwargs):
  118. if windows:
  119. kwargs['shell'] = True
  120. return subprocess.call(cmd, **kwargs)
  121. def Popen(cmd, **kwargs):
  122. if windows:
  123. kwargs['shell'] = True
  124. return subprocess.Popen(cmd, **kwargs)
  125. def gfile(*args):
  126. return os.path.join(gisbase, *args)
  127. help_text = r"""GRASS GIS %s
  128. Geographic Resources Analysis Support System (GRASS GIS).
  129. %s:
  130. $CMD_NAME [-h | -help | --help] [-v | --version] [-c | -c geofile | -c EPSG:code]
  131. [-text | -gui] [--config param]
  132. [[[<GISDBASE>/]<LOCATION_NAME>/]<MAPSET>]
  133. %s:
  134. -h or -help or --help %s
  135. -v or --version %s
  136. -c %s
  137. -text %s
  138. %s
  139. -gui %s
  140. %s
  141. --config %s
  142. %s
  143. %s:
  144. GISDBASE %s
  145. LOCATION_NAME %s
  146. MAPSET %s
  147. GISDBASE/LOCATION_NAME/MAPSET %s
  148. %s:
  149. GRASS_GUI %s
  150. GRASS_WISH %s
  151. GRASS_HTML_BROWSER %s
  152. GRASS_ADDON_PATH %s
  153. GRASS_ADDON_BASE %s
  154. GRASS_BATCH_JOB %s
  155. GRASS_PYTHON %s
  156. """ % (grass_version,
  157. _("Usage"),
  158. _("Flags"),
  159. _("print this help message"),
  160. _("show version information and exit"),
  161. _("create given database, location or mapset if it doesn't exist"),
  162. _("use text based interface"),
  163. _("and set as default"),
  164. _("use $DEFAULT_GUI graphical user interface"),
  165. _("and set as default"),
  166. _("print GRASS configuration parameters"),
  167. _("options: arch,build,compiler,path,revision"),
  168. _("Parameters"),
  169. _("initial database (path to GIS data)"),
  170. _("initial location"),
  171. _("initial mapset"),
  172. _("fully qualified initial mapset directory"),
  173. _("Environment variables relevant for startup"),
  174. _("select GUI (text, gui)"),
  175. _("set wish shell name to override 'wish'"),
  176. _("set html web browser for help pages"),
  177. _("set additional path(s) to local GRASS modules or user scripts"),
  178. _("set additional GISBASE for locally installed GRASS Addons"),
  179. _("shell script to be processed as batch job"),
  180. _("set python shell name to override 'python'"))
  181. def help_message():
  182. t = string.Template(help_text)
  183. s = t.substitute(CMD_NAME = cmd_name, DEFAULT_GUI = default_gui)
  184. sys.stderr.write(s)
  185. def create_tmp():
  186. global tmpdir
  187. ## use $TMPDIR if it exists, then $TEMP, otherwise /tmp
  188. tmp = os.getenv('TMPDIR')
  189. if not tmp:
  190. tmp = os.getenv('TEMP')
  191. if not tmp:
  192. tmp = tempfile.gettempdir()
  193. if not tmp:
  194. tmp = '/tmp'
  195. tmpdir = os.path.join(tmp, "grass7-%s-%s" % (user, gis_lock))
  196. try:
  197. os.mkdir(tmpdir, 0700)
  198. except:
  199. fatal(_("Unable to create temporary directory <%s>! Exiting.") % tmpdir)
  200. def create_gisrc():
  201. global gisrc, gisrcrc
  202. # Set the session grassrc file
  203. gisrc = os.path.join(tmpdir, "gisrc")
  204. os.environ['GISRC'] = gisrc
  205. # remove invalid GISRC file to avoid disturbing error messages:
  206. try:
  207. s = readfile(gisrcrc)
  208. if "UNKNOWN" in s:
  209. try_remove(gisrcrc)
  210. s = None
  211. except:
  212. s = None
  213. # Copy the global grassrc file to the session grassrc file
  214. if s:
  215. writefile(gisrc, s)
  216. def read_gisrc():
  217. kv = {}
  218. try:
  219. f = open(gisrc, 'r')
  220. except IOError:
  221. return kv
  222. for line in f:
  223. k, v = line.split(':', 1)
  224. kv[k.strip()] = v.strip()
  225. f.close()
  226. return kv
  227. def read_env_file(path):
  228. kv = {}
  229. f = open(path, 'r')
  230. for line in f:
  231. k, v = line.split(':', 1)
  232. kv[k.strip()] = v.strip()
  233. f.close()
  234. return kv
  235. def write_gisrc(kv):
  236. f = open(gisrc, 'w')
  237. for k, v in kv.iteritems():
  238. f.write("%s: %s\n" % (k, v))
  239. f.close()
  240. def read_gui():
  241. global grass_gui
  242. # At this point the GRASS user interface variable has been set from the
  243. # command line, been set from an external environment variable, or is
  244. # not set. So we check if it is not set
  245. if not grass_gui:
  246. # Check for a reference to the GRASS user interface in the grassrc file
  247. if os.access(gisrc, os.R_OK):
  248. kv = read_gisrc()
  249. if 'GRASS_GUI' in os.environ:
  250. grass_gui = os.environ['GRASS_GUI']
  251. elif 'GUI' in kv:
  252. grass_gui = kv['GUI']
  253. elif 'GRASS_GUI' in kv:
  254. # For backward compatibility (GRASS_GUI renamed to GUI)
  255. grass_gui = kv['GRASS_GUI']
  256. else:
  257. # Set the GRASS user interface to the default if needed
  258. grass_gui = default_gui
  259. if not grass_gui:
  260. grass_gui = default_gui
  261. if grass_gui == 'gui':
  262. grass_gui = default_gui
  263. # FIXME oldtcltk, gis.m, d.m no longer exist
  264. if grass_gui in ['d.m', 'gis.m', 'oldtcltk', 'tcltk']:
  265. warning(_("GUI <%s> not supported in this version") % grass_gui)
  266. grass_gui = default_gui
  267. def path_prepend(dir, var):
  268. path = os.getenv(var)
  269. if path:
  270. path = dir + os.pathsep + path
  271. else:
  272. path = dir
  273. os.environ[var] = path
  274. def path_append(dir, var):
  275. path = os.getenv(var)
  276. if path:
  277. path = path + os.pathsep + dir
  278. else:
  279. path = dir
  280. os.environ[var] = path
  281. def set_paths():
  282. # addons (path)
  283. addon_path = os.getenv('GRASS_ADDON_PATH')
  284. if addon_path:
  285. for path in addon_path.split(os.pathsep):
  286. path_prepend(addon_path, 'PATH')
  287. # addons (base)
  288. addon_base = os.getenv('GRASS_ADDON_BASE')
  289. if not addon_base:
  290. addon_base = os.path.join(grass_config_dir, 'addons')
  291. os.environ['GRASS_ADDON_BASE'] = addon_base
  292. path_prepend(os.path.join(addon_base, 'scripts'), 'PATH')
  293. path_prepend(os.path.join(addon_base, 'bin'), 'PATH')
  294. # standard installation
  295. path_prepend(gfile('scripts'), 'PATH')
  296. path_prepend(gfile('bin'), 'PATH')
  297. # Set PYTHONPATH to find GRASS Python modules
  298. path_prepend(gfile('etc', 'python'), 'PYTHONPATH')
  299. # set path for the GRASS man pages
  300. grass_man_path = os.path.join(gisbase, 'docs', 'man')
  301. addons_man_path = os.path.join(addon_base, 'docs', 'man')
  302. man_path = os.getenv('MANPATH')
  303. if man_path:
  304. path_prepend(addons_man_path, 'MANPATH')
  305. path_prepend(grass_man_path, 'MANPATH')
  306. else:
  307. try:
  308. nul = open(os.devnull, 'w')
  309. p = Popen(['manpath'], stdout = subprocess.PIPE, stderr = nul)
  310. nul.close()
  311. s = p.stdout.read()
  312. p.wait()
  313. sys_man_path = s.strip()
  314. except:
  315. pass
  316. if sys_man_path:
  317. os.environ['MANPATH'] = sys_man_path
  318. path_prepend(addons_man_path, 'MANPATH')
  319. path_prepend(grass_man_path, 'MANPATH')
  320. else:
  321. os.environ['MANPATH'] = addons_man_path
  322. path_prepend(grass_man_path, 'MANPATH')
  323. # Add .py (Python) to list of executable extensions to search for
  324. # in MS-Windows PATH
  325. if windows:
  326. path_append('.PY', 'PATHEXT')
  327. def find_exe(pgm):
  328. for dir in os.getenv('PATH').split(os.pathsep):
  329. path = os.path.join(dir, pgm)
  330. if os.access(path, os.X_OK):
  331. return path
  332. return None
  333. def set_defaults():
  334. # GRASS_PAGER
  335. if not os.getenv('GRASS_PAGER'):
  336. if find_exe("more"):
  337. pager = "more"
  338. elif find_exe("less"):
  339. pager = "less"
  340. elif windows:
  341. pager = "more"
  342. else:
  343. pager = "cat"
  344. os.environ['GRASS_PAGER'] = pager
  345. # GRASS_WISH
  346. if not os.getenv('GRASS_WISH'):
  347. os.environ['GRASS_WISH'] = "wish"
  348. # GRASS_PYTHON
  349. if not os.getenv('GRASS_PYTHON'):
  350. if windows:
  351. os.environ['GRASS_PYTHON'] = "python.exe"
  352. else:
  353. os.environ['GRASS_PYTHON'] = "python"
  354. # GRASS_GNUPLOT
  355. if not os.getenv('GRASS_GNUPLOT'):
  356. os.environ['GRASS_GNUPLOT'] = "gnuplot -persist"
  357. # GRASS_PROJSHARE
  358. if not os.getenv('GRASS_PROJSHARE'):
  359. os.environ['GRASS_PROJSHARE'] = config_projshare
  360. def set_browser():
  361. # GRASS_HTML_BROWSER
  362. browser = os.getenv('GRASS_HTML_BROWSER')
  363. if not browser:
  364. if macosx:
  365. # OSX doesn't execute browsers from the shell PATH - route thru a script
  366. browser = gfile('etc', "html_browser_mac.sh")
  367. os.environ['GRASS_HTML_BROWSER_MACOSX'] = "-b com.apple.helpviewer"
  368. if windows or cygwin:
  369. # MinGW startup moved to into init.bat
  370. browser = "explorer"
  371. else:
  372. # the usual suspects
  373. browsers = [ "xdg-open", "htmlview", "konqueror", "mozilla", "mozilla-firefox",
  374. "firefox", "iceweasel", "opera", "netscape", "dillo", "lynx", "links", "w3c" ]
  375. for b in browsers:
  376. if find_exe(b):
  377. browser = b
  378. break
  379. elif macosx:
  380. # OSX doesn't execute browsers from the shell PATH - route thru a script
  381. os.environ['GRASS_HTML_BROWSER_MACOSX'] = "-b %s" % browser
  382. browser = gfile('etc', "html_browser_mac.sh")
  383. if not browser:
  384. warning(_("Searched for a web browser, but none found"))
  385. # even so we set konqueror to make lib/gis/parser.c happy:
  386. browser = "konqueror"
  387. os.environ['GRASS_HTML_BROWSER'] = browser
  388. def grass_intro():
  389. intro = r"""
  390. WELCOME TO GRASS %s
  391. 1) Have at your side all available GRASS tutorials
  392. 2) When working on your location, the following materials
  393. are extremely useful:
  394. - A topo map of your area
  395. - Current catalog of available computer maps
  396. 3) Check the GRASS webpages for feedback mailinglists and more:
  397. http://grass.osgeo.org
  398. http://www.grass-gis.org
  399. """ % grass_version
  400. sys.stderr.write(intro)
  401. sys.stderr.write("\n")
  402. sys.stderr.write(_("Hit RETURN to continue"))
  403. sys.stdin.readline()
  404. # for convenience, define pwd as GISDBASE:
  405. s = r"""GISDBASE: %s
  406. LOCATION_NAME: <UNKNOWN>
  407. MAPSET: <UNKNOWN>
  408. """ % os.getcwd()
  409. writefile(gisrc, s)
  410. def check_gui():
  411. global grass_gui, wxpython_base
  412. # Check if we are running X windows by checking the DISPLAY variable
  413. if os.getenv('DISPLAY') or windows:
  414. # Check if python is working properly
  415. if grass_gui == 'wxpython':
  416. nul = open(os.devnull, 'w')
  417. p = Popen([os.environ['GRASS_PYTHON']],
  418. stdin = subprocess.PIPE,
  419. stdout = nul, stderr = nul)
  420. nul.close()
  421. p.stdin.write("variable=True")
  422. p.stdin.close()
  423. p.wait()
  424. if p.returncode == 0:
  425. # Set the wxpython base directory
  426. wxpython_base = gfile("etc", "gui", "wxpython")
  427. else:
  428. # Python was not found - switch to text interface mode
  429. warning(_("The python command does not work as expected!\n"
  430. "Please check your GRASS_PYTHON environment variable.\n"
  431. "Use the -help option for details.\n"
  432. "Switching to text based interface mode.\n\n"
  433. "Hit RETURN to continue.\n"))
  434. sys.stdin.readline()
  435. grass_gui = 'text'
  436. else:
  437. # Display a message if a graphical interface was expected
  438. if grass_gui != 'text':
  439. # Set the interface mode to text
  440. warning(_("It appears that the X Windows system is not active.\n"
  441. "A graphical based user interface is not supported.\n"
  442. "Switching to text based interface mode.\n\n"
  443. "Hit RETURN to continue"""))
  444. sys.stdin.readline()
  445. grass_gui = 'text'
  446. # Save the user interface variable in the grassrc file - choose a temporary
  447. # file name that should not match another file
  448. if os.access(gisrc, os.F_OK):
  449. kv = read_gisrc()
  450. kv['GUI'] = grass_gui
  451. write_gisrc(kv)
  452. def non_interactive(arg, geofile = None):
  453. global gisdbase, location_name, mapset, location
  454. # Try non-interactive startup
  455. l = None
  456. if arg == '-':
  457. if location:
  458. l = location
  459. else:
  460. l = arg
  461. if l:
  462. if l == '.':
  463. l = os.getcwd()
  464. elif not os.path.isabs(l):
  465. l = os.path.abspath(l)
  466. l, mapset = os.path.split(l)
  467. if not mapset:
  468. l, mapset = os.path.split(l)
  469. l, location_name = os.path.split(l)
  470. gisdbase = l
  471. if gisdbase and location_name and mapset:
  472. location = os.path.join(gisdbase, location_name, mapset)
  473. if not os.access(os.path.join(location, "WIND"), os.R_OK):
  474. if location_name == "PERMANENT":
  475. fatal(_("<%s> is not a valid GRASS location") % location)
  476. else:
  477. # the user wants to create mapset on the fly
  478. if create_new:
  479. if not os.access(os.path.join(os.path.join(gisdbase, location_name,
  480. "PERMANENT", "DEFAULT_WIND")), os.F_OK):
  481. # create new location
  482. gisdbase = os.path.join(gisdbase, location_name)
  483. location_name = mapset
  484. mapset = "PERMANENT"
  485. if os.access(os.path.join(os.path.join(gisdbase, location_name,
  486. "PERMANENT", "DEFAULT_WIND")), os.F_OK):
  487. fatal(_("Failed to create new location. The location <%s> already exists." % location_name))
  488. sys.path.append(gfile('etc', 'python'))
  489. from grass.script import core as grass
  490. try:
  491. if geofile and geofile.find('EPSG:') > -1:
  492. epsg = geofile.split(':', 1)[1]
  493. grass.create_location(gisdbase, location_name, epsg = epsg)
  494. else:
  495. grass.create_location(gisdbase, location_name, filename = geofile)
  496. except grass.ScriptError, e:
  497. fatal(e.value.strip('"').strip("'").replace('\\n', os.linesep))
  498. else:
  499. # create new mapset
  500. os.mkdir(location)
  501. # copy PERMANENT/DEFAULT_WIND to <mapset>/WIND
  502. s = readfile(os.path.join(gisdbase, location_name, "PERMANENT", "DEFAULT_WIND"))
  503. writefile(os.path.join(location, "WIND"), s)
  504. message(_("Missing WIND file fixed"))
  505. else:
  506. fatal(_("<%s> is not a valid GRASS location") % location)
  507. if os.access(gisrc, os.R_OK):
  508. kv = read_gisrc()
  509. else:
  510. kv = {}
  511. kv['GISDBASE'] = gisdbase
  512. kv['LOCATION_NAME'] = location_name
  513. kv['MAPSET'] = mapset
  514. write_gisrc(kv)
  515. else:
  516. fatal(_("GISDBASE, LOCATION_NAME and MAPSET variables not set properly.\n"
  517. "Interactive startup needed."))
  518. def set_data():
  519. # User selects LOCATION and MAPSET if not set
  520. if not location:
  521. # Check for text interface
  522. if grass_gui == 'text':
  523. pass
  524. # Check for GUI
  525. elif grass_gui == 'wxpython':
  526. gui_startup()
  527. else:
  528. # Shouldn't need this but you never know
  529. fatal(_("Invalid user interface specified - <%s>.\n"
  530. "Use the --help option to see valid interface names.") % grass_gui)
  531. def gui_startup():
  532. if grass_gui == 'wxpython':
  533. thetest = call([os.getenv('GRASS_PYTHON'),
  534. gfile(wxpython_base, "gis_set.py")])
  535. if thetest == 0:
  536. pass
  537. elif thetest == 1:
  538. # The startup script printed an error message so wait
  539. # for user to read it
  540. message(_("Error in GUI startup. If necessary, please "
  541. "report this error to the GRASS developers.\n"
  542. "Switching to text mode now.\n\n"
  543. "Hit RETURN to continue..."))
  544. sys.stdin.readline()
  545. os.execlp(cmd_name, "-text")
  546. sys.exit(1)
  547. elif thetest == 2:
  548. # User wants to exit from GRASS
  549. message(_("Received EXIT message from GUI.\nGRASS is not started. Bye."))
  550. sys.exit(0)
  551. else:
  552. fatal(_("Invalid return code from GUI startup script.\n"
  553. "Please advise GRASS developers of this error."))
  554. def load_gisrc():
  555. global gisdbase, location_name, mapset, location
  556. kv = read_gisrc()
  557. gisdbase = kv.get('GISDBASE')
  558. location_name = kv.get('LOCATION_NAME')
  559. mapset = kv.get('MAPSET')
  560. if not gisdbase or not location_name or not mapset:
  561. fatal(_("Error reading data path information from g.gisenv.\n"
  562. "GISDBASE=%(gisbase)s\n"
  563. "LOCATION_NAME=%(location)s\n"
  564. "MAPSET=%(mapset)s\n\n"
  565. "Check the <%s(file)> file." % \
  566. { 'gisbase' : gisdbase, 'location' : location_name,
  567. 'mapset' : mapset, 'file' : gisrcrc }))
  568. location = os.path.join(gisdbase, location_name, mapset)
  569. # load environmental variables from grass_env_file
  570. def load_env():
  571. if not os.access(grass_env_file, os.R_OK):
  572. return
  573. for line in readfile(grass_env_file).split(os.linesep):
  574. try:
  575. k, v = map(lambda x: x.strip(), line.strip().split(' ', 1)[1].split('=', 1))
  576. except:
  577. continue
  578. os.environ[k] = v
  579. def set_language():
  580. import locale
  581. language = os.getenv('LANG')
  582. if not language:
  583. return
  584. language = language.split('.')[0] # Split off ignored .encoding part if present
  585. orig_language = language
  586. try:
  587. locale.setlocale(locale.LC_ALL, language)
  588. except locale.Error, e:
  589. if sys.platform != 'win32': # Don't try on Windows, it will probably not work
  590. # sys.stderr.write("Failed to set LC_ALL to %s (%s)\n" % (language, e))
  591. try:
  592. # Locale lang.encoding might be missing. Let's try
  593. # UTF-8 encoding before giving up as on Linux systems
  594. # lang.UTF-8 locales are more common than legacy
  595. # ISO-8859 ones.
  596. language = locale.normalize('%s.UTF-8' % (language))
  597. locale.setlocale(locale.LC_ALL, language)
  598. except locale.Error, e:
  599. # If we got so far, provided locale is not supported
  600. # on this system
  601. sys.stderr.write("Failed to set LC_ALL to %s (%s)\n" % (language, e))
  602. ### locale.getdefaultlocale() is probably related to gettext?
  603. # try:
  604. # default_locale = locale.getdefaultlocale()
  605. # except:
  606. # default_locale = None
  607. # if default_locale and default_locale[0]:
  608. # language = default_locale[0]
  609. # else:
  610. language = 'C'
  611. # Set up environment for subprocesses
  612. for lc in ('LC_CTYPE', 'LC_MESSAGES', 'LC_TIME', 'LC_COLLATE', 'LC_MONETARY', 'LC_PAPER',
  613. 'LC_NAME', 'LC_ADDRESS', 'LC_TELEPHONE', 'LC_MEASUREMENT', 'LC_IDENTIFICATION'):
  614. os.environ[lc] = language
  615. # Some code in GRASS might not like other decimal separators than .
  616. # Other potential sources for problems are: LC_TIME LC_CTYPE
  617. locale.setlocale(locale.LC_NUMERIC, 'C')
  618. os.environ['LC_NUMERIC'] = 'C'
  619. if os.getenv('LC_ALL'):
  620. del os.environ['LC_ALL'] # Remove LC_ALL to not override LC_NUMERIC
  621. # Even if setting locale has failed, let's set LANG in a hope,
  622. # that UI will use it GRASS texts will be in selected language,
  623. # system messages (i.e. OK, Cancel etc.) - in system default
  624. # language
  625. os.environ['LANGUAGE'] = orig_language
  626. os.environ['LANG'] = orig_language
  627. # Calling gettext.install twice seems to allow to see also
  628. # localized startup messages Black magic ;)
  629. gettext.install('grasslibs', os.path.join(gisbase, 'locale'), unicode = True)
  630. def check_lock():
  631. global lockfile
  632. if not os.path.exists(location):
  633. fatal(_("Path '%s' doesn't exist") % location)
  634. # Check for concurrent use
  635. lockfile = os.path.join(location, ".gislock")
  636. ret = call([gfile("etc", "lock"),
  637. lockfile,
  638. "%d" % os.getpid()])
  639. if ret == 0:
  640. msg = None
  641. elif ret == 2:
  642. msg = _("%(user)s is currently running GRASS in selected mapset (file %(file)s found). "
  643. "Concurrent use not allowed." % \
  644. { 'user' : user, 'file' : lockfile })
  645. else:
  646. msg = _("Unable to properly access '%s'.\n"
  647. "Please notify system personel.") % lockfile
  648. if msg:
  649. if grass_gui == "wxpython":
  650. thetest = call([os.getenv('GRASS_PYTHON'), os.path.join(wxpython_base, "gis_set_error.py"), msg])
  651. else:
  652. global remove_lockfile
  653. remove_lockfile = False
  654. fatal(msg)
  655. def make_fontcap():
  656. fc = os.getenv('GRASS_FONT_CAP')
  657. if fc and not os.access(fc, os.R_OK):
  658. message(_("Building user fontcap..."))
  659. call(["g.mkfontcap"])
  660. def check_shell():
  661. global sh, shellname, grass_env_file
  662. # cygwin has many problems with the shell setup
  663. # below, so i hardcoded everything here.
  664. if os.getenv('CYGWIN'):
  665. sh = "cygwin"
  666. shellname = "GNU Bash (Cygwin)"
  667. os.environ['SHELL'] = "/usr/bin/bash.exe"
  668. os.environ['OSTYPE'] = "cygwin"
  669. else:
  670. sh = os.path.basename(os.getenv('SHELL'))
  671. if windows and sh:
  672. sh = os.path.splitext(sh)[0]
  673. if sh == "ksh":
  674. shellname = "Korn Shell"
  675. elif sh == "csh":
  676. shellname = "C Shell"
  677. elif sh == "tcsh":
  678. shellname = "TC Shell"
  679. elif sh == "bash":
  680. shellname = "Bash Shell"
  681. elif sh == "sh":
  682. shellname = "Bourne Shell"
  683. elif sh == "zsh":
  684. shellname = "Z Shell"
  685. elif sh == "cmd":
  686. shellname = "Command Shell"
  687. else:
  688. shellname = "shell"
  689. if sh in ['csh', 'tcsh']:
  690. grass_env_file = os.path.join(grass_config_dir, 'cshrc')
  691. elif sh in ['bash', 'msh', 'cygwin', 'sh']:
  692. grass_env_file = os.path.join(grass_config_dir, 'bashrc')
  693. elif sh == 'zsh':
  694. grass_env_file = os.path.join(grass_config_dir, 'zshrc')
  695. elif sh == 'cmd':
  696. grass_env_file = os.path.join(grass_config_dir, 'env.bat')
  697. else:
  698. grass_env_file = os.path.join(grass_config_dir, 'bashrc')
  699. warning(_("Unsupported shell <%s>: %s") % (sh, grass_env_file))
  700. # check for SHELL
  701. if not os.getenv('SHELL'):
  702. fatal(_("The SHELL variable is not set"))
  703. def check_batch_job():
  704. global batch_job
  705. # hack to process batch jobs:
  706. batch_job = os.getenv('GRASS_BATCH_JOB')
  707. if batch_job:
  708. # defined, but ...
  709. if not os.access(batch_job, os.F_OK):
  710. # wrong file
  711. fatal(_("Job file '%s' has been defined in "
  712. "the 'GRASS_BATCH_JOB' variable but not found. Exiting.\n\n"
  713. "Use 'unset GRASS_BATCH_JOB' to disable batch job processing.") % batch_job)
  714. elif not os.access(batch_job, os.X_OK):
  715. # right file, but ...
  716. fatal(_("Change file permission to 'executable' for '%s'") % batch_job)
  717. else:
  718. message(_("Executing '%s' ...") % batch_job)
  719. grass_gui = "text"
  720. shell = batch_job
  721. bj = Popen(shell, shell=True)
  722. bj.wait()
  723. message(_("Execution of '%s' finished.") % batch_job)
  724. def start_gui():
  725. # Start the chosen GUI but ignore text
  726. if grass_debug:
  727. message(_("GRASS GUI should be <%s>") % grass_gui)
  728. # Check for gui interface
  729. if grass_gui == "wxpython":
  730. Popen([os.getenv('GRASS_PYTHON'),
  731. gfile(wxpython_base, "wxgui.py")])
  732. def clear_screen():
  733. if windows:
  734. pass
  735. # TODO: uncomment when PDCurses works.
  736. # cls
  737. else:
  738. if not os.getenv('GRASS_BATCH_JOB') and not grass_debug:
  739. call(["tput", "clear"])
  740. def show_banner():
  741. sys.stderr.write(r"""
  742. __________ ___ __________ _______________
  743. / ____/ __ \/ | / ___/ ___/ / ____/ _/ ___/
  744. / / __/ /_/ / /| | \__ \\_ \ / / __ / / \__ \
  745. / /_/ / _, _/ ___ |___/ /__/ / / /_/ // / ___/ /
  746. \____/_/ |_/_/ |_/____/____/ \____/___//____/
  747. """)
  748. def say_hello():
  749. sys.stderr.write(_("Welcome to GRASS %s") % grass_version)
  750. def show_info():
  751. sys.stderr.write(
  752. r"""
  753. %-41shttp://grass.osgeo.org
  754. %-41s%s (%s)
  755. %-41sg.manual -i
  756. %-41sg.version -c
  757. """ % (_("GRASS homepage:"),
  758. _("This version running through:"),
  759. shellname, os.getenv('SHELL'),
  760. _("Help is available with the command:"),
  761. _("See the licence terms with:")))
  762. if grass_gui == 'wxpython':
  763. message("%-41sg.gui wxpython" % _("If required, restart the GUI with:"))
  764. else:
  765. message("%-41sg.gui %s" % (_("Start the GUI with:"), default_gui))
  766. message("%-41sexit" % _("When ready to quit enter:"))
  767. message("")
  768. def csh_startup():
  769. global exit_val
  770. userhome = os.getenv('HOME') # save original home
  771. home = location
  772. os.environ['HOME'] = home
  773. cshrc = os.path.join(home, ".cshrc")
  774. tcshrc = os.path.join(home, ".tcshrc")
  775. try_remove(cshrc)
  776. try_remove(tcshrc)
  777. f = open(cshrc, 'w')
  778. f.write("set home = %s\n" % userhome)
  779. f.write("set history = 3000 savehist = 3000 noclobber ignoreeof\n")
  780. f.write("set histfile = %s\n" % os.path.join(os.getenv('HOME'), ".history"))
  781. f.write("set prompt = '\\\n")
  782. f.write("Mapset <%s> in Location <%s> \\\n" % (mapset, location_name))
  783. f.write("GRASS %s > '\n" % grass_version)
  784. f.write("set BOGUS=``;unset BOGUS\n")
  785. path = os.path.join(userhome, ".grass.cshrc") # left for backward compatibility
  786. if os.access(path, os.R_OK):
  787. f.write(readfile(path) + '\n')
  788. if os.access(grass_env_file, os.R_OK):
  789. f.write(readfile(grass_env_file) + '\n')
  790. mail_re = re.compile(r"^ *set *mail *= *")
  791. for filename in [".cshrc", ".tcshrc", ".login"]:
  792. path = os.path.join(userhome, filename)
  793. if os.access(path, os.R_OK):
  794. s = readfile(path)
  795. lines = s.splitlines()
  796. for l in lines:
  797. if mail_re.match(l):
  798. f.write(l)
  799. path = os.getenv('PATH').split(':')
  800. f.write("set path = ( %s ) \n" % ' '.join(path))
  801. f.close()
  802. writefile(tcshrc, readfile(cshrc))
  803. exit_val = call([gfile("etc", "run"), os.getenv('SHELL')])
  804. os.environ['HOME'] = userhome
  805. def bash_startup():
  806. global exit_val
  807. # save command history in mapset dir and remember more
  808. os.environ['HISTFILE'] = os.path.join(location, ".bash_history")
  809. if not os.getenv('HISTSIZE') and not os.getenv('HISTFILESIZE'):
  810. os.environ['HISTSIZE'] = "3000"
  811. # instead of changing $HOME, start bash with: --rcfile "$LOCATION/.bashrc" ?
  812. # if so, must care be taken to explicity call .grass.bashrc et al for
  813. # non-interactive bash batch jobs?
  814. userhome = os.getenv('HOME') # save original home
  815. home = location # save .bashrc in $LOCATION
  816. os.environ['HOME'] = home
  817. bashrc = os.path.join(home, ".bashrc")
  818. try_remove(bashrc)
  819. f = open(bashrc, 'w')
  820. f.write("test -r ~/.alias && . ~/.alias\n")
  821. f.write("PS1='GRASS %s (%s):\w > '\n" % (grass_version, location_name))
  822. f.write("PROMPT_COMMAND=\"'%s'\"\n" % os.path.join(gisbase, 'etc', 'prompt.py'))
  823. # read environmental variables
  824. path = os.path.join(userhome, ".grass.bashrc") # left for backward compatibility
  825. if os.access(path, os.R_OK):
  826. f.write(readfile(path) + '\n')
  827. if os.access(grass_env_file, os.R_OK):
  828. f.write(readfile(grass_env_file) + '\n')
  829. f.write("export PATH=\"%s\"\n" % os.getenv('PATH'))
  830. f.write("export HOME=\"%s\"\n" % userhome) # restore user home path
  831. f.close()
  832. exit_val = call([gfile("etc", "run"), os.getenv('SHELL')])
  833. os.environ['HOME'] = userhome
  834. def default_startup():
  835. global exit_val
  836. if windows:
  837. os.environ['PS1'] = "GRASS %s> " % (grass_version)
  838. # "$ETC/run" doesn't work at all???
  839. exit_val = subprocess.call([os.getenv('SHELL')])
  840. cleanup_dir(os.path.join(location, ".tmp")) # remove GUI session files from .tmp
  841. else:
  842. os.environ['PS1'] = "GRASS %s (%s):\w > " % (grass_version, location_name)
  843. exit_val = call([gfile("etc", "run"), os.getenv('SHELL')])
  844. if exit_val != 0:
  845. fatal(_("Failed to start shell '%s'") % os.getenv('SHELL'))
  846. def done_message():
  847. if batch_job and os.access(batch_job, os.X_OK):
  848. message(_("Batch job '%s' (defined in GRASS_BATCH_JOB variable) was executed.") % batch_job)
  849. message(_("Goodbye from GRASS GIS"))
  850. sys.exit(exit_val)
  851. else:
  852. message(_("Done."))
  853. message("")
  854. message(_("Goodbye from GRASS GIS"))
  855. message("")
  856. def clean_temp():
  857. message(_("Cleaning up temporary files..."))
  858. nul = open(os.devnull, 'w')
  859. call([gfile("etc", "clean_temp")], stdout = nul, stderr = nul)
  860. nul.close()
  861. def grep(string,list):
  862. expr = re.compile(string)
  863. return [elem for elem in list if expr.match(elem)]
  864. def print_params():
  865. plat = gfile(gisbase, 'include', 'Make', 'Platform.make')
  866. fileplat = open(plat)
  867. linesplat = fileplat.readlines()
  868. fileplat.close()
  869. params = sys.argv[2:]
  870. if not params:
  871. params = ['arch', 'build', 'compiler', 'path', 'revision']
  872. for arg in params:
  873. if arg == 'path':
  874. sys.stdout.write("%s\n" % gisbase)
  875. elif arg == 'arch':
  876. val = grep('ARCH',linesplat)
  877. sys.stdout.write("%s\n" % val[0].split('=')[1].strip())
  878. elif arg == 'build':
  879. build = os.path.join(gisbase,'include','grass','confparms.h')
  880. filebuild = open(build)
  881. val = filebuild.readline()
  882. filebuild.close()
  883. sys.stdout.write("%s\n" % val.strip().strip('"').strip())
  884. elif arg == 'compiler':
  885. val = grep('CC',linesplat)
  886. sys.stdout.write("%s\n" % val[0].split('=')[1].strip())
  887. elif arg == 'revision':
  888. rev = os.path.join(gisbase,'include','grass','gis.h')
  889. filerev = open(rev)
  890. linesrev = filerev.readlines()
  891. val = grep('#define GIS_H_VERSION', linesrev)
  892. filerev.close()
  893. sys.stdout.write("%s\n" % val[0].split(':')[1].rstrip('$"\n').strip())
  894. else:
  895. message(_("Parameter <%s> not supported") % arg)
  896. def get_username():
  897. global user
  898. if windows:
  899. user = os.getenv('USERNAME')
  900. if not user:
  901. user = "user_name"
  902. else:
  903. user = os.getenv('USER')
  904. if not user:
  905. user = os.getenv('LOGNAME')
  906. if not user:
  907. try:
  908. p = Popen(['whoami'], stdout = subprocess.PIPE)
  909. s = p.stdout.read()
  910. p.wait()
  911. user = s.strip()
  912. except:
  913. pass
  914. if not user:
  915. user = "user_%d" % os.getuid()
  916. def parse_cmdline():
  917. global args, grass_gui, create_new
  918. args = []
  919. for i in sys.argv[1:]:
  920. # Check if the user asked for the version
  921. if i in ["-v", "--version"]:
  922. message('\n' + readfile(gfile("etc", "license")))
  923. sys.exit()
  924. # Check if the user asked for help
  925. elif i in ["help", "-h", "-help", "--help"]:
  926. help_message()
  927. sys.exit()
  928. # Check if the -text flag was given
  929. elif i in ["-text", "--text"]:
  930. grass_gui = 'text'
  931. # Check if the -gui flag was given
  932. elif i in ["-gui", "--gui"]:
  933. grass_gui = default_gui
  934. # Check if the -wxpython flag was given
  935. elif i in ["-wxpython", "-wx", "--wxpython", "--wx"]:
  936. grass_gui = 'wxpython'
  937. # Check if the user wants to create a new mapset
  938. elif i == "-c":
  939. create_new = True
  940. elif i == "--config":
  941. print_params()
  942. sys.exit()
  943. else:
  944. args.append(i)
  945. ### MAIN script starts here
  946. # Get the system name
  947. windows = sys.platform == 'win32'
  948. cygwin = "cygwin" in sys.platform
  949. macosx = "darwin" in sys.platform
  950. # Set GISBASE
  951. os.environ['GISBASE'] = gisbase
  952. # set HOME
  953. if windows and not os.getenv('HOME'):
  954. os.environ['HOME'] = os.path.join(os.getenv('HOMEDRIVE'), os.getenv('HOMEPATH'))
  955. # set SHELL
  956. if windows:
  957. if os.getenv('GRASS_SH'):
  958. os.environ['SHELL'] = os.getenv('GRASS_SH')
  959. if not os.getenv('SHELL'):
  960. os.environ['SHELL'] = os.getenv('COMSPEC', 'cmd.exe')
  961. atexit.register(cleanup)
  962. # Set default GUI
  963. default_gui = "wxpython"
  964. # the following is only meant to be an internal variable for debugging this script.
  965. # use 'g.gisenv set="DEBUG=[0-5]"' to turn GRASS debug mode on properly.
  966. grass_debug = os.getenv('GRASS_DEBUG')
  967. # Set GRASS version number for R interface etc (must be an env_var for MS-Windows)
  968. os.environ['GRASS_VERSION'] = grass_version
  969. # Set the GIS_LOCK variable to current process id
  970. gis_lock = str(os.getpid())
  971. os.environ['GIS_LOCK'] = gis_lock
  972. # Set the global grassrc file
  973. batch_job = os.getenv('GRASS_BATCH_JOB')
  974. if batch_job:
  975. gisrcrc = os.path.join(grass_config_dir, "rc.%s" % platform.node())
  976. if not os.access(gisrcrc, os.R_OK):
  977. gisrcrc = os.path.join(grass_config_dir, "rc")
  978. else:
  979. gisrcrc = os.path.join(grass_config_dir, "rc")
  980. # Set the username and working directory
  981. get_username()
  982. # Parse the command-line options
  983. parse_cmdline()
  984. # Create the temporary directory and session grassrc file
  985. create_tmp()
  986. # Create the session grassrc file
  987. create_gisrc()
  988. # Set shell (needs to be called before load_env())
  989. check_shell()
  990. # Load environmental variables from the file
  991. load_env()
  992. # Ensure GUI is set
  993. read_gui()
  994. # Set PATH, PYTHONPATH
  995. set_paths()
  996. # Set LD_LIBRARY_PATH (etc) to find GRASS shared libraries
  997. path_prepend(gfile("lib"), ld_library_path_var)
  998. # Set GRASS_PAGER, GRASS_WISH, GRASS_PYTHON, GRASS_GNUPLOT, GRASS_PROJSHARE
  999. set_defaults()
  1000. # Set GRASS_HTML_BROWSER
  1001. set_browser()
  1002. #predefine monitor size for certain architectures
  1003. if os.getenv('HOSTTYPE') == 'arm':
  1004. # small monitor on ARM (iPAQ, zaurus... etc)
  1005. os.environ['GRASS_HEIGHT'] = "320"
  1006. os.environ['GRASS_WIDTH'] = "240"
  1007. # First time user - GISRC is defined in the GRASS script
  1008. if not os.access(gisrc, os.F_OK):
  1009. if grass_gui == 'text' and len(args) == 0:
  1010. fatal(_("Unable to start GRASS. You can:\n"
  1011. " - Launch GRASS with '-gui' switch (`grass70 -gui`)\n"
  1012. " - Create manually GISRC file (%s)\n"
  1013. " - Launch GRASS with path to "
  1014. "the location/mapset as an argument (`grass70 /path/to/location/mapset`)") % gisrcrc)
  1015. grass_intro()
  1016. else:
  1017. clean_temp()
  1018. message(_("Starting GRASS GIS..."))
  1019. # Check that the GUI works
  1020. check_gui()
  1021. # Parsing argument to get LOCATION
  1022. if not args:
  1023. # Try interactive startup
  1024. location = None
  1025. else:
  1026. if create_new:
  1027. if len(args) > 1:
  1028. non_interactive(args[1], args[0])
  1029. else:
  1030. non_interactive(args[0])
  1031. else:
  1032. non_interactive(args[0])
  1033. # Set language
  1034. set_language()
  1035. # User selects LOCATION and MAPSET if not set
  1036. set_data()
  1037. # Set GISDBASE, LOCATION_NAME, MAPSET, LOCATION from $GISRC
  1038. load_gisrc()
  1039. # Check .gislock file
  1040. check_lock()
  1041. # build user fontcap if specified but not present
  1042. make_fontcap()
  1043. # predefine default driver if DB connection not defined
  1044. # is this really needed?? Modules should call this when/if required.
  1045. if not os.access(os.path.join(location, "VAR"), os.F_OK):
  1046. call(['db.connect', '-c', '--quiet'])
  1047. check_batch_job()
  1048. if not batch_job:
  1049. start_gui()
  1050. clear_screen()
  1051. # Display the version and license info
  1052. if batch_job:
  1053. say_hello()
  1054. grass_gui = 'text'
  1055. clear_screen()
  1056. clean_temp()
  1057. try_remove(lockfile)
  1058. sys.exit(0)
  1059. else:
  1060. show_banner()
  1061. say_hello()
  1062. show_info()
  1063. if grass_gui == "wxpython":
  1064. message(_("Launching <%s> GUI in the background, please wait...") % grass_gui)
  1065. if sh in ['csh', 'tcsh']:
  1066. csh_startup()
  1067. elif sh in ['bash', 'msh', 'cygwin']:
  1068. bash_startup()
  1069. else:
  1070. default_startup()
  1071. clear_screen()
  1072. clean_env()
  1073. clean_temp()
  1074. try_remove(lockfile)
  1075. # Save GISRC
  1076. s = readfile(gisrc)
  1077. if not os.path.exists(grass_config_dir):
  1078. os.mkdir(grass_config_dir)
  1079. writefile(gisrcrc, s)
  1080. cleanup()
  1081. # After this point no more grass modules may be called
  1082. done_message()