def get_help_files(): import os result = [] result.append((1, 'OSPy')) result.append((2, 'Readme', 'README.md')) for doc in help_files_in_directory(os.path.join('ospy', 'docs')): result.append((2, doc[0], doc[1])) result.append((1, 'API')) result.append((2, 'Readme', os.path.join('api', 'README.md'))) for doc in help_files_in_directory(os.path.join('api', 'docs')): result.append((2, doc[0], doc[1])) result.append((1, 'Plug-ins')) result.append((2, 'Readme', os.path.join('plugins', 'README.md'))) from plugins import plugin_names, plugin_dir, plugin_docs_dir for module, name in plugin_names().iteritems(): readme_file = os.path.join(os.path.relpath(plugin_dir(module)), 'README.md') readme_exists = os.path.isfile(readme_file) docs = help_files_in_directory(plugin_docs_dir(module)) if readme_exists or docs: if readme_exists: result.append((2, name, readme_file)) else: result.append((2, name)) for doc in docs: result.append((3, doc[0], doc[1])) return result
def main(): if '-h' in sys.argv: print(USAGE) return try: plugin = sys.argv[1] path = sys.argv[2] args = sys.argv[3:] except IndexError: output_and_exit('Insufficient arguments supplied.\n{}\n'.format(USAGE)) if plugin not in plugins.plugin_names(): output_and_exit('{} not an available plugin.\n{}\n'.format(plugin, USAGE)) env = os.environ ret = plugins.process(plugin, path, args, env) if ret: print(ret)
def process(plugin, args, _e): if plugin not in plugins.plugin_names(): return "{} plugin not found.".format(plugin) else: return plugins.available_plugins[plugin].__doc__
def output_and_exit(msg): sys.stderr.write(msg) sys.exit(1) try: import plugins except ImportError: output_and_exit('Cannot find any plugins\n') USAGE = """\ Usage: {0} plugin path [args] Calls on plugin to process path with optional [args]. Type '{0} help plugin' for more info. Available plugins: {1}\ """.format("courier.py", ' '.join(plugins.plugin_names())) def main(): if '-h' in sys.argv: print(USAGE) return try: plugin = sys.argv[1] path = sys.argv[2] args = sys.argv[3:] except IndexError: output_and_exit('Insufficient arguments supplied.\n{}\n'.format(USAGE)) if plugin not in plugins.plugin_names(): output_and_exit('{} not an available plugin.\n{}\n'.format(plugin, USAGE)) env = os.environ ret = plugins.process(plugin, path, args, env)