Skip to content

Commit c9e5d88

Browse files
authored
Merge pull request #70 from nexB/58-deltacode-script
58 deltacode script
2 parents 6da96c7 + 214b0db commit c9e5d88

6 files changed

Lines changed: 2443 additions & 3 deletions

File tree

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
graft src
22
graft etc
33
graft thirdparty
4+
graft samples
45

56
recursive-exclude thirdparty/dev *
67
prune tests
@@ -18,6 +19,8 @@ include setup.cfg
1819
include .gitignore
1920
include configure
2021
include configure.bat
22+
include deltacode
23+
include deltacode.bat
2124
include .travis.yml
2225

2326
global-exclude *.py[co] __pycache__ *.*~

deltacode

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2018 nexB Inc. http://www.nexb.com/ - All rights reserved.
4+
#
5+
6+
# A minimal shell wrapper to the CLI entry point fo DeltaCode
7+
8+
9+
###################################################################################
10+
# from https://raw.githubusercontent.com/mkropat/sh-realpath/58c03982cfd8accbcf0c4426a4adf0f120a8b2bb/realpath.sh
11+
# realpath emulation for portability on *nix
12+
# this allow running scancode from aribtrary locations and from symlinks
13+
#
14+
# Copyright (c) 2014 Michael Kropat
15+
#
16+
# Permission is hereby granted, free of charge, to any person obtaining a copy
17+
# of this software and associated documentation files (the "Software"), to deal
18+
# in the Software without restriction, including without limitation the rights
19+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20+
# copies of the Software, and to permit persons to whom the Software is
21+
# furnished to do so, subject to the following conditions:
22+
#
23+
# The above copyright notice and this permission notice shall be included in
24+
# all copies or substantial portions of the Software.
25+
#
26+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32+
# THE SOFTWARE.
33+
34+
realpath() {
35+
canonicalize_path "$(resolve_symlinks "$1")"
36+
}
37+
38+
resolve_symlinks() {
39+
_resolve_symlinks "$1"
40+
}
41+
42+
_resolve_symlinks() {
43+
_assert_no_path_cycles "$@" || return
44+
45+
local dir_context path
46+
path=$(readlink -- "$1")
47+
if [ $? -eq 0 ]; then
48+
dir_context=$(dirname -- "$1")
49+
_resolve_symlinks "$(_prepend_dir_context_if_necessary "$dir_context" "$path")" "$@"
50+
else
51+
printf '%s\n' "$1"
52+
fi
53+
}
54+
55+
_prepend_dir_context_if_necessary() {
56+
if [ "$1" = . ]; then
57+
printf '%s\n' "$2"
58+
else
59+
_prepend_path_if_relative "$1" "$2"
60+
fi
61+
}
62+
63+
_prepend_path_if_relative() {
64+
case "$2" in
65+
/* ) printf '%s\n' "$2" ;;
66+
* ) printf '%s\n' "$1/$2" ;;
67+
esac
68+
}
69+
70+
_assert_no_path_cycles() {
71+
local target path
72+
73+
target=$1
74+
shift
75+
76+
for path in "$@"; do
77+
if [ "$path" = "$target" ]; then
78+
return 1
79+
fi
80+
done
81+
}
82+
83+
canonicalize_path() {
84+
if [ -d "$1" ]; then
85+
_canonicalize_dir_path "$1"
86+
else
87+
_canonicalize_file_path "$1"
88+
fi
89+
}
90+
91+
_canonicalize_dir_path() {
92+
(cd "$1" 2>/dev/null && pwd -P)
93+
}
94+
95+
_canonicalize_file_path() {
96+
local dir file
97+
dir=$(dirname -- "$1")
98+
file=$(basename -- "$1")
99+
(cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file")
100+
}
101+
102+
###################################################################################
103+
# Now run scancode proper
104+
105+
DELTACODE_BIN="$( realpath "${BASH_SOURCE[0]}" )"
106+
DELTACODE_ROOT_DIR="$( cd "$( dirname "${DELTACODE_BIN}" )" && pwd )"
107+
108+
DELTACODE_CONFIGURED_PYTHON="$DELTACODE_ROOT_DIR/bin/python"
109+
if [ ! -f "$DELTACODE_CONFIGURED_PYTHON" ]; then
110+
echo "* Configuring DeltaCode for first use..."
111+
CONFIGURE_QUIET=1 "$DELTACODE_ROOT_DIR/configure" etc/conf
112+
fi
113+
114+
"$DELTACODE_ROOT_DIR/bin/deltacode" "$@"

deltacode.bat

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@echo OFF
2+
@rem Copyright (c) 2018 nexB Inc. http://www.nexb.com/ - All rights reserved.
3+
4+
@rem A minimal shell wrapper to the CLI entry point
5+
6+
set DELTACODE_ROOT_DIR=%~dp0
7+
@rem Use a trailing space in the next line to set the variable to an empty string
8+
set DELTACODE_CMD_LINE_ARGS=
9+
set DELTACODE_CONFIGURED_PYTHON=%DELTACODE_ROOT_DIR%\bin\python.exe
10+
11+
@rem Collect all command line arguments in a variable
12+
:collectarg
13+
if ""%1""=="""" goto continue
14+
call set DELTACODE_CMD_LINE_ARGS=%DELTACODE_CMD_LINE_ARGS% %1
15+
shift
16+
goto collectarg
17+
18+
:continue
19+
20+
if not exist "%DELTACODE_CONFIGURED_PYTHON%" goto configure
21+
goto deltacode
22+
23+
:configure
24+
echo * Configuring DeltaCode for first use...
25+
set CONFIGURE_QUIET=1
26+
call "%DELTACODE_ROOT_DIR%\configure" etc/conf
27+
if %errorlevel% neq 0 (
28+
exit /b %errorlevel%
29+
)
30+
31+
:deltacode
32+
"%DELTACODE_ROOT_DIR%\bin\deltacode" %DELTACODE_CMD_LINE_ARGS%
33+
34+
:EOS

etc/release/MANIFEST.in.release

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
graft src
22
graft etc
33
graft thirdparty
4+
graft samples
45

56
recursive-exclude thirdparty/dev *
67
prune tests
@@ -18,6 +19,8 @@ include setup.cfg
1819
include .gitignore
1920
include configure
2021
include configure.bat
22+
include deltacode
23+
include deltacode.bat
2124
include .travis.yml
2225

2326
global-exclude *.py[co] __pycache__ *.*~

etc/release/release.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ function test_scan {
5050
extract_dir=$(ls -d */)
5151
cd $extract_dir
5252

53-
./configure etc/conf
54-
55-
./bin/deltacode --help
53+
./deltacode --help
5654
echo "TEST help passed: ./deltacode --help"
5755

56+
./deltacode -n samples/samples.json -o samples/samples.json
57+
echo "TEST sample delta passed: ./deltacode -n samples/samples.json -o samples/samples.json"
58+
5859
# cleanup
5960
cd ..
6061
rm -rf $extract_dir

0 commit comments

Comments
 (0)