forked from R-ArcGIS/r-bridge-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR Integration.pyt
164 lines (129 loc) · 5.3 KB
/
R Integration.pyt
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import
import os
import sys
import arcpy
import rtools
from rtools.utils import dedent
class Toolbox(object):
def __init__(self):
self.label = 'R Integration'
self.alias = 'rintegration'
self.tools = [UpdateBindings, InstallBindings, RInstallDetails, RVersion]
# Tool implementation code
class UpdateBindings(object):
def __init__(self):
self.label = 'Update R bindings'
self.description = dedent("""
Update the package that ArcGIS uses to communicate with R.
Checks with the server for any newer releases, and if
they exist, installs the new release.""")
self.canRunInBackground = False
def getParameterInfo(self):
return []
def isLicensed(self):
return True
def updateParameters(self, parameters):
validator = getattr(self, 'ToolValidator', None)
if validator:
return validator(parameters).updateParameters()
def updateMessages(self, parameters):
validator = getattr(self, 'ToolValidator', None)
if validator:
return validator(parameters).updateMessages()
def execute(self, parameters, messages):
rtools.update_package()
class RVersion(object):
def __init__(self):
self.label = 'Print R Version'
self.description = dedent("""\
Print the version of R that ArcGIS is connected to.""")
self.canRunInBackground = False
def getParameterInfo(self):
return []
def isLicensed(self):
return True
def updateParameters(self, parameters):
validator = getattr(self, 'ToolValidator', None)
if validator:
return validator(parameters).updateParameters()
def updateMessages(self, parameters):
validator = getattr(self, 'ToolValidator', None)
if validator:
return validator(parameters).updateMessages()
def execute(self, parameters, messages):
rtools.r_version()
class RInstallDetails(object):
def __init__(self):
self.label = 'R Installation Details'
self.description = dedent("""\
Show details of R installation. Also detects
the presence of the ArcGIS R bridge, if installed.
""")
self.canRunInBackground = False
def getParameterInfo(self):
return []
def isLicensed(self):
return True
def updateParameters(self, parameters):
validator = getattr(self, 'ToolValidator', None)
if validator:
return validator(parameters).updateParameters()
def updateMessages(self, parameters):
validator = getattr(self, 'ToolValidator', None)
if validator:
return validator(parameters).updateMessages()
def execute(self, parameters, messages):
if rtools.r_install_path is None:
arcpy.AddError(dedent("""\
R not installed. Please install R prior to using
this toolbox. The R installation can be found at:
http://www.r-project.org/
"""))
else:
arcpy.AddMessage("R (version {}), installed in: {}".format(
rtools.r_version_info, rtools.r_install_path))
arcpy.AddMessage("R packages will be installed into: {}".format(
rtools.r_library_path))
arcpy.AddMessage("All R package libraries detected: {}".format(
";".join(rtools.r_all_library_paths)))
current_package_path = rtools.rpath.r_pkg_path()
current_package_version = rtools.rpath.r_pkg_version()
if current_package_path is None or current_package_version is None:
arcpy.AddWarning("The ArcGIS R package is not installed."
" Use the 'Install R Bindings' tool to "
"install them.")
else:
arcpy.AddMessage(
"The ArcGIS R package (version {}) is installed at: {}".format(
rtools.rpath.r_pkg_version(), current_package_path))
class InstallBindings(object):
def __init__(self):
self.label = 'Install R bindings'
self.description = dedent("""\
Install ArcGIS R bindings onto this machine. R must first
be installed for this command to correctly function.""")
self.canRunInBackground = False
def getParameterInfo(self):
# overwrite existing?
param_1 = arcpy.Parameter()
param_1.name = 'overwrite'
param_1.displayName = 'Overwrite Existing Installation?'
param_1.parameterType = 'Required'
param_1.direction = 'Input'
param_1.datatype = 'GPBoolean'
param_1.value = False
return [param_1]
def isLicensed(self):
return True
def updateParameters(self, parameters):
validator = getattr(self, 'ToolValidator', None)
if validator:
return validator(parameters).updateParameters()
def updateMessages(self, parameters):
validator = getattr(self, 'ToolValidator', None)
if validator:
return validator(parameters).updateMessages()
def execute(self, parameters, messages):
rtools.install_package(overwrite=parameters[0].value)