Skip to content

Commit

Permalink
Add deltacode script #58
Browse files Browse the repository at this point in the history
* Add Unix deltacode entrypoint script
* Add Windows deltacode entrypoint script

Signed-off-by: Steven Esser <sesser@nexb.com>
  • Loading branch information
steven-esser committed Feb 15, 2018
1 parent 6da96c7 commit c407e12
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
114 changes: 114 additions & 0 deletions deltacode
@@ -0,0 +1,114 @@
#!/bin/bash
#
# Copyright (c) 2018 nexB Inc. http://www.nexb.com/ - All rights reserved.
#

# A minimal shell wrapper to the CLI entry point fo DeltaCode


###################################################################################
# from https://raw.githubusercontent.com/mkropat/sh-realpath/58c03982cfd8accbcf0c4426a4adf0f120a8b2bb/realpath.sh
# realpath emulation for portability on *nix
# this allow running scancode from aribtrary locations and from symlinks
#
# Copyright (c) 2014 Michael Kropat
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

realpath() {
canonicalize_path "$(resolve_symlinks "$1")"
}

resolve_symlinks() {
_resolve_symlinks "$1"
}

_resolve_symlinks() {
_assert_no_path_cycles "$@" || return

local dir_context path
path=$(readlink -- "$1")
if [ $? -eq 0 ]; then
dir_context=$(dirname -- "$1")
_resolve_symlinks "$(_prepend_dir_context_if_necessary "$dir_context" "$path")" "$@"
else
printf '%s\n' "$1"
fi
}

_prepend_dir_context_if_necessary() {
if [ "$1" = . ]; then
printf '%s\n' "$2"
else
_prepend_path_if_relative "$1" "$2"
fi
}

_prepend_path_if_relative() {
case "$2" in
/* ) printf '%s\n' "$2" ;;
* ) printf '%s\n' "$1/$2" ;;
esac
}

_assert_no_path_cycles() {
local target path

target=$1
shift

for path in "$@"; do
if [ "$path" = "$target" ]; then
return 1
fi
done
}

canonicalize_path() {
if [ -d "$1" ]; then
_canonicalize_dir_path "$1"
else
_canonicalize_file_path "$1"
fi
}

_canonicalize_dir_path() {
(cd "$1" 2>/dev/null && pwd -P)
}

_canonicalize_file_path() {
local dir file
dir=$(dirname -- "$1")
file=$(basename -- "$1")
(cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file")
}

###################################################################################
# Now run scancode proper

DELTACODE_BIN="$( realpath "${BASH_SOURCE[0]}" )"
DELTACODE_ROOT_DIR="$( cd "$( dirname "${DELTACODE_BIN}" )" && pwd )"

DELTACODE_CONFIGURED_PYTHON="$DELTACODE_ROOT_DIR/bin/python"
if [ ! -f "$DELTACODE_CONFIGURED_PYTHON" ]; then
echo "* Configuring DeltaCode for first use..."
CONFIGURE_QUIET=1 "$DELTACODE_ROOT_DIR/configure" etc/conf
fi

"$DELTACODE_ROOT_DIR/bin/deltacode" "$@"
34 changes: 34 additions & 0 deletions deltacode.bat
@@ -0,0 +1,34 @@
@echo OFF
@rem Copyright (c) 2018 nexB Inc. http://www.nexb.com/ - All rights reserved.

@rem A minimal shell wrapper to the CLI entry point

set DELTACODE_ROOT_DIR=%~dp0
@rem Use a trailing space in the next line to set the variable to an empty string
set DELTACODE_CMD_LINE_ARGS=
set DELTACODE_CONFIGURED_PYTHON=%DELTACODE_ROOT_DIR%\bin\python.exe

@rem Collect all command line arguments in a variable
:collectarg
if ""%1""=="""" goto continue
call set DELTACODE_CMD_LINE_ARGS=%DELTACODE_CMD_LINE_ARGS% %1
shift
goto collectarg

:continue

if not exist "%DELTACODE_CONFIGURED_PYTHON%" goto configure
goto deltacode

:configure
echo * Configuring DeltaCode for first use...
set CONFIGURE_QUIET=1
call "%DELTACODE_ROOT_DIR%\configure" etc/conf
if %errorlevel% neq 0 (
exit /b %errorlevel%
)

:deltacode
"%DELTACODE_ROOT_DIR%\bin\deltacode" %DELTACODE_CMD_LINE_ARGS%

:EOS

0 comments on commit c407e12

Please sign in to comment.