Skip to content

Commit aa5da29

Browse files
committed
Add CLI scripts copied from scancode-toolkit
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 1fbf4e3 commit aa5da29

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

extractcode

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

extractcode.bat

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@echo OFF
2+
3+
@rem Copyright (c) nexB Inc. and others. All rights reserved.
4+
@rem SPDX-License-Identifier: Apache-2.0
5+
@rem See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
@rem ScanCode is a trademark of nexB Inc.
7+
@rem See https://github.com/nexB/extractcode for support or download.
8+
@rem See https://aboutcode.org for more information about nexB OSS projects.
9+
10+
@rem A wrapper to ExtractCode command line entry point
11+
12+
set EXTRACTCODE_ROOT_DIR=%~dp0
13+
set EXTRACTCODE_CONFIGURED_PYTHON=%EXTRACTCODE_ROOT_DIR%Scripts\python.exe
14+
15+
if not exist "%EXTRACTCODE_CONFIGURED_PYTHON%" goto configure
16+
goto extractcode
17+
18+
:configure
19+
echo * Configuring ExtractCode for first use...
20+
set CONFIGURE_QUIET=1
21+
call "%EXTRACTCODE_ROOT_DIR%configure"
22+
23+
@rem Return a proper return code on failure
24+
if %errorlevel% neq 0 (
25+
exit /b %errorlevel%
26+
)
27+
28+
:extractcode
29+
@rem without this things may not always work on Windows 10, but this makes things slower
30+
set PYTHONDONTWRITEBYTECODE=1
31+
32+
"%EXTRACTCODE_ROOT_DIR%Scripts\extractcode" %*

0 commit comments

Comments
 (0)