def _LoadHelpMaps(self): """Returns tuple (help type -> [HelpProviders], help name->HelpProvider dict, ).""" # Walk gslib/commands and gslib/addlhelp to find all HelpProviders. for f in os.listdir(os.path.join(gslib.GSLIB_DIR, 'commands')): # Handles no-extension files, etc. (module_name, ext) = os.path.splitext(f) if ext == '.py': __import__('gslib.commands.%s' % module_name) for f in os.listdir(os.path.join(gslib.GSLIB_DIR, 'addlhelp')): (module_name, ext) = os.path.splitext(f) if ext == '.py': __import__('gslib.addlhelp.%s' % module_name) help_type_map = {} help_name_map = {} for s in gslib.help_provider.ALL_HELP_TYPES: help_type_map[s] = [] # Only include HelpProvider subclasses in the dict. for help_prov in itertools.chain( HelpProvider.__subclasses__(), Command.__subclasses__()): if help_prov is Command: # Skip the Command base class itself; we just want its subclasses, # where the help command text lives (in addition to non-Command # HelpProviders, like naming.py). continue gslib.help_provider.SanityCheck(help_prov, help_name_map) help_name_map[help_prov.help_spec[HELP_NAME]] = help_prov for help_name_aliases in help_prov.help_spec[HELP_NAME_ALIASES]: help_name_map[help_name_aliases] = help_prov help_type_map[help_prov.help_spec[HELP_TYPE]].append(help_prov) return (help_type_map, help_name_map)
def _LoadHelpMaps(self): """Returns tuple (help type -> [HelpProviders], help name->HelpProvider dict, ).""" # Import all gslib.commands submodules. for _, module_name, _ in pkgutil.iter_modules(gslib.commands.__path__): __import__('gslib.commands.%s' % module_name) # Import all gslib.addlhelp submodules. for _, module_name, _ in pkgutil.iter_modules(gslib.addlhelp.__path__): __import__('gslib.addlhelp.%s' % module_name) help_type_map = {} help_name_map = {} for s in gslib.help_provider.ALL_HELP_TYPES: help_type_map[s] = [] # Only include HelpProvider subclasses in the dict. for help_prov in itertools.chain( HelpProvider.__subclasses__(), Command.__subclasses__()): if help_prov is Command: # Skip the Command base class itself; we just want its subclasses, # where the help command text lives (in addition to non-Command # HelpProviders, like naming.py). continue gslib.help_provider.SanityCheck(help_prov, help_name_map) help_name_map[help_prov.help_spec[HELP_NAME]] = help_prov for help_name_aliases in help_prov.help_spec[HELP_NAME_ALIASES]: help_name_map[help_name_aliases] = help_prov help_type_map[help_prov.help_spec[HELP_TYPE]].append(help_prov) return (help_type_map, help_name_map)
def _LoadCommandMap(self): """Returns dict mapping each command_name to implementing class.""" # Import all gslib.commands submodules. for _, module_name, _ in pkgutil.iter_modules(gslib.commands.__path__): __import__('gslib.commands.%s' % module_name) command_map = {} # Only include Command subclasses in the dict. for command in Command.__subclasses__(): command_map[command.command_spec.command_name] = command for command_name_aliases in command.command_spec.command_name_aliases: command_map[command_name_aliases] = command return command_map
def _LoadCommandMap(self): """Returns dict mapping each command_name to implementing class.""" # Walk gslib/commands and find all commands. commands_dir = os.path.join(self.gsutil_bin_dir, 'gslib', 'commands') for f in os.listdir(commands_dir): # Handles no-extension files, etc. (module_name, ext) = os.path.splitext(f) if ext == '.py': __import__('gslib.commands.%s' % module_name) command_map = {} # Only include Command subclasses in the dict. for command in Command.__subclasses__(): command_map[command.command_spec[COMMAND_NAME]] = command for command_name_aliases in command.command_spec[COMMAND_NAME_ALIASES]: command_map[command_name_aliases] = command return command_map
def _LoadCommandMap(self): """Returns dict mapping each command_name to implementing class.""" # Walk gslib/commands and find all commands. commands_dir = os.path.join(self.gsutil_bin_dir, 'gslib', 'commands') for f in os.listdir(commands_dir): # Handles no-extension files, etc. (module_name, ext) = os.path.splitext(f) if ext == '.py': __import__('gslib.commands.%s' % module_name) command_map = {} # Only include Command subclasses in the dict. for command in Command.__subclasses__(): command_map[command.command_spec[COMMAND_NAME]] = command for command_name_aliases in command.command_spec[ COMMAND_NAME_ALIASES]: command_map[command_name_aliases] = command return command_map
def _LoadHelpMaps(self): """Returns tuple of help type and help name. help type is a dict with key: help type value: list of HelpProviders help name is a dict with key: help command name or alias value: HelpProvider Returns: (help type, help name) """ # Import all gslib.commands submodules. for _, module_name, _ in pkgutil.iter_modules(gslib.commands.__path__): __import__('gslib.commands.%s' % module_name) # Import all gslib.addlhelp submodules. for _, module_name, _ in pkgutil.iter_modules(gslib.addlhelp.__path__): __import__('gslib.addlhelp.%s' % module_name) help_type_map = {} help_name_map = {} for s in gslib.help_provider.ALL_HELP_TYPES: help_type_map[s] = [] # Only include HelpProvider subclasses in the dict. for help_prov in itertools.chain(HelpProvider.__subclasses__(), Command.__subclasses__()): if help_prov is Command: # Skip the Command base class itself; we just want its subclasses, # where the help command text lives (in addition to non-Command # HelpProviders, like naming.py). continue gslib.help_provider.SanityCheck(help_prov, help_name_map) help_name_map[help_prov.help_spec.help_name] = help_prov for help_name_aliases in help_prov.help_spec.help_name_aliases: help_name_map[help_name_aliases] = help_prov help_type_map[help_prov.help_spec.help_type].append(help_prov) return (help_type_map, help_name_map)
def _LoadHelpMaps(self): """Returns tuple of help type and help name. help type is a dict with key: help type value: list of HelpProviders help name is a dict with key: help command name or alias value: HelpProvider Returns: (help type, help name) """ # Import all gslib.commands submodules. for _, module_name, _ in pkgutil.iter_modules(gslib.commands.__path__): __import__('gslib.commands.%s' % module_name) # Import all gslib.addlhelp submodules. for _, module_name, _ in pkgutil.iter_modules(gslib.addlhelp.__path__): __import__('gslib.addlhelp.%s' % module_name) help_type_map = {} help_name_map = {} for s in gslib.help_provider.ALL_HELP_TYPES: help_type_map[s] = [] # Only include HelpProvider subclasses in the dict. for help_prov in itertools.chain( HelpProvider.__subclasses__(), Command.__subclasses__()): if help_prov is Command: # Skip the Command base class itself; we just want its subclasses, # where the help command text lives (in addition to non-Command # HelpProviders, like naming.py). continue gslib.help_provider.SanityCheck(help_prov, help_name_map) help_name_map[help_prov.help_spec.help_name] = help_prov for help_name_aliases in help_prov.help_spec.help_name_aliases: help_name_map[help_name_aliases] = help_prov help_type_map[help_prov.help_spec.help_type].append(help_prov) return (help_type_map, help_name_map)