def oldstyle_read_configuration(filename): """ Read variables from the config file """ _log.deprecated("oldstyle_read_configuration filename %s" % filename, "2.0") file_variables = get_repositories(check_usable=False) try: execfile(filename, {}, file_variables) except (IOError, SyntaxError), err: _log.exception("Failed to read config file %s %s" % (filename, err))
def init(options, config_options_dict): """ Gather all variables and check if they're valid Variables are read in this order of preference: generaloption > legacy environment > legacy config file """ if SUPPORT_OLDSTYLE: _log.deprecated( 'oldstyle init with modifications to support oldstyle options', '2.0') oldstyle_init(options.config) # add the DEFAULT_MODULECLASSES as default (behavior is now that this extends the defautl list) variables['moduleclasses'] = nub( list(variables.get('moduleclasses', [])) + [x[0] for x in DEFAULT_MODULECLASSES]) # all defaults are now set in generaloption # distinguish between default generaloption values and values actually passed by generaloption for dest in config_options_dict.keys(): if not options._action_taken.get(dest, False): if dest == 'installpath' and options.pretend: # the installpath has been set by pretend option in postprocess continue # remove the default options if they are set in variables # this way, all defaults are set if dest in variables: _log.debug("Oldstyle support: no action for dest %s." % dest) del config_options_dict[dest] # update the variables with the generaloption values _log.debug("Updating config variables with generaloption dict %s" % config_options_dict) variables.update(config_options_dict) _log.debug("Config variables: %s" % variables) # Create an instance of the repository class if 'repository' in variables and not isinstance(variables['repository'], Repository): repo = get_repositories().get(options.repository) repoargs = options.repositorypath try: repository = repo(*repoargs) except Exception, err: _log.error( 'Failed to create a repository instance for %s (class %s) with args %s (msg: %s)' % (options.repository, repo.__name__, repoargs, err)) variables['repository'] = repository
def avail_repositories(self): """Show list of known repository types.""" repopath_defaults = get_default_oldstyle_configfile_defaults()["repositorypath"] all_repos = get_repositories(check_usable=False) usable_repos = get_repositories(check_usable=True).keys() indent = " " * 2 txt = ["All avaialble repository types"] repos = sorted(all_repos.keys()) for repo in repos: if repo in usable_repos: missing = "" else: missing = " (*Not usable*, something is missing (eg a specific module))" if repo in repopath_defaults: default = " (Default arguments: %s)" % (repopath_defaults[repo]) else: default = " (No default arguments)" txt.append("%s%s%s%s" % (indent, repo, default, missing)) txt.append("%s%s" % (indent * 2, all_repos[repo].DESCRIPTION)) return "\n".join(txt)
def avail_repositories(self): """Show list of known repository types.""" repopath_defaults = get_default_oldstyle_configfile_defaults()['repositorypath'] all_repos = get_repositories(check_usable=False) usable_repos = get_repositories(check_usable=True).keys() indent = ' ' * 2 txt = ['All avaialble repository types'] repos = sorted(all_repos.keys()) for repo in repos: if repo in usable_repos: missing = '' else: missing = ' (*Not usable*, something is missing (eg a specific module))' if repo in repopath_defaults: default = ' (Default arguments: %s)' % (repopath_defaults[repo]) else: default = ' (No default arguments)' txt.append("%s%s%s%s" % (indent, repo, default, missing)) txt.append("%s%s" % (indent * 2, all_repos[repo].DESCRIPTION)) return "\n".join(txt)
def config_options(self): # config options descr = ("Configuration options", "Configure EasyBuild behavior.") oldstyle_defaults = get_default_oldstyle_configfile_defaults() opts = { "config":("Path to EasyBuild config file", None, 'store', oldstyle_defaults['config'], "C",), 'prefix': (('Change prefix for buildpath, installpath, sourcepath and repositorypath ' '(repositorypath prefix is only relevant in case of FileRepository repository)' '(used prefix for defaults %s)' % oldstyle_defaults['prefix']), None, 'store', None), 'buildpath': ('Temporary build path', None, 'store', oldstyle_defaults['buildpath']), 'installpath': ('Final install path', None, 'store', oldstyle_defaults['installpath']), 'subdir-modules': ('Subdir in installpath for modules', None, 'store', oldstyle_defaults['subdir_modules']), 'subdir-software': ('Subdir in installpath for software', None, 'store', oldstyle_defaults['subdir_software']), 'repository': ('Repository type, using repositorypath', 'choice', 'store', oldstyle_defaults['repository'], sorted(get_repositories().keys())), 'repositorypath': (('Repository path, used by repository ' '(is passed as list of arguments to create the repository instance). ' 'For more info, use --avail-repositories.'), 'strlist', 'store', oldstyle_defaults['repositorypath'][oldstyle_defaults['repository']]), "avail-repositories":(("Show all repository types (incl. non-usable)"), None, "store_true", False,), 'logfile-format': ('Directory name and format of the log file ', 'strtuple', 'store', oldstyle_defaults['logfile_format'], {'metavar': 'DIR,FORMAT'}), 'tmp-logdir': ('Log directory where temporary log files are stored', None, 'store', oldstyle_defaults['tmp_logdir']), 'sourcepath': ('Path to where sources should be downloaded', None, 'store', oldstyle_defaults['sourcepath']), 'moduleclasses': (('Extend supported module classes' ' (For more info on the default classes, use --show-default-moduleclasses)'), None, 'extend', oldstyle_defaults['moduleclasses']), 'show-default-moduleclasses': ('Show default module classes with description', None, 'store_true', False), # this one is sort of an exception, it's something jobscripts can set, # has no real meaning for regular eb usage "testoutput": ("Path to where a job should place the output (to be set within jobscript)", None, "store", None), } self.log.debug("config_options: descr %s opts %s" % (descr, opts)) self.add_group_parser(opts, descr)
def init(options, config_options_dict): """ Gather all variables and check if they're valid Variables are read in this order of preference: generaloption > legacy environment > legacy config file """ if SUPPORT_OLDSTYLE: _log.deprecated('oldstyle init with modifications to support oldstyle options', '2.0') oldstyle_init(options.config) # add the DEFAULT_MODULECLASSES as default (behavior is now that this extends the defautl list) variables['moduleclasses'] = nub(list(variables.get('moduleclasses', [])) + [x[0] for x in DEFAULT_MODULECLASSES]) # all defaults are now set in generaloption # distinguish between default generaloption values and values actually passed by generaloption for dest in config_options_dict.keys(): if not options._action_taken.get(dest, False): if dest == 'installpath' and options.pretend: # the installpath has been set by pretend option in postprocess continue # remove the default options if they are set in variables # this way, all defaults are set if dest in variables: _log.debug("Oldstyle support: no action for dest %s." % dest) del config_options_dict[dest] # update the variables with the generaloption values _log.debug("Updating config variables with generaloption dict %s" % config_options_dict) variables.update(config_options_dict) _log.debug("Config variables: %s" % variables) # Create an instance of the repository class if 'repository' in variables and not isinstance(variables['repository'], Repository): repo = get_repositories().get(options.repository) repoargs = options.repositorypath try: repository = repo(*repoargs) except Exception, err: _log.error('Failed to create a repository instance for %s (class %s) with args %s (msg: %s)' % (options.repository, repo.__name__, repoargs, err)) variables['repository'] = repository
def config_options(self): # config options descr = ("Configuration options", "Configure EasyBuild behavior.") oldstyle_defaults = get_default_oldstyle_configfile_defaults() opts = { "config": ("Path to EasyBuild config file", None, "store", oldstyle_defaults["config"], "C"), "prefix": ( ( "Change prefix for buildpath, installpath, sourcepath and repositorypath " "(repositorypath prefix is only relevant in case of FileRepository repository)" "(used prefix for defaults %s)" % oldstyle_defaults["prefix"] ), None, "store", None, ), "buildpath": ("Temporary build path", None, "store", oldstyle_defaults["buildpath"]), "installpath": ("Final install path", None, "store", oldstyle_defaults["installpath"]), "subdir-modules": ("Subdir in installpath for modules", None, "store", oldstyle_defaults["subdir_modules"]), "subdir-software": ( "Subdir in installpath for software", None, "store", oldstyle_defaults["subdir_software"], ), "repository": ( "Repository type, using repositorypath", "choice", "store", oldstyle_defaults["repository"], sorted(get_repositories().keys()), ), "repositorypath": ( ( "Repository path, used by repository " "(is passed as list of arguments to create the repository instance). " "For more info, use --avail-repositories." ), "strlist", "store", oldstyle_defaults["repositorypath"][oldstyle_defaults["repository"]], ), "avail-repositories": (("Show all repository types (incl. non-usable)"), None, "store_true", False), "logfile-format": ( "Directory name and format of the log file ", "strtuple", "store", oldstyle_defaults["logfile_format"], {"metavar": "DIR,FORMAT"}, ), "tmp-logdir": ( "Log directory where temporary log files are stored", None, "store", oldstyle_defaults["tmp_logdir"], ), "sourcepath": ( "Path to where sources should be downloaded", None, "store", oldstyle_defaults["sourcepath"], ), "moduleclasses": ( ( "Extend supported module classes" " (For more info on the default classes, use --show-default-moduleclasses)" ), None, "extend", oldstyle_defaults["moduleclasses"], ), "show-default-moduleclasses": ("Show default module classes with description", None, "store_true", False), # this one is sort of an exception, it's something jobscripts can set, # has no real meaning for regular eb usage "testoutput": ( "Path to where a job should place the output (to be set within jobscript)", None, "store", None, ), } self.log.debug("config_options: descr %s opts %s" % (descr, opts)) self.add_group_parser(opts, descr)