def find_modules(): plugins = set() paths = module_loader._get_paths() for path in paths: if not os.path.exists(path): continue for plugin in os.listdir(path): full_path = '/'.join([path, plugin]) if plugin.startswith('.'): continue elif os.path.isdir(full_path): continue elif any(plugin.endswith(x) for x in C.BLACKLIST_EXTS): continue elif plugin.startswith('__'): continue elif plugin in C.IGNORE_FILES: continue elif plugin .startswith('_'): if os.path.islink(full_path): # avoids aliases continue plugin = os.path.splitext(plugin)[0] # removes the extension plugin = plugin.lstrip('_') # remove underscore from deprecated plugins if plugin not in plugin_docs.BLACKLIST.get("MODULE", ()): plugins.add(plugin) return [module_loader.find_plugin(p, mod_type='.py', ignore_deprecated=True) for p in plugins]
def _list_all_modules(): modules = set() module_paths = module_loader._get_paths() for path in module_paths: if path is not None: modules.update(_find_modules_in_path(path)) return modules
def list_modules(self): modules = set() if self.options.module_path is not None: for i in self.options.module_path.split(os.pathsep): module_loader.add_directory(i) module_paths = module_loader._get_paths() for path in module_paths: if path is not None: modules.update(self._find_modules_in_path(path)) return modules
def list_ansible_modules(): # inspired by # https://github.com/ansible/ansible/blob/devel/bin/ansible-doc paths = (p for p in module_loader._get_paths() if os.path.isdir(p)) modules = set() for path in paths: modules.update(m for m in get_modules_from_path(path)) return modules
def main(): doc_cli = DocCLI([]) module_paths = module_loader._get_paths() module_keys = ('module', 'short_description', 'options', 'deprecated') for path in module_paths: doc_cli.find_modules(path) result = { 'modules': [], 'directives': defaultdict(list), 'lookup_plugins': [], } for module in sorted(set(doc_cli.module_list)): if module in module_docs.BLACKLIST_MODULES: continue filename = module_loader.find_plugin(module, mod_type='.py') if not filename: continue if filename.endswith('.ps1'): continue if os.path.isdir(filename): continue try: doc, plain_examples, return_docs = module_docs.get_docstring(filename) filtered_doc = {key: doc.get(key) for key in module_keys} result['modules'].append(filtered_doc) except Exception: pass for aclass in (Play, Role, Block, Task): aobj = aclass() name = aclass.__name__ for attr in aobj.__dict__['_attributes']: if 'private' in attr and attr.private: continue direct_target = result['directives'][attr] direct_target.append(name) if attr == 'action': local_action = result['directives']['local_action'] local_action.append(name) result['directives']['with_'] = ['Task'] for lookup in lookup_loader.all(): name = os.path.splitext(os.path.basename(lookup._original_path))[0] result['lookup_plugins'].append(name) fn = os.path.join(__path__, '../data/ansible-data.json') with codecs.open(fn, 'wb', encoding='utf-8') as f: json.dump(result, f, ensure_ascii=False, indent=2)
def main(): doc_cli = DocCLI([]) module_paths = module_loader._get_paths() module_keys = ('module', 'short_description', 'options', 'deprecated') for path in module_paths: doc_cli.find_modules(path) result = {'modules': [], 'directives': {}, 'lookup_plugins':[]} for module in sorted(set(doc_cli.module_list)): if module in module_docs.BLACKLIST_MODULES: continue filename = module_loader.find_plugin(module, mod_type='.py') if filename is None: continue if filename.endswith(".ps1"): continue if os.path.isdir(filename): continue try: doc, plainexamples, returndocs = module_docs.get_docstring(filename) filtered_doc = {key: doc.get(key, None) for key in module_keys} result['modules'].append(filtered_doc) except: pass for aclass in (Play, Role, Block, Task): aobj = aclass() name = type(aobj).__name__ for attr in aobj.__dict__['_attributes']: if 'private' in attr and attr.private: continue direct_target = result['directives'].setdefault(attr, []) direct_target.append(name) if attr == 'action': local_action = result['directives'].setdefault('local_action', []) local_action.append(name) result['directives']['with_'] = ['Task'] for lookup in lookup_loader.all(): name = os.path.splitext(os.path.basename(lookup._original_path))[0] result['lookup_plugins'].append(name) print(json.dumps(result))
def run(self): super(DocCLI, self).run() if self.options.module_path is not None: for i in self.options.module_path.split(os.pathsep): module_loader.add_directory(i) # list modules if self.options.list_dir: paths = module_loader._get_paths() for path in paths: self.find_modules(path) self.pager(self.get_module_list_text()) return 0 if len(self.args) == 0: raise AnsibleOptionsError("Incorrect options passed") # process command line module list text = '' for module in self.args: try: filename = module_loader.find_plugin(module) if filename is None: self.display.warning( "module %s not found in %s\n" % (module, DocCLI.print_paths(module_loader))) continue if any(filename.endswith(x) for x in self.BLACKLIST_EXTS): continue try: doc, plainexamples, returndocs = module_docs.get_docstring( filename, verbose=(self.options.verbosity > 0)) except: self.display.vvv(traceback.print_exc()) self.display.error( "module %s has a documentation error formatting or is missing documentation\nTo see exact traceback use -vvv" % module) continue if doc is not None: all_keys = [] for (k, v) in iteritems(doc['options']): all_keys.append(k) all_keys = sorted(all_keys) doc['option_keys'] = all_keys doc['filename'] = filename doc['docuri'] = doc['module'].replace('_', '-') doc['now_date'] = datetime.date.today().strftime( '%Y-%m-%d') doc['plainexamples'] = plainexamples doc['returndocs'] = returndocs if self.options.show_snippet: text += DocCLI.get_snippet_text(doc) else: text += DocCLI.get_man_text(doc) else: # this typically means we couldn't even parse the docstring, not just that the YAML is busted, # probably a quoting issue. raise AnsibleError("Parsing produced an empty object.") except Exception as e: self.display.vvv(traceback.print_exc()) raise AnsibleError( "module %s missing documentation (or could not parse documentation): %s\n" % (module, str(e))) self.pager(text) return 0
def run(self): if self.options.module_path is not None: for i in self.options.module_path.split(os.pathsep): module_loader.add_directory(i) # list modules if self.options.list_dir: paths = module_loader._get_paths() for path in paths: self.find_modules(path) CLI.pager(self.get_module_list_text()) return 0 if len(self.args) == 0: raise AnsibleOptionsError("Incorrect options passed") # process command line module list text = '' for module in self.args: filename = module_loader.find_plugin(module) if filename is None: self.display.warning("module %s not found in %s\n" % (module, DocCLI.print_paths(module_loader))) continue if any(filename.endswith(x) for x in self.BLACKLIST_EXTS): continue try: doc, plainexamples, returndocs = module_docs.get_docstring(filename) except: self.display.vvv(traceback.print_exc()) self.display.error("module %s has a documentation error formatting or is missing documentation\nTo see exact traceback use -vvv" % module) continue if doc is not None: all_keys = [] for (k,v) in doc['options'].iteritems(): all_keys.append(k) all_keys = sorted(all_keys) doc['option_keys'] = all_keys doc['filename'] = filename doc['docuri'] = doc['module'].replace('_', '-') doc['now_date'] = datetime.date.today().strftime('%Y-%m-%d') doc['plainexamples'] = plainexamples doc['returndocs'] = returndocs if self.options.show_snippet: text += DocCLI.get_snippet_text(doc) else: text += DocCLI.get_man_text(doc) else: # this typically means we couldn't even parse the docstring, not just that the YAML is busted, # probably a quoting issue. self.display.warning("module %s missing documentation (or could not parse documentation)\n" % module) CLI.pager(text) return 0
def run(self): super(DocCLI, self).run() if self.options.module_path is not None: for i in self.options.module_path.split(os.pathsep): module_loader.add_directory(i) # list modules if self.options.list_dir: paths = module_loader._get_paths() for path in paths: self.find_modules(path) self.pager(self.get_module_list_text()) return 0 if len(self.args) == 0: raise AnsibleOptionsError("Incorrect options passed") # process command line module list text = '' for module in self.args: try: # if the module lives in a non-python file (eg, win_X.ps1), require the corresponding python file for docs filename = module_loader.find_plugin(module, mod_type='.py') if filename is None: display.warning("module %s not found in %s\n" % (module, DocCLI.print_paths(module_loader))) continue if any(filename.endswith(x) for x in C.BLACKLIST_EXTS): continue try: doc, plainexamples, returndocs = module_docs.get_docstring(filename, verbose=(self.options.verbosity > 0)) except: display.vvv(traceback.print_exc()) display.error("module %s has a documentation error formatting or is missing documentation\nTo see exact traceback use -vvv" % module) continue if doc is not None: # is there corresponding action plugin? if module in action_loader: doc['action'] = True else: doc['action'] = False all_keys = [] for (k,v) in iteritems(doc['options']): all_keys.append(k) all_keys = sorted(all_keys) doc['option_keys'] = all_keys doc['filename'] = filename doc['docuri'] = doc['module'].replace('_', '-') doc['now_date'] = datetime.date.today().strftime('%Y-%m-%d') doc['plainexamples'] = plainexamples doc['returndocs'] = returndocs if self.options.show_snippet: text += self.get_snippet_text(doc) else: text += self.get_man_text(doc) else: # this typically means we couldn't even parse the docstring, not just that the YAML is busted, # probably a quoting issue. raise AnsibleError("Parsing produced an empty object.") except Exception as e: display.vvv(traceback.print_exc()) raise AnsibleError("module %s missing documentation (or could not parse documentation): %s\n" % (module, str(e))) if text: self.pager(text) return 0
def run(self): super(DocCLI, self).run() if self.options.module_path is not None: for i in self.options.module_path.split(os.pathsep): module_loader.add_directory(i) # list modules if self.options.list_dir: paths = module_loader._get_paths() for path in paths: self.find_modules(path) self.pager(self.get_module_list_text()) return 0 # process all modules if self.options.all_modules: paths = module_loader._get_paths() for path in paths: self.find_modules(path) self.args = sorted( set(self.module_list) - module_docs.BLACKLIST_MODULES) if len(self.args) == 0: raise AnsibleOptionsError("Incorrect options passed") # process command line module list text = '' for module in self.args: try: # if the module lives in a non-python file (eg, win_X.ps1), require the corresponding python file for docs filename = module_loader.find_plugin(module, mod_type='.py', ignore_deprecated=True) if filename is None: display.warning( "module %s not found in %s\n" % (module, DocCLI.print_paths(module_loader))) continue if any(filename.endswith(x) for x in C.BLACKLIST_EXTS): continue try: doc, plainexamples, returndocs, metadata = module_docs.get_docstring( filename, verbose=(self.options.verbosity > 0)) except: display.vvv(traceback.format_exc()) display.error( "module %s has a documentation error formatting or is missing documentation\nTo see exact traceback use -vvv" % module) continue if doc is not None: # is there corresponding action plugin? if module in action_loader: doc['action'] = True else: doc['action'] = False all_keys = [] for (k, v) in iteritems(doc['options']): all_keys.append(k) all_keys = sorted(all_keys) doc['option_keys'] = all_keys doc['filename'] = filename doc['docuri'] = doc['module'].replace('_', '-') doc['now_date'] = datetime.date.today().strftime( '%Y-%m-%d') doc['plainexamples'] = plainexamples doc['returndocs'] = returndocs doc['metadata'] = metadata if 'metadata_version' in doc['metadata']: del doc['metadata']['metadata_version'] if 'version' in doc['metadata']: del doc['metadata']['metadata_version'] if self.options.show_snippet: text += self.get_snippet_text(doc) else: text += self.get_man_text(doc) else: # this typically means we couldn't even parse the docstring, not just that the YAML is busted, # probably a quoting issue. raise AnsibleError("Parsing produced an empty object.") except Exception as e: display.vvv(traceback.format_exc()) raise AnsibleError( "module %s missing documentation (or could not parse documentation): %s\n" % (module, str(e))) if text: self.pager(text) return 0