def handle_args(self, args): # No messages to stderr, but do collect the E_APP_MISSING and # E_FUNC_MISSING errors. aggregator = Aggregator() MessageDefManager.muted = True # Load func_odbc functions if requested. load_func_odbc_functions(args.func_odbc, args.dialplan) parser = FileDialplanParser() parser.include(args.dialplan) dialplan = next(iter(parser)) del dialplan apploader = AppLoader() funcloader = FuncLoader() self.print_modules_used(apploader, funcloader) self.print_load_statements( set(apploader.used_modules) | set(funcloader.used_modules)) self.print_unknowns(aggregator) return int( bool(aggregator.unknown_apps) or bool(aggregator.unknown_funcs))
def main(args, envs): parser = argparse.ArgumentParser( description=( 'Do sanity checks on dialplan. Suppress comma separated ' 'error classes through the ALINT_IGNORE environment variable. ' 'Returns 1 if any issue was reported.')) parser.add_argument( 'dialplan', metavar='EXTENSIONS_CONF', nargs='?', default='./extensions.conf', help='path to extensions.conf') parser.add_argument( '--func-odbc', metavar='FUNC_ODBC_CONF', action=UniqueStore, help="path to func_odbc.conf, will be read automatically if found " "in same the same dir as extensions.conf; set empty to disable") args = parser.parse_args(args) # Load func_odbc functions if requested. load_func_odbc_functions(args.func_odbc, args.dialplan) parser = FileDialplanParser() parser.include(args.dialplan) dialplan = next(iter(parser)) dialplan.walk_jump_destinations() del dialplan # MessageDefManager.raised is a dict of messages ordered by message # type. All message types share the same muted flag, so we need only # examine the first. if any(not i[0].muted for i in MessageDefManager.raised.values()): return 1
def handle_args(self, args): # Load func_odbc functions if requested. load_func_odbc_functions(args.func_odbc, args.dialplan) parser = FileDialplanParser() parser.include(args.dialplan) dialplan = next(iter(parser)) dialplan.walk_jump_destinations() del dialplan # MessageDefManager.raised is a dict of messages ordered by message # type. All message types share the same muted flag, so we need only # examine the first. if any(not i[0].muted for i in MessageDefManager.raised.values()): return 1
def main(args, envs): parser = argparse.ArgumentParser( description=( "Show which modules, apps and functions are used by the dialplan. " "Useful when you use autoload=no in your modules.conf. Beware " "that you do need more modules than just these listed.")) parser.add_argument( 'dialplan', metavar='EXTENSIONS_CONF', nargs='?', default='./extensions.conf', help='path to extensions.conf') parser.add_argument( '--func-odbc', metavar='FUNC_ODBC_CONF', action=UniqueStore, help="path to func_odbc.conf, will be read automatically if found " "in same the same dir as extensions.conf; set empty to disable") args = parser.parse_args(args) # No messages to stderr, but do collect the E_APP_MISSING and # E_FUNC_MISSING errors. aggregator = Aggregator() MessageDefManager.muted = True # Load func_odbc functions if requested. load_func_odbc_functions(args.func_odbc, args.dialplan) parser = FileDialplanParser() parser.include(args.dialplan) dialplan = next(iter(parser)) del dialplan apploader = AppLoader() funcloader = FuncLoader() all_modules = set() for what, used_items, used_modules in ( ('Application', apploader.used_apps, apploader.used_modules), ('Function', funcloader.used_funcs, funcloader.used_modules)): all_modules.update(used_modules) used_items_per_module = defaultdict(list) for item in used_items: used_items_per_module[item.module].append(item) print('; {} providing modules used:'.format(what)) for module in used_modules: items = used_items_per_module[module][:] item_lines = [''] while items: next_ = items.pop(0) if item_lines[-1]: item_lines[-1] += ', ' formatted = '{}()'.format(next_.name) if len(item_lines[-1]) + len(formatted) > 52: item_lines.append(formatted) else: item_lines[-1] += formatted # Output. print('; {:20s} {}'.format( module, item_lines[0].strip())) for item_line in item_lines[1:]: print('; {:20s} {}'.format( '', item_line.strip())) print(';') print('; modules.conf') for module in sorted(all_modules): if module != '<builtin>': print('load => {}.so'.format(module)) print() if aggregator.unknown_apps: print('; WARNING: The following unknown applications were seen:') print('; {}'.format(', '.join(sorted(aggregator.unknown_apps)))) print(';') if aggregator.unknown_funcs: print('; WARNING: The following unknown functions were seen:') print('; {}'.format(', '.join(sorted(aggregator.unknown_funcs)))) print(';') return int(bool(aggregator.unknown_apps) or bool(aggregator.unknown_funcs))