Jason Scheirer avatar Jason Scheirer committed 18ec78b

Bring validation over if possible

Comments (0)

Files changed (1)

 
 ACCEPTABLE_VARIABLENAME = re.compile("^[_a-z][_a-z0-9]*$", re.IGNORECASE)
 CALL_RE_TEMPLATE = "((?:[_a-z][_a-z0-9]* *[.] *)*{}\(([^)]*)\))"
-CODING_RE = re.compile("coding: ([^ ]+)")
+CODING_RE = re.compile("coding: ([^ ]+)", re.IGNORECASE)
 HEADER_SOURCE = """# -*- coding: utf-8 -*-
 
 import contextlib
     ('GetParameterAsText', 'parameters[{}].valueAsText'),
     ('SetParameterAsText', 'set_parameter_as_text(parameters, {})'),
     ('GetParameter', 'parameters[{}]'),
-    ('GetArgumentCount', 'len(parameters)')
+    ('GetArgumentCount', 'len(parameters)'),
+    ('GetParameterInfo', 'parameters')
 )
 
 def collect_lines(fn):
                                   for line in source.split("\n"))
     # Now apply some mechanical translations to common parameter access routines
     for fnname, replacement_pattern in FUNCTION_REMAPPINGS:
-        regexp = re.compile(CALL_RE_TEMPLATE.format(fnname))
+        regexp = re.compile(CALL_RE_TEMPLATE.format(fnname), re.IGNORECASE)
         finds = regexp.findall(src)
         if finds:
             for codepattern, arguments in finds:
     def python_code(self):
         yield "class {}(object):".format(self.name)
         yield '    """{}"""'.format(self._tool.PathName.encode("utf-8"))
+
+        try:
+            gptool = pytexportutils.IGPScriptTool2(self._tool)
+            codeblock = gptool.CodeBlock.encode("utf-8").replace("__init__(self)", "__init__(self, parameters)")
+            yield rearrange_source(codeblock, 4)
+        except:
+            pass
+
         yield "    def __init__(self):"
         try:
             yield "        self.label = {}".format(repr(self._tool.DisplayName))
         try:
             yield "        self.canRunInBackground = {}".format(not pytexportutils.IGPScriptTool2(self._tool).RunInProc)
         except:
-            pass
+            yield "        self.canRunInBackground = False"
         yield "    def getParameterInfo(self):"
         index_dict = {parameter.Name.lower(): idx for idx, parameter in enumerate(self._parameters)}
         for idx, parameter in enumerate(self._parameters):
                     pass
                 if dep_list:
                     yield "        param_{}.parameterDependencies = {}".format(idx + 1, repr(dep_list))
-            except Exception as e:
-                yield "        # DEPENDENCIES ERROR {}".format(e)
+            except:
                 pass
             yield ""
         yield "        return [{}]".format(", ".join("param_{}".format(idx + 1) for idx in xrange(len(self._parameters))))
         yield "    def isLicensed(self):"
         yield "        return True"
         yield "    def updateParameters(self, parameters):"
-        yield "        pass"
+        yield "        validator = getattr(self, 'ToolValidator', None)"
+        yield "        if validator:"
+        yield "             return validator(parameters).updateParameters()"
         yield "    def updateMessages(self, parameters):"
-        yield "        pass"
+        yield "        validator = getattr(self, 'ToolValidator', None)"
+        yield "        if validator:"
+        yield "             return validator(parameters).updateMessages()"
         yield "    def execute(self, parameters, messages):"
         try:
             filename = pytexportutils.IGPScriptTool(self._tool).FileName
 
 if __name__ == "__main__":
     import glob
-    for filename in [r'Toolboxes\My Toolboxes\OutScript.tbx']:
+    for filename in [r'C:\SupportFiles\ArcGIS\ArcToolBox\Toolboxes\Spatial Statistics Tools.tbx']: #[r'Toolboxes\My Toolboxes\OutScript.tbx']:
         print HEADER_SOURCE
         print PYTToolbox(filename).python_code.encode("ascii", "replace")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.