diff --git a/src/ipbb/cli/repo.py b/src/ipbb/cli/repo.py index 51496c9..8bb8ed2 100644 --- a/src/ipbb/cli/repo.py +++ b/src/ipbb/cli/repo.py @@ -92,12 +92,16 @@ def tar(env, repo, dest, strip): # ------------------------------------------------------------------------------ @add.command('symlink', short_help="Add new source as symlink.") -@click.argument('path', type=click.Path(exists=True)) +@click.argument('path', type=click.Path(exists=False)) +@click.option('--absolute/--relative', + 'absolute', + default=True, + help='Create a link to the absolute/relative target path') @click.pass_obj -def symlink(env, path): - '''Add a tarball-ed package to the source area''' +def symlink(env, path, absolute): + '''Add a symlink to the source area''' from ..cmds.repo import symlink - symlink(env, path) + symlink(env, path, absolute) # ------------------------------------------------------------------------------ diff --git a/src/ipbb/cmds/repo.py b/src/ipbb/cmds/repo.py index b07d9f4..0fe883f 100644 --- a/src/ipbb/cmds/repo.py +++ b/src/ipbb/cmds/repo.py @@ -2,6 +2,7 @@ # Modules import click import os +import pathlib import subprocess import sh import sys @@ -468,7 +469,7 @@ def tar(ictx, repo, dest, strip): # ------------------------------------------------------------------------------ -def symlink(ictx, path): +def symlink(ictx, path, absolute): lRepoName = basename(path) lRepoLocalPath = join(ictx.srcdir, lRepoName) @@ -476,11 +477,22 @@ def symlink(ictx, path): if exists(lRepoLocalPath): raise click.ClickException('Repository already exists \'%s\'' % lRepoLocalPath) + lPathToCheck = \ + pathlib.Path(abspath(path)) if absolute \ + else pathlib.Path(ictx.srcdir)/path + + if not lPathToCheck.exists(): + raise click.ClickException('Target path \'%s\' does not exist' % lPathToCheck) + + lPathToCreate = \ + lPathToCheck if absolute \ + else path + cprint( - 'Adding symlink [blue]{}[/blue] to [blue]{}[/blue]'.format(path, lRepoName) + 'Adding symlink [blue]{}[/blue] to [blue]{}[/blue]'.format(lPathToCreate, lRepoName) ) - sh.ln('-s', abspath(path), _cwd=ictx.srcdir ) + sh.ln('-s', lPathToCreate, _cwd=ictx.srcdir ) # ------------------------------------------------------------------------------