Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ipbb add symlink behaviour #198

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/ipbb/cli/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


# ------------------------------------------------------------------------------
Expand Down
18 changes: 15 additions & 3 deletions src/ipbb/cmds/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Modules
import click
import os
import pathlib
import subprocess
import sh
import sys
Expand Down Expand Up @@ -468,19 +469,30 @@ def tar(ictx, repo, dest, strip):


# ------------------------------------------------------------------------------
def symlink(ictx, path):
def symlink(ictx, path, absolute):

lRepoName = basename(path)
lRepoLocalPath = join(ictx.srcdir, lRepoName)

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 )


# ------------------------------------------------------------------------------
Expand Down