mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 11:10:21 -07:00
Add some basic support for powershell modules
This commit is contained in:
parent
0386aa2643
commit
4f9b6899fe
1 changed files with 51 additions and 17 deletions
|
@ -10,6 +10,7 @@ import argparse
|
||||||
|
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
|
|
||||||
|
from ansible.module_common import REPLACER_WINDOWS
|
||||||
from ansible.utils.module_docs import get_docstring, BLACKLIST_MODULES
|
from ansible.utils.module_docs import get_docstring, BLACKLIST_MODULES
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,6 +84,11 @@ class ModuleValidator(Validator):
|
||||||
'command.py',
|
'command.py',
|
||||||
))
|
))
|
||||||
|
|
||||||
|
PS_DOC_BLACKLIST = frozenset((
|
||||||
|
'slurp.ps1',
|
||||||
|
'setup.ps1'
|
||||||
|
))
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
super(ModuleValidator, self).__init__()
|
super(ModuleValidator, self).__init__()
|
||||||
|
|
||||||
|
@ -121,7 +127,12 @@ class ModuleValidator(Validator):
|
||||||
def _is_bottom_import_blacklisted(self):
|
def _is_bottom_import_blacklisted(self):
|
||||||
return self.object_name in self.BOTTOM_IMPORTS_BLACKLIST
|
return self.object_name in self.BOTTOM_IMPORTS_BLACKLIST
|
||||||
|
|
||||||
def _check_interpreter(self):
|
def _check_interpreter(self, powershell=False):
|
||||||
|
if powershell:
|
||||||
|
if not self.text.startswith('#!powershell\n'):
|
||||||
|
self.errors.append('Interpreter line is not "#!powershell"')
|
||||||
|
return
|
||||||
|
|
||||||
if not self.text.startswith('#!/usr/bin/python'):
|
if not self.text.startswith('#!/usr/bin/python'):
|
||||||
self.errors.append('Interpreter line is not "#!/usr/bin/python"')
|
self.errors.append('Interpreter line is not "#!/usr/bin/python"')
|
||||||
|
|
||||||
|
@ -230,6 +241,20 @@ class ModuleValidator(Validator):
|
||||||
self.warnings.append('Found Try/Except block without HAS_ '
|
self.warnings.append('Found Try/Except block without HAS_ '
|
||||||
'assginment')
|
'assginment')
|
||||||
|
|
||||||
|
def _find_ps_replacers(self):
|
||||||
|
if 'WANT_JSON' not in self.text:
|
||||||
|
self.errors.append('WANT_JSON not found in module')
|
||||||
|
|
||||||
|
if REPLACER_WINDOWS not in self.text:
|
||||||
|
self.errors.append('"%s" not found in module' % REPLACER_WINDOWS)
|
||||||
|
|
||||||
|
def _find_ps_docs_py_file(self):
|
||||||
|
if self.object_name in self.PS_DOC_BLACKLIST:
|
||||||
|
return
|
||||||
|
py_path = self.path.replace('.ps1', '.py')
|
||||||
|
if not os.path.isfile(py_path):
|
||||||
|
self.errors.append('Missing python documentation file')
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
super(ModuleValidator, self).validate()
|
super(ModuleValidator, self).validate()
|
||||||
|
|
||||||
|
@ -241,18 +266,21 @@ class ModuleValidator(Validator):
|
||||||
if fnmatch(self.basename, pat):
|
if fnmatch(self.basename, pat):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._powershell_module():
|
# if self._powershell_module():
|
||||||
self.warnings.append('Cannot check powershell modules at this '
|
# self.warnings.append('Cannot check powershell modules at this '
|
||||||
'time. Skipping')
|
# 'time. Skipping')
|
||||||
return
|
# return
|
||||||
if not self._python_module():
|
if not self._python_module() and not self._powershell_module():
|
||||||
self.errors.append('Official Ansible modules must have a .py '
|
self.errors.append('Official Ansible modules must have a .py '
|
||||||
'extension')
|
'extension for python modules or a .ps1 '
|
||||||
|
'for powershell modules')
|
||||||
return
|
return
|
||||||
if self.ast is None:
|
|
||||||
|
if self._python_module() and self.ast is None:
|
||||||
self.errors.append('Python SyntaxError while parsing module')
|
self.errors.append('Python SyntaxError while parsing module')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if self._python_module():
|
||||||
doc, examples, ret = get_docstring(self.path)
|
doc, examples, ret = get_docstring(self.path)
|
||||||
if not bool(doc):
|
if not bool(doc):
|
||||||
self.errors.append('Invalid or no DOCUMENTATION provided')
|
self.errors.append('Invalid or no DOCUMENTATION provided')
|
||||||
|
@ -261,15 +289,21 @@ class ModuleValidator(Validator):
|
||||||
if not bool(ret):
|
if not bool(ret):
|
||||||
self.warnings.append('No RETURN provided')
|
self.warnings.append('No RETURN provided')
|
||||||
|
|
||||||
if not self._just_docs():
|
if self._python_module() and not self._just_docs():
|
||||||
self._check_interpreter()
|
self._check_interpreter()
|
||||||
self._check_for_sys_exit()
|
self._check_for_sys_exit()
|
||||||
self._check_for_gpl3_header()
|
|
||||||
self._find_json_import()
|
self._find_json_import()
|
||||||
main = self._find_main_call()
|
main = self._find_main_call()
|
||||||
self._find_module_utils(main)
|
self._find_module_utils(main)
|
||||||
self._find_has_import()
|
self._find_has_import()
|
||||||
|
|
||||||
|
if self._powershell_module():
|
||||||
|
self._find_ps_replacers()
|
||||||
|
self._find_ps_docs_py_file()
|
||||||
|
|
||||||
|
self._check_for_gpl3_header()
|
||||||
|
self._check_interpreter(powershell=self._powershell_module())
|
||||||
|
|
||||||
|
|
||||||
class PythonPackageValidator(Validator):
|
class PythonPackageValidator(Validator):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue