Skip to content

Commit

Permalink
Merge 5e10ae1 into 138307d
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidPoliakoff committed May 17, 2016
2 parents 138307d + 5e10ae1 commit 0ec784c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
51 changes: 36 additions & 15 deletions lib/spack/spack/cmd/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
import os
import re
import shutil

from external import argparse
import llnl.util.tty as tty
from llnl.util.filesystem import join_path, mkdirp

import spack.spec
import spack.config
from spack.util.environment import get_path
import spack.url
import spack.fetch_strategy as fs
from spack.repository import *
from spack.stage import Stage

description = "Manage package source repositories."


def setup_parser(subparser):
sp = subparser.add_subparsers(metavar='SUBCOMMAND', dest='repo_command')
scopes = spack.config.config_scopes
Expand All @@ -57,13 +57,18 @@ def setup_parser(subparser):

# Add
add_parser = sp.add_parser('add', help=repo_add.__doc__)
add_parser.add_argument('path', help="Path to a Spack package repository directory.")
add_parser.add_argument(
'path',
help="Path to a Spack package repository directory")

add_parser.add_argument(
'--scope', choices=scopes, default=spack.cmd.default_modify_scope,
help="Configuration scope to modify.")

# Remove
remove_parser = sp.add_parser('remove', help=repo_remove.__doc__, aliases=['rm'])
remove_parser = sp.add_parser(
'remove',
help=repo_remove.__doc__, aliases=['rm'])
remove_parser.add_argument(
'path_or_namespace',
help="Path or namespace of a Spack package repository.")
Expand All @@ -83,7 +88,22 @@ def repo_create(args):
def repo_add(args):
"""Add a package source to Spack's configuration."""
path = args.path

fetcher = fs.from_url(path)
spack_repo_config = spack.config.get_config('repos')
root_repo = Repo(spack_repo_config[-1])
if isinstance(fetcher, fs.VCSFetchStrategy):
with Stage("testpath") as stage:
fetcher.set_stage(stage)
fetcher.fetch()
packageName = os.listdir(stage.path)[0]
try:
shutil.rmtree(root_repo.packages_path + "/" + packageName)
except OSError:
pass
shutil.move(
stage.path + "/" + packageName,
root_repo.packages_path)
path = root_repo.packages_path + "/" + packageName
# real_path is absolute and handles substitution.
canon_path = canonicalize_path(path)

Expand All @@ -100,7 +120,8 @@ def repo_add(args):

# If that succeeds, finally add it to the configuration.
repos = spack.config.get_config('repos', args.scope)
if not repos: repos = []
if not repos:
repos = []

if repo.root in repos or path in repos:
tty.die("Repository is already registered with Spack: %s" % path)
Expand Down Expand Up @@ -135,7 +156,7 @@ def repo_remove(args):
tty.msg("Removed repository %s with namespace '%s'."
% (repo.root, repo.namespace))
return
except RepoError as e:
except RepoError:
continue

tty.die("No repository with path or namespace: %s"
Expand All @@ -149,7 +170,7 @@ def repo_list(args):
for r in roots:
try:
repos.append(Repo(r))
except RepoError as e:
except RepoError:
continue

msg = "%d package repositor" % len(repos)
Expand All @@ -166,9 +187,9 @@ def repo_list(args):


def repo(parser, args):
action = { 'create' : repo_create,
'list' : repo_list,
'add' : repo_add,
'remove' : repo_remove,
'rm' : repo_remove}
action = {'create': repo_create,
'list': repo_list,
'add': repo_add,
'remove': repo_remove,
'rm': repo_remove}
action[args.repo_command](args)
2 changes: 2 additions & 0 deletions lib/spack/spack/fetch_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,8 @@ def from_url(url):
TODO: make this return appropriate fetch strategies for other
types of URLs.
"""
if("github.com" in url or "stash." in url or "bitbucket" in url):
return GitFetchStrategy(git=url)
return URLFetchStrategy(url)


Expand Down

0 comments on commit 0ec784c

Please sign in to comment.