def find_view(self, view_name): """Attempts to locate a sub-view under this nested view with the given name :param str view_name: the name of the sub-view to locate :returns: Reference to View object for the view with the given name, or None if no view with that name exists :rtype: Object derived from :class:`~.view.View` """ data = self._controller.get_api_data() raw_views = data['views'] for cur_view in raw_views: if cur_view['name'] == view_name: new_io_obj = self._controller.clone(cur_view['url']) return View.create(new_io_obj, self._master) for cur_view in raw_views: new_io_obj = self._controller.clone(cur_view['url']) temp_view = View.create(new_io_obj, self._master) if temp_view.type == NestedView.type: sub_view = temp_view.find_view(view_name) if sub_view is not None: return sub_view return None
def find_view(self, view_name): """Searches views directly managed by this Jenkins instance for a specific view .. seealso: :py:meth:`.get_view` :param str view_name: the name of the view to search for :returns: If a view with the specified name can be found, an object to manage the view will be returned, otherwise None :rtype: :class:`~.view.View` """ data = self._controller.get_api_data() raw_views = data['views'] for cur_view in raw_views: if cur_view['name'] == view_name: turl = cur_view['url'] if turl.find('view') == -1: turl = turl.rstrip("/") + "/view/" + cur_view['name'] new_io_obj = self._controller.clone(turl) return View.create(new_io_obj, self) return None
def views(self): """Gets a list of all views directly managed by the Jenkins dashboard To retrieve all views managed by this Jenkins instance, including recursing into views that support sub-views, see the :py:meth:`.all_views` property :returns: list of one or more views defined on this Jenkins instance. :rtype: :class:`list` of :class:`~.view.View` objects """ data = self._controller.get_api_data() raw_views = data['views'] retval = [] for cur_view in raw_views: # The default view will not have a valid view URL # so we need to look for this and generate a corrected one turl = cur_view['url'] if turl.find('view') == -1: turl = turl.rstrip("/") + "/view/" + cur_view['name'] new_io_obj = self._controller.clone(turl) tview = View.create(new_io_obj, self) retval.append(tview) return retval
def create_view(self, view_name, view_type): """Creates a new sub-view within this nested view :param str view_name: name of the new sub-view to create :param str view_type: data type for newly generated view """ view_type = view_type.replace("__", "_") headers = {'Content-Type': 'application/x-www-form-urlencoded'} data = { "name": view_name, "mode": view_type, "Submit": "OK", "json": json.dumps({"name": view_name, "mode": view_type}) } args = {} args['data'] = data args['headers'] = headers self._controller.post('/createView', args) # Load a pyjen.View object with the new view data = self._controller.get_api_data() raw_views = data['views'] for cur_view in raw_views: if cur_view['name'] == view_name: new_io_obj = self._controller.clone(cur_view['url']) return View.create(new_io_obj, self._master) raise NestedViewCreationError("Failed to create nested view " + view_name + " under " + self.name)
def get_view(self, url): """Establishes a connection to a View based on an absolute URL This method may be a bit less convenient to use in certain situations but it has better performance than :py:meth:`.find_view` .. seealso: :py:meth:`.find_view` :param str url: absolute URL of the view to load :return: an instance of the appropriate View subclass for the given view :rtype: :class:`~.view.View` """ new_io_obj = self._controller.clone(url) return View.create(new_io_obj, self)
def default_view(self): """returns a reference to the primary / default Jenkins view The default view is the one displayed when navigating to the main URL. Typically this will be the "All" view. :returns: object that manages the default Jenkins view :rtype: :class:`~.view.View` """ data = self._controller.get_api_data() default_view = data['primaryView'] new_io_obj = self._controller.clone(default_view['url'].rstrip("/") + "/view/" + default_view['name']) return View.create(new_io_obj, self)
def views(self): """Gets all views contained within this view To get a recursive list of all child views and their children use :py:func:`all_views`. :returns: list of all views contained within this view :rtype: :class:`list` """ data = self._controller.get_api_data() raw_views = data['views'] retval = [] for cur_view in raw_views: new_io_obj = self._controller.clone(cur_view['url']) tview = View.create(new_io_obj, self._master) retval.append(tview) return retval