def _get_arg_parser(self): description = textwrap.dedent(__doc__ + """ The location we will write to is: {} """.format(os.path.dirname(get_config_dir()))) description += mdt.shell_utils.get_citation_message() parser = argparse.ArgumentParser( description=description, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( '--pass-if-exists', dest='pass_if_exists', action='store_true', help="do nothing if the config dir exists (default)") parser.add_argument( '--always-overwrite', dest='pass_if_exists', action='store_false', help= "always overwrite the config directory with the default settings") parser.set_defaults(pass_if_exists=False) return parser
def _get_components_path(user_type, component_type): """ Args: user_type (str): either 'standard' or 'user' component_type (str): one of the dir names in standard and user """ from mdt.configuration import get_config_dir return os.path.join(get_config_dir(), 'components', user_type, component_type)
def _load_home_folder(): """Load the components from the MDT home folder. This first loads all components from the ``standard`` folder and next all those from the ``user`` folder. """ for user_type in ['standard', 'user']: base_path = os.path.join(get_config_dir(), 'components', user_type) for path, sub_dirs, files in os.walk(base_path): for file in files: if file.endswith('.py') and not file.startswith('__'): full_path = os.path.join(path, file) module_name = os.path.splitext(full_path[ len(os.path.join(get_config_dir(), 'components')):])[0] try: SourceFileLoader(module_name, full_path).load_module() except Exception as e: logger = logging.getLogger(__name__) logger.warning( 'Could not load the file "{}", exception: "{}".'. format(full_path, str(e)))
def _load_home_folder(): """Load the components from the MDT home folder. This first loads all components from the ``standard`` folder and next all those from the ``user`` folder. """ for user_type in ('standard', 'user'): for component_type in supported_component_types: path = os.path.join(get_config_dir(), 'components', user_type, component_type) for dir_name, sub_dirs, files in os.walk(path): for file in files: if file.endswith('.py') and not file.startswith('__'): path = os.path.join(dir_name, file) module_name = os.path.join( user_type, component_type, dir_name[len(path) + 1:], os.path.splitext(os.path.basename(path))[0]) imp.load_source(module_name, path)