def config_set(args): # default scope for writing is 'user' if not args.scope: args.scope = "user" config = spack.config.get_config(args.scope) config.set_value(args.key, args.value) config.write()
def config_set(args): # default scope for writing is 'user' if not args.scope: args.scope = 'user' config = spack.config.get_config(args.scope) config.set_value(args.key, args.value) config.write()
def create_repo(root, namespace=None): """Create a new repository in root with the specified namespace. If the namespace is not provided, use basename of root. Return the canonicalized path and namespace of the created repository. """ root = spack.util.path.canonicalize_path(root) if not namespace: namespace = os.path.basename(root) if not re.match(r'\w[\.\w-]*', namespace): raise InvalidNamespaceError("'%s' is not a valid namespace." % namespace) existed = False if os.path.exists(root): if os.path.isfile(root): raise BadRepoError( 'File %s already exists and is not a directory' % root) elif os.path.isdir(root): if not os.access(root, os.R_OK | os.W_OK): raise BadRepoError( 'Cannot create new repo in %s: cannot access directory.' % root) if os.listdir(root): raise BadRepoError( 'Cannot create new repo in %s: directory is not empty.' % root) existed = True full_path = os.path.realpath(root) parent = os.path.dirname(full_path) if not os.access(parent, os.R_OK | os.W_OK): raise BadRepoError( "Cannot create repository in %s: can't access parent!" % root) try: config_path = os.path.join(root, repo_config_name) packages_path = os.path.join(root, packages_dir_name) fs.mkdirp(packages_path) with open(config_path, 'w') as config: config.write("repo:\n") config.write(" namespace: '%s'\n" % namespace) except (IOError, OSError) as e: # try to clean up. if existed: shutil.rmtree(config_path, ignore_errors=True) shutil.rmtree(packages_path, ignore_errors=True) else: shutil.rmtree(root, ignore_errors=True) raise BadRepoError('Failed to create new repository in %s.' % root, "Caused by %s: %s" % (type(e), e)) return full_path, namespace
def mirror_remove(args): """Remove a mirror by name.""" config = spack.config.get_config('user') name = args.name if not config.has_named_section('mirror', name): tty.die("No such mirror: %s" % name) config.remove_named_section('mirror', name) config.write()
def mirror_add(args): """Add a mirror to Spack.""" url = args.url if url.startswith("/"): url = "file://" + url config = spack.config.get_config("user") config.set_value("mirror", args.name, "url", url) config.write()
def create_repo(root, namespace=None): """Create a new repository in root with the specified namespace. If the namespace is not provided, use basename of root. Return the canonicalized path and namespace of the created repository. """ root = canonicalize_path(root) if not namespace: namespace = os.path.basename(root) if not re.match(r'\w[\.\w-]*', namespace): raise InvalidNamespaceError( "'%s' is not a valid namespace." % namespace) existed = False if os.path.exists(root): if os.path.isfile(root): raise BadRepoError('File %s already exists and is not a directory' % root) elif os.path.isdir(root): if not os.access(root, os.R_OK | os.W_OK): raise BadRepoError( 'Cannot create new repo in %s: cannot access directory.' % root) if os.listdir(root): raise BadRepoError( 'Cannot create new repo in %s: directory is not empty.' % root) existed = True full_path = os.path.realpath(root) parent = os.path.dirname(full_path) if not os.access(parent, os.R_OK | os.W_OK): raise BadRepoError( "Cannot create repository in %s: can't access parent!" % root) try: config_path = os.path.join(root, repo_config_name) packages_path = os.path.join(root, packages_dir_name) mkdirp(packages_path) with open(config_path, 'w') as config: config.write("repo:\n") config.write(" namespace: '%s'\n" % namespace) except (IOError, OSError) as e: raise BadRepoError('Failed to create new repository in %s.' % root, "Caused by %s: %s" % (type(e), e)) # try to clean up. if existed: shutil.rmtree(config_path, ignore_errors=True) shutil.rmtree(packages_path, ignore_errors=True) else: shutil.rmtree(root, ignore_errors=True) return full_path, namespace
def mirror_add(args): """Add a mirror to Spack.""" url = args.url if url.startswith('/'): url = 'file://' + url config = spack.config.get_config('user') config.set_value('mirror', args.name, 'url', url) config.write()
def add_compilers_to_config(scope, *compilers): config = spack.config.get_config(scope) for compiler in compilers: add_compiler(config, compiler) config.write()
def mirror_add(args): """Add a mirror to Spack.""" config = spack.config.get_config('user') config.set_value('mirror', args.name, 'url', args.url) config.write()