Pep8 fixes for jenkins_* module (#24154)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/24144/head
Abhijeet Kasurde 8 years ago committed by Matt Martz
parent d088030fa6
commit cdca648f15

@ -163,7 +163,9 @@ try:
except ImportError: except ImportError:
python_lxml_installed = False python_lxml_installed = False
class JenkinsJob: class JenkinsJob:
def __init__(self, module): def __init__(self, module):
self.module = module self.module = module
@ -265,7 +267,7 @@ class JenkinsJob:
if self.enabled is None: if self.enabled is None:
return False return False
if ( (self.enabled is False and status != "disabled") or (self.enabled is True and status == "disabled") ): if ((self.enabled is False and status != "disabled") or (self.enabled is True and status == "disabled")):
return True return True
return False return False
@ -328,31 +330,34 @@ class JenkinsJob:
result['enabled'] = None result['enabled'] = None
return result return result
def test_dependencies(module): def test_dependencies(module):
if not python_jenkins_installed: if not python_jenkins_installed:
module.fail_json(msg="python-jenkins required for this module. "\ module.fail_json(msg="python-jenkins required for this module. "
"see http://python-jenkins.readthedocs.io/en/latest/install.html") "see http://python-jenkins.readthedocs.io/en/latest/install.html")
if not python_lxml_installed: if not python_lxml_installed:
module.fail_json(msg="lxml required for this module. "\ module.fail_json(msg="lxml required for this module. "
"see http://lxml.de/installation.html") "see http://lxml.de/installation.html")
def job_config_to_string(xml_str): def job_config_to_string(xml_str):
return ET.tostring(ET.fromstring(xml_str)) return ET.tostring(ET.fromstring(xml_str))
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec=dict(
config = dict(required=False), config=dict(required=False),
name = dict(required=True), name=dict(required=True),
password = dict(required=False, no_log=True), password=dict(required=False, no_log=True),
state = dict(required=False, choices=['present', 'absent'], default="present"), state=dict(required=False, choices=['present', 'absent'], default="present"),
enabled = dict(required=False, type='bool'), enabled=dict(required=False, type='bool'),
token = dict(required=False, no_log=True), token=dict(required=False, no_log=True),
url = dict(required=False, default="http://localhost:8080"), url=dict(required=False, default="http://localhost:8080"),
user = dict(required=False) user=dict(required=False)
), ),
mutually_exclusive = [ mutually_exclusive=[
['password', 'token'], ['password', 'token'],
['config', 'enabled'], ['config', 'enabled'],
], ],

@ -127,6 +127,7 @@ except ImportError:
# python3 # python3
from urllib.parse import urlencode from urllib.parse import urlencode
def is_csrf_protection_enabled(module): def is_csrf_protection_enabled(module):
resp, info = fetch_url(module, resp, info = fetch_url(module,
module.params['url'] + '/api/json', module.params['url'] + '/api/json',
@ -137,6 +138,7 @@ def is_csrf_protection_enabled(module):
content = resp.read() content = resp.read()
return json.loads(content).get('useCrumbs', False) return json.loads(content).get('useCrumbs', False)
def get_crumb(module): def get_crumb(module):
resp, info = fetch_url(module, resp, info = fetch_url(module,
module.params['url'] + '/crumbIssuer/api/json', module.params['url'] + '/crumbIssuer/api/json',
@ -147,20 +149,20 @@ def get_crumb(module):
content = resp.read() content = resp.read()
return json.loads(content) return json.loads(content)
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec=dict(
script = dict(required=True, type="str"), script=dict(required=True, type="str"),
url = dict(required=False, type="str", default="http://localhost:8080"), url=dict(required=False, type="str", default="http://localhost:8080"),
validate_certs = dict(required=False, type="bool", default=True), validate_certs=dict(required=False, type="bool", default=True),
user = dict(required=False, no_log=True, type="str",default=None), user=dict(required=False, no_log=True, type="str", default=None),
password = dict(required=False, no_log=True, type="str",default=None), password=dict(required=False, no_log=True, type="str", default=None),
args = dict(required=False, type="dict", default=None) args=dict(required=False, type="dict", default=None)
) )
) )
if module.params['user'] is not None: if module.params['user'] is not None:
if module.params['password'] is None: if module.params['password'] is None:
module.fail_json(msg="password required when user provided") module.fail_json(msg="password required when user provided")
@ -168,7 +170,6 @@ def main():
module.params['url_password'] = module.params['password'] module.params['url_password'] = module.params['password']
module.params['force_basic_auth'] = True module.params['force_basic_auth'] = True
if module.params['args'] is not None: if module.params['args'] is not None:
from string import Template from string import Template
script_contents = Template(module.params['script']).substitute(module.params['args']) script_contents = Template(module.params['script']).substitute(module.params['args'])
@ -183,7 +184,7 @@ def main():
resp, info = fetch_url(module, resp, info = fetch_url(module,
module.params['url'] + "/scriptText", module.params['url'] + "/scriptText",
data=urlencode({'script': script_contents}), data=urlencode({'script': script_contents}),
headers = headers, headers=headers,
method="POST") method="POST")
if info["status"] != 200: if info["status"] != 200:
@ -195,10 +196,9 @@ def main():
module.fail_json(msg="script failed with stacktrace:\n " + result) module.fail_json(msg="script failed with stacktrace:\n " + result)
module.exit_json( module.exit_json(
output = result, output=result,
) )
if __name__ == '__main__': if __name__ == '__main__':
main() main()

@ -781,8 +781,6 @@ lib/ansible/modules/web_infrastructure/django_manage.py
lib/ansible/modules/web_infrastructure/ejabberd_user.py lib/ansible/modules/web_infrastructure/ejabberd_user.py
lib/ansible/modules/web_infrastructure/htpasswd.py lib/ansible/modules/web_infrastructure/htpasswd.py
lib/ansible/modules/web_infrastructure/jboss.py lib/ansible/modules/web_infrastructure/jboss.py
lib/ansible/modules/web_infrastructure/jenkins_job.py
lib/ansible/modules/web_infrastructure/jenkins_script.py
lib/ansible/modules/web_infrastructure/jira.py lib/ansible/modules/web_infrastructure/jira.py
lib/ansible/modules/web_infrastructure/letsencrypt.py lib/ansible/modules/web_infrastructure/letsencrypt.py
lib/ansible/modules/windows/win_disk_image.py lib/ansible/modules/windows/win_disk_image.py

Loading…
Cancel
Save