Changeset 1039


Ignore:
Timestamp:
08/31/12 18:07:23 (5 years ago)
Author:
jjr8
Message:

Fixed more Python 2.7 / ArcGIS 10.1 compatibility problems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/ArcGIS.py

    r1036 r1039  
    226226            cls._InstantiateGeoprocessorForArc92OrLater(major, minor, 2, 5, forceCOMInstantiation, forcePythonInstantiation) 
    227227         
     228        elif major == 10 and minor == 0: 
     229            cls._InstantiateGeoprocessorForArc92OrLater(major, minor, 2, 6, forceCOMInstantiation, forcePythonInstantiation) 
     230         
    228231        elif major >= 10: 
    229             cls._InstantiateGeoprocessorForArc92OrLater(major, minor, 2, 6, forceCOMInstantiation, forcePythonInstantiation) 
     232            cls._InstantiateGeoprocessorForArc92OrLater(major, minor, 2, 7, forceCOMInstantiation, forcePythonInstantiation) 
    230233 
    231234        else: 
     
    980983        # If it is a method, create a wrapper, add it to our dictionary of 
    981984        # wrapped methods, and return the wrapper. 
    982  
    983         if isinstance(value, (types.MethodType, types.BuiltinFunctionType, types.BuiltinMethodType)): 
     985        # 
     986        # Note: for ArcGIS 10.1, geoprocessing tools are no longer 
     987        # returned as methods or functions. Instead they are instances 
     988        # of <type 'geoprocessing Tool object'>, which are callable 
     989        # like methods. 
     990 
     991        if isinstance(value, (types.MethodType, types.BuiltinFunctionType, types.BuiltinMethodType)) or (GeoprocessorManager.GetArcGISMajorVersion() == 10 and GeoprocessorManager.GetArcGISMinorVersion() == 1 or GeoprocessorManager.GetArcGISMajorVersion() > 10) and isinstance(value, type(getattr(GeoprocessorManager.GetGeoprocessor(), 'Delete_management'))): 
    984992 
    985993            # Write the methods's definition. 
     
    11351143            _locals[argName] = self._ToGeoprocessorPreferredType(_locals[argName]) 
    11361144 
     1145        if hasattr(method, 'Name') and isinstance(method.Name, basestring) and len(method.Name) > 0: 
     1146            if hasattr(method, 'Toolbox') and hasattr(method.Toolbox, 'Alias') and isinstance(method.Toolbox.Alias, basestring) and len(method.Toolbox.Alias) > 0: 
     1147                methodName = method.Name + '_' + method.Toolbox.Alias 
     1148            else: 
     1149                methodName = method.Name 
     1150        else: 
     1151            methodName = method.__name__ 
     1152 
    11371153        if _varargs is not None: 
    11381154 
     
    11501166            # geoprocessor is used. 
    11511167 
    1152             if self._Name == 'Row' and method.__name__.lower() == 'setvalue' and len(_locals[_varargs]) == 2 and _locals[_varargs][1] is None: 
     1168            if self._Name == 'Row' and methodName.lower() == 'setvalue' and len(_locals[_varargs]) == 2 and _locals[_varargs][1] is None: 
    11531169                _locals[_varargs] = (self._ToGeoprocessorPreferredType(_locals[_varargs][0]), None) 
    11541170            else: 
     
    11571173        # Build the source code needed to invoke the method. 
    11581174 
    1159         sourceCode = 'self._Object.%s(' % method.__name__ 
     1175        sourceCode = 'self._Object.%s(' % methodName 
    11601176        for argName in _args: 
    11611177            if not sourceCode.endswith('('): 
     
    11921208            tempDir = None 
    11931209            scratchDir = None 
    1194             if self._Name == u'Geoprocessor' and method.__name__.endswith('_sa'): 
     1210            if self._Name == u'Geoprocessor' and methodName.endswith('_sa'): 
    11951211                scratchDir = self.ScratchWorkspace 
    11961212                from GeoEco.DataManagement.Directories import TemporaryDirectory 
     
    12001216            # Invoke the method. 
    12011217 
    1202             self._LogDebug(_(u'ArcGIS %s object 0x%08X: Invoking %s%s...') % (self._Name, id(self._Object), method.__name__, inspect.formatargvalues(_args, _varargs, _varkw, _locals))) 
     1218            self._LogDebug(_(u'ArcGIS %s object 0x%08X: Invoking %s%s...') % (self._Name, id(self._Object), methodName, inspect.formatargvalues(_args, _varargs, _varkw, _locals))) 
    12031219 
    12041220            try: 
     
    12141230                        value = eval(sourceCode, globals(), locals()) 
    12151231                    except sys.modules['pythoncom'].com_error, (hr, msg, exc, arg): 
    1216                         self._LogReturnedGeoprocessingMessages(method.__name__) 
     1232                        self._LogReturnedGeoprocessingMessages(methodName) 
    12171233                        from GeoEco.COM import FormatCOMError 
    1218                         if self._Name == u'Geoprocessor' and method.__name__.lower() not in _ArcGISObjectWrapper._NonGeoprocessingToolMethods: 
    1219                             raise ArcGISError(_(u'The ArcGIS %(tool)s geoprocessing tool failed when given the parameters %(params)s and reported %(error)s') % {u'tool': method.__name__, u'params': inspect.formatargvalues(_args, _varargs, _varkw, _locals), u'error': FormatCOMError(hr, msg, exc, arg)}) 
     1234                        if self._Name == u'Geoprocessor' and methodName.lower() not in _ArcGISObjectWrapper._NonGeoprocessingToolMethods: 
     1235                            raise ArcGISError(_(u'The ArcGIS %(tool)s geoprocessing tool failed when given the parameters %(params)s and reported %(error)s') % {u'tool': methodName, u'params': inspect.formatargvalues(_args, _varargs, _varkw, _locals), u'error': FormatCOMError(hr, msg, exc, arg)}) 
    12201236                        else: 
    1221                             raise ArcGISError(_(u'The %(func)s function of the ArcGIS %(obj)s object failed when given the parameters %(params)s and reported %(error)s') % {u'func': method.__name__, u'obj': self._Name, u'params': inspect.formatargvalues(_args, _varargs, _varkw, _locals), u'error': FormatCOMError(hr, msg, exc, arg)}) 
     1237                            raise ArcGISError(_(u'The %(func)s function of the ArcGIS %(obj)s object failed when given the parameters %(params)s and reported %(error)s') % {u'func': methodName, u'obj': self._Name, u'params': inspect.formatargvalues(_args, _varargs, _varkw, _locals), u'error': FormatCOMError(hr, msg, exc, arg)}) 
    12221238 
    12231239                # If we did not import pythoncom, invoke the method and allow the 
     
    12381254             
    12391255            except Exception, e: 
    1240                 self._LogReturnedGeoprocessingMessages(method.__name__) 
    1241                 if self._Name == u'Geoprocessor' and method.__name__.lower() not in _ArcGISObjectWrapper._NonGeoprocessingToolMethods: 
    1242                     raise ArcGISError(_(u'The ArcGIS %(tool)s geoprocessing tool failed when given the parameters %(params)s and reported %(error)s: %(msg)s') % {u'tool': method.__name__, u'params': inspect.formatargvalues(_args, _varargs, _varkw, _locals), u'error': e.__class__.__name__, u'msg': unicode(e)}) 
     1256                self._LogReturnedGeoprocessingMessages(methodName) 
     1257                if self._Name == u'Geoprocessor' and methodName.lower() not in _ArcGISObjectWrapper._NonGeoprocessingToolMethods: 
     1258                    raise ArcGISError(_(u'The ArcGIS %(tool)s geoprocessing tool failed when given the parameters %(params)s and reported %(error)s: %(msg)s') % {u'tool': methodName, u'params': inspect.formatargvalues(_args, _varargs, _varkw, _locals), u'error': e.__class__.__name__, u'msg': unicode(e)}) 
    12431259                else: 
    1244                     raise ArcGISError(_(u'The %(func)s function of the ArcGIS %(obj)s object failed when given the parameters %(params)s and reported %(error)s') % {u'func': method.__name__, u'obj': self._Name, u'params': inspect.formatargvalues(_args, _varargs, _varkw, _locals), u'error': e.__class__.__name__, u'msg': unicode(e)}) 
     1260                    raise ArcGISError(_(u'The %(func)s function of the ArcGIS %(obj)s object failed when given the parameters %(params)s and reported %(error)s') % {u'func': methodName, u'obj': self._Name, u'params': inspect.formatargvalues(_args, _varargs, _varkw, _locals), u'error': e.__class__.__name__, u'msg': unicode(e)}) 
    12451261 
    12461262            # The method executed successfully. Log any geoprocessing messages it 
    12471263            # generated. 
    12481264 
    1249             self._LogReturnedGeoprocessingMessages(method.__name__) 
     1265            self._LogReturnedGeoprocessingMessages(methodName) 
    12501266 
    12511267            # Log the returned value. 
    12521268 
    1253             self._LogDebug(_(u'ArcGIS %s object 0x%08X: %s returned %s') % (self._Name, id(self._Object), method.__name__, repr(value))) 
     1269            self._LogDebug(_(u'ArcGIS %s object 0x%08X: %s returned %s') % (self._Name, id(self._Object), methodName, repr(value))) 
    12541270 
    12551271        # If we created a temporary directory to manage the rasters 
     
    12671283        # the type we prefer. 
    12681284 
    1269         value = self._FromGeoprocessorPreferredType(value, method.__name__, *(tuple(map(_locals.get, _args)) + _locals[_varargs])) 
     1285        value = self._FromGeoprocessorPreferredType(value, methodName, *(tuple(map(_locals.get, _args)) + _locals[_varargs])) 
    12701286 
    12711287        # Special case: If the geoprocessor was created with 
     
    12751291 
    12761292        if not GeoprocessorManager.GetGeoprocessorIsCOMObject() and value is not None: 
    1277             methodName = method.__name__.lower() 
     1293            methodName = methodName.lower() 
    12781294 
    12791295            if self._Name == u'Geoprocessor' and (methodName == u'searchcursor' or methodName == u'insertcursor' or methodName == u'updatecursor'): 
Note: See TracChangeset for help on using the changeset viewer.