Bug fixes, tty tweaks.
This commit is contained in:
parent
8c140f4725
commit
346f102234
1 changed files with 10 additions and 9 deletions
|
@ -46,7 +46,7 @@ def setup_parser(subparser):
|
||||||
# The action parameterizes the command but in keeping with Spack
|
# The action parameterizes the command but in keeping with Spack
|
||||||
# patterns we make it a subcommand.
|
# patterns we make it a subcommand.
|
||||||
sps = [
|
sps = [
|
||||||
sp.add_parser('link', aliases=['add'],
|
sp.add_parser('add', aliases=['link'],
|
||||||
help='Add packages to the view, create view if needed.'),
|
help='Add packages to the view, create view if needed.'),
|
||||||
sp.add_parser('remove', aliases=['rm'],
|
sp.add_parser('remove', aliases=['rm'],
|
||||||
help='Remove packages from the view, and view if empty.'),
|
help='Remove packages from the view, and view if empty.'),
|
||||||
|
@ -112,6 +112,7 @@ def action_remove(spec, prefix):
|
||||||
tty.info("Skipping nonexistent package %s"%spec.name)
|
tty.info("Skipping nonexistent package %s"%spec.name)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
tty.info("remove %s"%spec.name)
|
||||||
for dirpath,dirnames,filenames in os.walk(spec.prefix):
|
for dirpath,dirnames,filenames in os.walk(spec.prefix):
|
||||||
if not filenames:
|
if not filenames:
|
||||||
continue
|
continue
|
||||||
|
@ -125,7 +126,6 @@ def action_remove(spec, prefix):
|
||||||
continue
|
continue
|
||||||
os.unlink(dst)
|
os.unlink(dst)
|
||||||
|
|
||||||
|
|
||||||
def action_link(spec, prefix):
|
def action_link(spec, prefix):
|
||||||
'Symlink all files in `spec` into directory `prefix`.'
|
'Symlink all files in `spec` into directory `prefix`.'
|
||||||
|
|
||||||
|
@ -134,6 +134,7 @@ def action_link(spec, prefix):
|
||||||
tty.warn("Skipping previously added package %s"%spec.name)
|
tty.warn("Skipping previously added package %s"%spec.name)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
tty.info("link %s" % spec.name)
|
||||||
for dirpath,dirnames,filenames in os.walk(spec.prefix):
|
for dirpath,dirnames,filenames in os.walk(spec.prefix):
|
||||||
if not filenames:
|
if not filenames:
|
||||||
continue # avoid explicitly making empty dirs
|
continue # avoid explicitly making empty dirs
|
||||||
|
@ -151,8 +152,6 @@ def action_link(spec, prefix):
|
||||||
continue
|
continue
|
||||||
os.symlink(src,dst)
|
os.symlink(src,dst)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def purge_empty_directories(path):
|
def purge_empty_directories(path):
|
||||||
'Ascend up from the leaves accessible from `path` and remove empty directories.'
|
'Ascend up from the leaves accessible from `path` and remove empty directories.'
|
||||||
for dirpath, subdirs, files in os.walk(path, topdown=False):
|
for dirpath, subdirs, files in os.walk(path, topdown=False):
|
||||||
|
@ -161,13 +160,14 @@ def purge_empty_directories(path):
|
||||||
try:
|
try:
|
||||||
os.rmdir(sdp)
|
os.rmdir(sdp)
|
||||||
except OSError:
|
except OSError:
|
||||||
tty.warn("Not removing directory with contents: %s" % sdp)
|
#tty.warn("Not removing directory with contents: %s" % sdp)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def view_action(action, parser, args):
|
def view_action(action, parser, args):
|
||||||
'The view command.'
|
'The view command parameterized by the action.'
|
||||||
to_exclude = [re.compile(e) for e in args.exclude]
|
to_exclude = [re.compile(e) for e in args.exclude]
|
||||||
def exclude(spec):
|
def exclude(spec):
|
||||||
for e in to_exclude:
|
for e in to_exclude:
|
||||||
|
@ -180,7 +180,7 @@ def exclude(spec):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
prefix = args.prefix
|
prefix = args.prefix[0]
|
||||||
assuredir(prefix)
|
assuredir(prefix)
|
||||||
|
|
||||||
flat = set()
|
flat = set()
|
||||||
|
@ -197,14 +197,15 @@ def exclude(spec):
|
||||||
if not os.path.exists(spec.prefix):
|
if not os.path.exists(spec.prefix):
|
||||||
tty.warn('Skipping unknown package: %s in %s' % (spec.name, spec.prefix))
|
tty.warn('Skipping unknown package: %s in %s' % (spec.name, spec.prefix))
|
||||||
continue
|
continue
|
||||||
tty.info("%s %s" % (action, spec.name))
|
|
||||||
action(spec, prefix)
|
action(spec, prefix)
|
||||||
|
|
||||||
if action in ['remove']:
|
if args.action in ['remove','rm']:
|
||||||
purge_empty_directories(prefix)
|
purge_empty_directories(prefix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def view(parser, args):
|
def view(parser, args):
|
||||||
|
'The view command.'
|
||||||
action = {
|
action = {
|
||||||
'add': action_link,
|
'add': action_link,
|
||||||
'link': action_link,
|
'link': action_link,
|
||||||
|
|
Loading…
Reference in a new issue