Skip to content

Commit

Permalink
Fix some codacy advisories (#2393)
Browse files Browse the repository at this point in the history

Co-authored-by: Slavey Karadzhov <[email protected]>
  • Loading branch information
mikee47 and slav-at-attachix authored Oct 14, 2021
1 parent 5ed63aa commit 25066b1
Show file tree
Hide file tree
Showing 31 changed files with 140 additions and 137 deletions.
2 changes: 2 additions & 0 deletions Sming/Arch/Esp32/Tools/ci/build.run.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
#
# Esp32 build.run.sh

$MAKE_PARALLEL Basic_Blink Basic_WiFi HttpServer_ConfigNetwork DEBUG_VERBOSE_LEVEL=3 STRICT=1
Expand Down
2 changes: 2 additions & 0 deletions Sming/Arch/Esp32/Tools/ci/build.setup.sh
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#!/bin/bash
#
# Esp32 build.setup.sh
1 change: 0 additions & 1 deletion Sming/Arch/Esp32/Tools/decode-stacktrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ def extractAddresses(data):

pipe.stdin.write(line.encode('ascii'))
pipe.stdin.flush()

2 changes: 2 additions & 0 deletions Sming/Arch/Esp32/Tools/install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
#
# Esp32 install.sh

if [ -n "$IDF_PATH" ] && [ -n "$IDF_TOOLS_PATH" ]; then
Expand Down
2 changes: 2 additions & 0 deletions Sming/Arch/Esp8266/Tools/ci/build.run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
#
# Esp8266 build.run.sh

$MAKE_PARALLEL samples
Expand Down
2 changes: 2 additions & 0 deletions Sming/Arch/Esp8266/Tools/ci/build.setup.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
#
# Esp8266 build.setup.sh

unset SPIFFY
Expand Down
1 change: 0 additions & 1 deletion Sming/Arch/Esp8266/Tools/decode-stacktrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ def extractAddresses(data):

pipe.stdin.write(line.encode('ascii'))
pipe.stdin.flush()

18 changes: 10 additions & 8 deletions Sming/Arch/Esp8266/Tools/install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
#
# Esp8266 install.sh

# Old toolchain
Expand All @@ -6,11 +8,11 @@ if [ -n "$UDK_ROOT" ]; then
printf "\n\n** Skipping Esp8266 tools installation: '$UDK_ROOT' exists\n\n"
else
TOOLCHAIN=esp-open-sdk-linux-x86_64.tar.gz
$WGET $SMINGTOOLS/$TOOLCHAIN -O $DOWNLOADS/$TOOLCHAIN
mkdir -p $UDK_ROOT
tar -zxf $DOWNLOADS/$TOOLCHAIN -C $UDK_ROOT --totals
mv $UDK_ROOT/esp-open-sdk/* $UDK_ROOT
rmdir $UDK_ROOT/esp-open-sdk
$WGET "$SMINGTOOLS/$TOOLCHAIN" -O "$DOWNLOADS/$TOOLCHAIN"
mkdir -p "$UDK_ROOT"
tar -zxf "$DOWNLOADS/$TOOLCHAIN" -C "$UDK_ROOT" --totals
mv "$UDK_ROOT/esp-open-sdk/"* "$UDK_ROOT"
rmdir "$UDK_ROOT/esp-open-sdk"
fi
fi

Expand All @@ -20,8 +22,8 @@ if [ -n "$EQT_ROOT" ]; then
printf "\n\n** Skipping Esp8266 tools installation: '$EQT_ROOT' exists\n\n"
else
TOOLCHAIN=x86_64-linux-gnu.xtensa-lx106-elf-e6a192b.201211.tar.gz
$WGET $SMINGTOOLS/$TOOLCHAIN -O $DOWNLOADS/$TOOLCHAIN
mkdir -p $EQT_ROOT
tar -zxf $DOWNLOADS/$TOOLCHAIN -C $EQT_ROOT --totals
$WGET "$SMINGTOOLS/$TOOLCHAIN" -O "$DOWNLOADS/$TOOLCHAIN"
mkdir -p "$EQT_ROOT"
tar -zxf "$DOWNLOADS/$TOOLCHAIN" -C "$EQT_ROOT" --totals
fi
fi
4 changes: 3 additions & 1 deletion Sming/Arch/Host/Tools/ci/build.run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
#
# Host build.run.sh

SOURCE="${BASH_SOURCE[0]}"
Expand All @@ -9,7 +11,7 @@ done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"

if [[ $CHECK_SCA -eq 1 ]]; then
$DIR/coverity-scan.sh
"$DIR/coverity-scan.sh"
else
$MAKE_PARALLEL Basic_Blink Basic_DateTime Basic_Delegates Basic_Interrupts Basic_ProgMem Basic_Serial Basic_Servo Basic_Ssl LiveDebug DEBUG_VERBOSE_LEVEL=3
fi
Expand Down
6 changes: 4 additions & 2 deletions Sming/Arch/Host/Tools/ci/build.setup.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
#
# Host build.setup.sh

# Check coding style
Expand All @@ -13,7 +15,7 @@ fi
# Make deployment keys, etc. available
set +x
if [ -n "$SMING_SECRET" ]; then
openssl aes-256-cbc -d -a -iter 100 -in $CI_BUILD_DIR/Tools/ci/secrets.sh.enc -out /tmp/secrets.sh -pass pass:$SMING_SECRET
openssl aes-256-cbc -d -a -iter 100 -in "$CI_BUILD_DIR/Tools/ci/secrets.sh.enc" -out /tmp/secrets.sh -pass "pass:$SMING_SECRET"
source /tmp/secrets.sh
unset SMING_SECRET
fi
Expand All @@ -25,4 +27,4 @@ sudo ip a a dev tap0 192.168.13.1/24
sudo ip link set tap0 up

# Build documentation
make -C $SMING_HOME docs
make -C "$SMING_HOME" docs
6 changes: 3 additions & 3 deletions Sming/Arch/Host/Tools/ci/coverity-scan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ if [ "$AUTH_RES" = "Access denied" ]; then
echo -e "\033[33;1mCoverity Scan API access denied. Check COVERITY_SCAN_PROJECT_NAME and COVERITY_SCAN_TOKEN.\033[0m"
exit 1
else
AUTH=$(echo $AUTH_RES | ruby -e "require 'rubygems'; require 'json'; puts JSON[STDIN.read]['upload_permitted']")
AUTH=$(echo "$AUTH_RES" | ruby -e "require 'rubygems'; require 'json'; puts JSON[STDIN.read]['upload_permitted']")
if [ "$AUTH" = "true" ]; then
echo -e "\033[33;1mCoverity Scan analysis authorized per quota.\033[0m"
else
WHEN=$(echo $AUTH_RES | ruby -e "require 'rubygems'; require 'json'; puts JSON[STDIN.read]['next_upload_permitted_at']")
WHEN=$(echo "$AUTH_RES" | ruby -e "require 'rubygems'; require 'json'; puts JSON[STDIN.read]['next_upload_permitted_at']")
echo -e "\033[33;1mOops!Coverity Scan analysis engine NOT authorized until $WHEN.\033[0m"
permit=false
fi
Expand All @@ -50,7 +50,7 @@ if [ ! -d $TOOL_BASE ]; then
# Download Coverity Scan Analysis Tool
if [ ! -e $TOOL_ARCHIVE ]; then
echo -e "\033[33;1mDownloading Coverity Scan Analysis Tool...\033[0m"
wget -nv -O $TOOL_ARCHIVE $TOOL_URL --post-data "project=$COVERITY_SCAN_PROJECT_NAME&token=$COVERITY_SCAN_TOKEN"
wget -nv -O "$TOOL_ARCHIVE" "$TOOL_URL" --post-data "project=$COVERITY_SCAN_PROJECT_NAME&token=$COVERITY_SCAN_TOKEN"
fi

# Extract Coverity Scan Analysis Tool
Expand Down
2 changes: 2 additions & 0 deletions Sming/Arch/Host/Tools/install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash
#
# Host install.sh

# Required by deployment script
Expand Down
4 changes: 2 additions & 2 deletions Sming/Arch/Host/Tools/setup-network-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ sudo sysctl net.ipv4.ip_forward=1
sudo sysctl net.ipv6.conf.default.forwarding=1
sudo sysctl net.ipv6.conf.all.forwarding=1

sudo iptables -t nat -A POSTROUTING -o $INTERNET_IF -j MASQUERADE
sudo iptables -t nat -A POSTROUTING -o "$INTERNET_IF" -j MASQUERADE
sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i tap0 -o $INTERNET_IF -j ACCEPT
sudo iptables -A FORWARD -i tap0 -o "$INTERNET_IF" -j ACCEPT

exit 0
2 changes: 1 addition & 1 deletion Sming/Components/Network/src/Network/TcpConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class TcpConnection : public IpConnection
static err_t staticOnPoll(void* arg, tcp_pcb* tcp);
static void closeTcpConnection(tcp_pcb* tpcb);

inline void checkSelfFree()
void checkSelfFree()
{
if(tcp == nullptr && autoSelfDestruct) {
delete this;
Expand Down
2 changes: 1 addition & 1 deletion Sming/Components/Network/src/Network/TcpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ err_t TcpServer::onAccept(tcp_pcb* clientTcp, err_t err)
connections.add(client);
debug_d("Opening connection. Total connections: %d", connections.count());

onClient((TcpClient*)client);
onClient(reinterpret_cast<TcpClient*>(client));

return ERR_OK;
}
Expand Down
14 changes: 7 additions & 7 deletions Sming/Components/Storage/Tools/hwconfig/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,28 @@
quiet = False

def status(msg):
""" Print status message to stderr """
"""Print status message to stderr."""
if not quiet:
critical(msg)


def critical(msg):
""" Print critical message to stderr """
"""Print critical message to stderr."""
sys.stderr.write(msg)
sys.stderr.write('\n')


def fixpath(path):
""" Paths in Windows can get a little weird """
"""Paths in Windows can get a little weird """
if len(path) > 2 and path[1] != ':' and platform.system() == 'Windows' and path[2] == '/':
return path[1] + ':' + path[2:]
return path


def parse_int(v, keywords=None):
"""Generic parser for integer fields - int(x,0) with provision for
k/m/K/M suffixes and 'keyword' value lookup.
"""Generic parser for integer fields.
int(x,0) with provision for k/m/K/M suffixes and 'keyword' value lookup.
"""
if not isinstance(v, str):
return v
Expand All @@ -50,8 +51,7 @@ def parse_int(v, keywords=None):


def stringnum(s):
"""Return number if s contains only digits, otherwise return the string
"""
"""Return number if s contains only digits, otherwise return the string."""
return int(s) if s.isdigit() else s


Expand Down
15 changes: 7 additions & 8 deletions Sming/Components/Storage/Tools/hwconfig/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ def __str__(self):

@classmethod
def from_name(cls, name):
"""Create configuration given its name and resolve options
"""
"""Create configuration given its name and resolve options."""
config = Config()
config.load(name)
options = os.environ.get('HWCONFIG_OPTS', '').replace(' ', '')
Expand All @@ -105,26 +104,26 @@ def from_name(cls, name):
return config

@classmethod
def from_json(cls, json, options = []):
def from_json(cls, json, options = None):
config = Config()
config.parse_dict(copy.deepcopy(json))
config.parse_options(options)
if options is not None:
config.parse_options(options)
config.resolve_expressions()
config.partitions.sort()
return config

def load(self, name):
"""Load a configuration recursively
"""
"""Load a configuration recursively."""
filename = find_config(name)
self.depends.append(filename)
data = json_load(filename)
self.parse_dict(data)

def parse_options(self, options):
"""Apply any specified options
"""Apply any specified options.
Each option can be applied more than once to ensure overrides work as expected
Each option can be applied more than once to ensure overrides work as expected.
"""
for option in options:
self.options.append(option)
Expand Down
Loading

0 comments on commit 25066b1

Please sign in to comment.