def register_tool(self, _tool, _module): assert _tool.name not in self._tools if self._init_project is None: name = _tool.name else: name = self._init_project + ':' + _tool.name log("Registering tool {}".format(name)) self._tools[name] = _tool self._modules[name] = _module
def import_projects(projects): """ Load any user specified tools directories. Expecting dict of {<prefix>: <path>} """ ret = {} for name, path in projects.items(): log("Loading project {}".format(name)) path = os.path.expanduser(path) sys.path.insert(1, path) init_file = os.path.join(path, '__init__.py') import_tools(init_file, prefix=name) ret[name] = path return ret
def execute(server, script, args, raw_output=False): """ Execute the script string on server using args Note: args[0] is expected to be the filename of the script. Returns a tuple (status, data) where data is the parsed json object if status is OK, otherwise it is the raw response content. """ url = server.url(SERVICE_PATH) script = _replace_vars(script, args) form_data = dict(script=script) log("Posting groovy script to {}".format(url)) resp = requests.post(url, auth=server.auth, data=form_data) if resp.status_code == 200: data = resp.json() output = _clean_output(data) if not raw_output else data return OK, output else: return SERVER_ERROR, resp.content
def import_tools(path, package=None, prefix=None, config=None): """ Import tools in directory path path -- Path string to the directory to import e.g. /projects/foo/bar package -- the package name of the imported path e.g. foo.bar prefix -- the name prefix to set to the tools in the directory """ log("Importing path {} : {}".format(path, package)) pyfiles = _list_files(path) tool_repo.set_prefix(prefix) tool_repo.config = config for pyfile in pyfiles: if pyfile == '__init__.py' or pyfile[-3:] != '.py': continue module_name = pyfile[:-3] if package is not None: module_name = "{}.{}".format(package, module_name) importlib.import_module(module_name)
def execute(server, script, args, raw_output=False): """ Execute the script string on server using args Note: args[0] is expected to be the filename of the script. Returns a tuple (status, data) where data is the parsed json object if status is OK, otherwise it is the raw response content. """ url = server.url(SERVICE_PATH) script = _replace_vars(script, args) form_data = dict( script=script ) log("Posting groovy script to {}".format(url)) resp = requests.post(url, auth=server.auth, data=form_data) if resp.status_code == 200: data = resp.json() output = _clean_output(data) if not raw_output else data return OK, output else: return SERVER_ERROR, resp.content