Update class List to use convert_to_xml()

Change-Id: I6ef0dc66245a3f2fc1e09ee09506f34fca78eb60
This commit is contained in:
Yolande Amate 2017-06-30 22:24:03 +01:00
parent 7adf73ef1b
commit a558b12dbf
3 changed files with 17 additions and 25 deletions

View File

@ -15,6 +15,8 @@
import xml.etree.ElementTree as XML import xml.etree.ElementTree as XML
import jenkins_jobs.modules.base import jenkins_jobs.modules.base
from jenkins_jobs.modules.helpers import convert_mapping_to_xml
""" """
The view list module handles creating Jenkins List views. The view list module handles creating Jenkins List views.
@ -24,7 +26,7 @@ to the :ref:`View-list` definition.
:View Parameters: :View Parameters:
* **name** (`str`): The name of the view. * **name** (`str`): The name of the view.
* **view-type** (`str`): The type of view. * **view-type** (`str`): The type of view.
* **description** (`str`): A description of the view. (optional) * **description** (`str`): A description of the view. (default '')
* **filter-executors** (`bool`): Show only executors that can * **filter-executors** (`bool`): Show only executors that can
execute the included views. (default false) execute the included views. (default false)
* **filter-queue** (`bool`): Show only included jobs in builder * **filter-queue** (`bool`): Show only included jobs in builder
@ -55,18 +57,13 @@ class List(jenkins_jobs.modules.base.Base):
def root_xml(self, data): def root_xml(self, data):
root = XML.Element('hudson.model.ListView') root = XML.Element('hudson.model.ListView')
XML.SubElement(root, 'name').text = data['name']
desc_text = data.get('description', None)
if desc_text is not None:
XML.SubElement(root, 'description').text = desc_text
filterExecutors = data.get('filter-executors', False) mapping = [
FE_element = XML.SubElement(root, 'filterExecutors') ('name', 'name', None),
FE_element.text = 'true' if filterExecutors else 'false' ('description', 'description', ''),
('filter-executors', 'filterExecutors', False),
filterQueue = data.get('filter-queue', False) ('filter-queue', 'filterQueue', False)]
FQ_element = XML.SubElement(root, 'filterQueue') convert_mapping_to_xml(root, data, mapping, fail_required=True)
FQ_element.text = 'true' if filterQueue else 'false'
XML.SubElement(root, 'properties', XML.SubElement(root, 'properties',
{'class': 'hudson.model.View$PropertyList'}) {'class': 'hudson.model.View$PropertyList'})
@ -82,21 +79,14 @@ class List(jenkins_jobs.modules.base.Base):
c_xml = XML.SubElement(root, 'columns') c_xml = XML.SubElement(root, 'columns')
columns = data.get('columns', []) columns = data.get('columns', [])
for column in columns: for column in columns:
if column in COLUMN_DICT: if column in COLUMN_DICT:
XML.SubElement(c_xml, COLUMN_DICT[column]) XML.SubElement(c_xml, COLUMN_DICT[column])
mapping = [
regex = data.get('regex', None) ('regex', 'includeRegex', None),
if regex is not None: ('recurse', 'recurse', False),
XML.SubElement(root, 'includeRegex').text = regex ('status-filter', 'statusFilter', None)]
convert_mapping_to_xml(root, data, mapping, fail_required=False)
recurse = data.get('recurse', False)
R_element = XML.SubElement(root, 'recurse')
R_element.text = 'true' if recurse else 'false'
statusfilter = data.get('status-filter', None)
if statusfilter is not None:
SF_element = XML.SubElement(root, 'statusFilter')
SF_element.text = 'true' if statusfilter else 'false'
return root return root

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<hudson.model.ListView> <hudson.model.ListView>
<name>regex-example</name> <name>regex-example</name>
<description>description</description>
<filterExecutors>false</filterExecutors> <filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue> <filterQueue>false</filterQueue>
<properties class="hudson.model.View$PropertyList"/> <properties class="hudson.model.View$PropertyList"/>

View File

@ -1,5 +1,6 @@
name: regex-example name: regex-example
view-type: list view-type: list
description: 'description'
columns: columns:
- status - status
- weather - weather