-
Notifications
You must be signed in to change notification settings - Fork 15
/
ArcpyMockup.py
56 lines (49 loc) · 1.71 KB
/
ArcpyMockup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
#-------------------------------------------------------------------------------
# Name: arcapi.ArcpyMockup
# Purpose: Class to pretend that arcpy is always present.
#
# Authors: Filip Kral,
#
# Created: 28/07/2014
# Licence: LGPL v3
#-------------------------------------------------------------------------------
#
# Not all functions in arcapi require arcpy. This module allows you to use
# arcapi even if you don't have arcpy. The functions that require arcpy will
# not work, but you can still use functions that do not need arcpy.
#
#
# You do not have to do anything to load arcapi, it has been coded to use this
# module. If you want to pretend that arcpy is present on computers without
# ArcGIS in your own projects, you can reuse the class from this module like so:
#
# try:
# import arcpy
# except ImportError:
# arcpy = ArcpyMockup()
#
#-------------------------------------------------------------------------------
"""
from types import ModuleType
class ArcpyMockup(ModuleType):
"""This class will create object that looks like
the arcpy module on computers where arcpy is not
available so that users without arcpy can still use
arcapi functions that do not require arcpy.
Calls to functions that require arcpy will print
a WARNING message.
"""
def __init__(self):
"""Create mockup of the arcpy module"""
self.da = None
# override some methods
def AddMessage(self, m):
print m
def AddWarning(self, m):
print m
def __getattr__(self, key):
m = 'WARNING: Arcapi loaded without arcpy, %s not available' % key
print m
return None
__all__ = [] # support wildcard imports