[GRASS-SVN] r61187 - in grass/trunk: gui/wxpython lib/python lib/python/exceptions lib/python/pygrass lib/python/pygrass/messages lib/python/pygrass/modules/interface lib/python/script lib/python/temporal
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jul 8 05:09:33 PDT 2014
Author: zarch
Date: 2014-07-08 05:09:32 -0700 (Tue, 08 Jul 2014)
New Revision: 61187
Added:
grass/trunk/lib/python/exceptions/
grass/trunk/lib/python/exceptions/Makefile
grass/trunk/lib/python/exceptions/__init__.py
Modified:
grass/trunk/gui/wxpython/wxgui.py
grass/trunk/lib/python/Makefile
grass/trunk/lib/python/pygrass/errors.py
grass/trunk/lib/python/pygrass/messages/__init__.py
grass/trunk/lib/python/pygrass/modules/interface/module.py
grass/trunk/lib/python/script/core.py
grass/trunk/lib/python/temporal/abstract_dataset.py
grass/trunk/lib/python/temporal/temporal_algebra.py
Log:
exceptions: Move exceptions from around the GRASS code to one place
Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py 2014-07-08 10:58:50 UTC (rev 61186)
+++ grass/trunk/gui/wxpython/wxgui.py 2014-07-08 12:09:32 UTC (rev 61187)
@@ -1,4 +1,4 @@
-"""
+"""
@package wxgui
@brief Main Python application for GRASS wxPython GUI
@@ -25,6 +25,8 @@
from core import globalvar
from core.utils import _
+from grass.exceptions import Usage
+
import wx
try:
import wx.lib.agw.advancedsplash as SC
@@ -33,6 +35,7 @@
from lmgr.frame import GMFrame
+
class GMApp(wx.App):
def __init__(self, workspace = None):
""" Main GUI class.
@@ -40,28 +43,28 @@
:param workspace: path to the workspace file
"""
self.workspaceFile = workspace
-
+
# call parent class initializer
wx.App.__init__(self, False)
-
+
self.locale = wx.Locale(language = wx.LANGUAGE_DEFAULT)
-
+
def OnInit(self):
""" Initialize all available image handlers
-
+
:return: True
"""
if not globalvar.CheckWxVersion([2, 9]):
wx.InitAllImageHandlers()
-
+
# create splash screen
introImagePath = os.path.join(globalvar.IMGDIR, "silesia_splash.png")
introImage = wx.Image(introImagePath, wx.BITMAP_TYPE_PNG)
introBmp = introImage.ConvertToBitmap()
if SC and sys.platform != 'darwin':
- # AdvancedSplash is buggy on the Mac as of 2.8.12.1
+ # AdvancedSplash is buggy on the Mac as of 2.8.12.1
# and raises annoying (though seemingly harmless) errors everytime the GUI is started
- splash = SC.AdvancedSplash(bitmap = introBmp,
+ splash = SC.AdvancedSplash(bitmap = introBmp,
timeout = 2000, parent = None, id = wx.ID_ANY)
splash.SetText(_('Starting GRASS GUI...'))
splash.SetTextColour(wx.Colour(45, 52, 27))
@@ -71,21 +74,18 @@
else:
wx.SplashScreen (bitmap = introBmp, splashStyle = wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
milliseconds = 2000, parent = None, id = wx.ID_ANY)
-
+
wx.Yield()
-
+
# create and show main frame
mainframe = GMFrame(parent = None, id = wx.ID_ANY,
workspace = self.workspaceFile)
-
+
mainframe.Show()
self.SetTopWindow(mainframe)
-
+
return True
-class Usage(Exception):
- def __init__(self, msg):
- self.msg = msg
def printHelp():
""" Print program help"""
@@ -95,13 +95,14 @@
print >> sys.stderr, " -w\t--workspace file\tWorkspace file to load"
sys.exit(1)
+
def process_opt(opts, args):
""" Process command-line arguments"""
workspaceFile = None
for o, a in opts:
if o in ("-h", "--help"):
printHelp()
-
+
if o in ("-w", "--workspace"):
if a != '':
workspaceFile = str(a)
@@ -110,8 +111,9 @@
return (workspaceFile,)
+
def main(argv = None):
-
+
if argv is None:
argv = sys.argv
try:
@@ -120,19 +122,19 @@
["help", "workspace"])
except getopt.error as msg:
raise Usage(msg)
-
+
except Usage as err:
print >> sys.stderr, err.msg
print >> sys.stderr, "for help use --help"
printHelp()
-
+
workspaceFile = process_opt(opts, args)[0]
-
+
app = GMApp(workspaceFile)
# suppress wxPython logs
q = wx.LogNull()
-
+
app.MainLoop()
-
+
if __name__ == "__main__":
sys.exit(main())
Modified: grass/trunk/lib/python/Makefile
===================================================================
--- grass/trunk/lib/python/Makefile 2014-07-08 10:58:50 UTC (rev 61186)
+++ grass/trunk/lib/python/Makefile 2014-07-08 12:09:32 UTC (rev 61187)
@@ -5,7 +5,7 @@
PYDIR = $(ETC)/python/grass
-SUBDIRS = script ctypes temporal pygrass pydispatch imaging
+SUBDIRS = exceptions script ctypes temporal pygrass pydispatch imaging
default: $(PYDIR)/__init__.py
$(MAKE) subdirs
Added: grass/trunk/lib/python/exceptions/Makefile
===================================================================
--- grass/trunk/lib/python/exceptions/Makefile (rev 0)
+++ grass/trunk/lib/python/exceptions/Makefile 2014-07-08 12:09:32 UTC (rev 61187)
@@ -0,0 +1,30 @@
+MODULE_TOPDIR=../../..
+
+include $(MODULE_TOPDIR)/include/Make/Other.make
+include $(MODULE_TOPDIR)/include/Make/Python.make
+include $(MODULE_TOPDIR)/include/Make/Doxygen.make
+
+PYDIR = $(ETC)/python
+GDIR = $(PYDIR)/grass
+DSTDIR = $(GDIR)/exceptions
+
+PYFILES := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
+PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)
+
+default: $(PYFILES) $(PYCFILES) $(GDIR)/__init__.py $(GDIR)/__init__.pyc
+
+
+$(PYDIR):
+ $(MKDIR) $@
+
+$(GDIR): | $(PYDIR)
+ $(MKDIR) $@
+
+$(DSTDIR): | $(GDIR)
+ $(MKDIR) $@
+
+$(DSTDIR)/%: % | $(DSTDIR)
+ $(INSTALL_DATA) $< $@
+
+#doxygen:
+DOXNAME = exceptions
Added: grass/trunk/lib/python/exceptions/__init__.py
===================================================================
--- grass/trunk/lib/python/exceptions/__init__.py (rev 0)
+++ grass/trunk/lib/python/exceptions/__init__.py 2014-07-08 12:09:32 UTC (rev 61187)
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+
+
+class DBError(Exception):
+ pass
+
+
+class FatalError(Exception):
+ pass
+
+
+class FlagError(Exception):
+ pass
+
+
+class GrassError(Exception):
+ pass
+
+
+class ImplementationError(Exception):
+ pass
+
+
+class OpenError(Exception):
+ pass
+
+
+class ParameterError(Exception):
+ pass
+
+
+class ScriptError(Exception):
+ pass
+
+
+class Usage(Exception):
+ pass
Modified: grass/trunk/lib/python/pygrass/errors.py
===================================================================
--- grass/trunk/lib/python/pygrass/errors.py 2014-07-08 10:58:50 UTC (rev 61186)
+++ grass/trunk/lib/python/pygrass/errors.py 2014-07-08 12:09:32 UTC (rev 61187)
@@ -5,37 +5,13 @@
@author: pietro
"""
from functools import wraps
-from grass.pygrass.messages import get_msgr
+from grass.exceptions import (FlagError, ParameterError, DBError,
+ GrassError, OpenError)
-class AbstractError(Exception):
- def __init__(self, value):
- self.value = value
+from grass.pygrass.messages import get_msgr
- def __str__(self):
- return repr(self.value)
-
-class ParameterError(Exception):
- pass
-
-
-class FlagError(Exception):
- pass
-
-
-class DBError(AbstractError):
- pass
-
-
-class GrassError(AbstractError):
- pass
-
-
-class OpenError(AbstractError):
- pass
-
-
def must_be_open(method):
@wraps(method)
Modified: grass/trunk/lib/python/pygrass/messages/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/messages/__init__.py 2014-07-08 10:58:50 UTC (rev 61186)
+++ grass/trunk/lib/python/pygrass/messages/__init__.py 2014-07-08 12:09:32 UTC (rev 61187)
@@ -14,21 +14,12 @@
@author Soeren Gebbert
"""
import sys
-import grass.lib.gis as libgis
from multiprocessing import Process, Lock, Pipe
+import grass.lib.gis as libgis
+from grass.exceptions import FatalError
-class FatalError(Exception):
- """This error will be raised in case raise_on_error was set True
- when creating the messenger object.
- """
- def __init__(self, msg):
- self.value = msg
- def __str__(self):
- return self.value
-
-
def message_server(lock, conn):
"""The GRASS message server function designed to be a target for
multiprocessing.Process
Modified: grass/trunk/lib/python/pygrass/modules/interface/module.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/interface/module.py 2014-07-08 10:58:50 UTC (rev 61186)
+++ grass/trunk/lib/python/pygrass/modules/interface/module.py 2014-07-08 12:09:32 UTC (rev 61187)
@@ -410,25 +410,21 @@
for flg in kargs['flags']:
self.flags[flg].value = True
del(kargs['flags'])
- if 'run_' in kargs:
- self.run_ = kargs['run_']
- del(kargs['run_'])
- if 'stdin_' in kargs:
- self.inputs['stdin'].value = kargs['stdin_']
- del(kargs['stdin_'])
- if 'stdout_' in kargs:
- self.stdout_ = kargs['stdout_']
- del(kargs['stdout_'])
- if 'stderr_' in kargs:
- self.stderr_ = kargs['stderr_']
- del(kargs['stderr_'])
- if 'env_' in kargs:
- self.env_ = kargs['env_']
- del(kargs['env_'])
- if 'finish_' in kargs:
- self.finish_ = kargs['finish_']
- del(kargs['finish_'])
+ # set attributs
+ for key in ('run_', 'env_', 'finish_'):
+ if key in kargs:
+ setattr(self, key, kargs.pop(key))
+
+ # set inputs
+ for key in ('stdin_', ):
+ if key in kargs:
+ self.inputs[key].value = kargs.pop(key)
+ # set outputs
+ for key in ('stdout_', 'stderr_'):
+ if key in kargs:
+ self.outputs[key].value = kargs.pop(key)
+
#
# check args
#
@@ -570,6 +566,9 @@
self.outputs['stdout'].value = stdout if stdout else ''
self.outputs['stderr'].value = stderr if stderr else ''
self.time = time.time() - start
+ #if self.popen.poll():
+ # raise CalledModuleError(self.popen.returncode, self.get_bash(),
+ # {}, stderr)
return self
###############################################################################
Modified: grass/trunk/lib/python/script/core.py
===================================================================
--- grass/trunk/lib/python/script/core.py 2014-07-08 10:58:50 UTC (rev 61186)
+++ grass/trunk/lib/python/script/core.py 2014-07-08 12:09:32 UTC (rev 61187)
@@ -33,6 +33,8 @@
import locale
import codecs
+from grass.exceptions import ScriptError
+
# i18N
import gettext
gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'))
@@ -67,13 +69,6 @@
STDOUT = subprocess.STDOUT
-class ScriptError(Exception):
- def __init__(self, msg):
- self.value = msg
-
- def __str__(self):
- return self.value
-
raise_on_error = False # raise exception instead of calling fatal()
@@ -519,7 +514,7 @@
if debug_level() >= debug:
if sys.platform == "win32":
msg = msg.replace('&', '^&')
-
+
run_command("g.message", flags='d', message=msg, debug=debug)
def verbose(msg):
@@ -866,7 +861,7 @@
@param val_sep The character that separates the values of a single key, default is ","
@param checkproj True if it has to check some information about projection system
@param checkproj True if it has to check some information about units
-
+
@return The dictionary
A text file with this content:
@@ -985,9 +980,9 @@
def diff_files(filename_a, filename_b):
"""!Diffs two text files and returns difference.
- @param filename_a first file path
+ @param filename_a first file path
@param filename_b second file path
-
+
@return list of strings
"""
import difflib
@@ -1619,7 +1614,7 @@
else:
warning(_("Location <%s> already exists and will be overwritten") % location)
shutil.rmtree(os.path.join(dbase, location))
-
+
kwargs = dict()
if datum:
kwargs['datum'] = datum
Modified: grass/trunk/lib/python/temporal/abstract_dataset.py
===================================================================
--- grass/trunk/lib/python/temporal/abstract_dataset.py 2014-07-08 10:58:50 UTC (rev 61186)
+++ grass/trunk/lib/python/temporal/abstract_dataset.py 2014-07-08 12:09:32 UTC (rev 61187)
@@ -22,16 +22,8 @@
from temporal_topology_dataset_connector import *
from spatial_topology_dataset_connector import *
+from grass.exceptions import ImplementationError
-class ImplementationError(Exception):
- """!Exception raised for the calling of methods that should be implemented in
- sub classes.
- """
- def __init__(self, msg):
- self.msg = msg
- def __str__(self):
- return repr(self.msg)
-
###############################################################################
class AbstractDataset(SpatialTopologyDatasetConnector, TemporalTopologyDatasetConnector):
Modified: grass/trunk/lib/python/temporal/temporal_algebra.py
===================================================================
--- grass/trunk/lib/python/temporal/temporal_algebra.py 2014-07-08 10:58:50 UTC (rev 61186)
+++ grass/trunk/lib/python/temporal/temporal_algebra.py 2014-07-08 12:09:32 UTC (rev 61187)
@@ -396,6 +396,8 @@
from open_stds import *
import copy
+from grass.exceptions import FatalError
+
##############################################################################
class TemporalAlgebraLexer(object):
@@ -650,17 +652,10 @@
def __str__(self):
return str(self.tfunc) + str(self.compop) + str(self.value)
-###############################################################################
-class FatalError(Exception):
- def __init__(self, msg):
- self.value = msg
-
- def __str__(self):
- return self.value
-
###############################################################################
+
class TemporalAlgebraParser(object):
"""The temporal algebra class"""
More information about the grass-commit
mailing list