def import_commands(nm_dir): import glob, imp sysdir = nm_dir + "/commands" sys.path.append(sysdir) loaded_modules = [] # First load modules in our current directory, for developers, and then # out of the system dir. files = glob.glob("*cmds.py") files = files + glob.glob("%s/*cmds.py" % sysdir) for file in files: (path, name) = os.path.split(file) (name, ext) = os.path.splitext(name) if name in loaded_modules: continue (file, filename, data) = imp.find_module(name, [path]) try: module = imp.load_module(name, file, filename, data) except ImportError: nmtalk.warning("Can't import module " + filename) else: loaded_modules.append(name) if file: file.close()
def extract_command_from_argv(argv): command = None i = 0 unknown_commands = [] while i < len(argv) and not command: if argv[i][0] != "-": command = construct(argv[i]) if command: argv.pop(i) else: unknown_commands.append(argv[i]) else: takes_arg = 0 for o in default_opt_table: if not (argv[i][1:] == o[0] or argv[i][2:] == o[1]): continue if o[2] != "": takes_arg = 1 break if takes_arg and string.find(argv[i], "=") == -1: i = i + 1 i = i + 1 if not command: map(lambda x:nmtalk.warning("Unknown command '%s'" % x), unknown_commands) nmtalk.warning("No command found on command line.") if "--help" in argv or "-?" in argv: usage_full() else: usage_basic() sys.exit(1) return command