Skip to content

Commit 9c355a0

Browse files
committed
Bug fixes
1 parent 5b9930f commit 9c355a0

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

plugins/venv

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ function dovenv() {
3131
# createoptions for the python -m venv $path
3232
# pyver
3333
# optional pip list command at end
34-
function venvpline() {
35-
local line
36-
while read line
37-
do
38-
logtoboth " $line"
39-
echo $line >> /usr/local/bin/logit.txt
40-
done
41-
}
34+
4235
local pip python fcreate=0
4336

4437
python="python${pyver}"
@@ -64,7 +57,7 @@ function dovenv() {
6457
copt=""
6558
[ "$createoptions" != "" ] && copt=" with create options '$createoptions'"
6659
logtoboth "> Plugin $pfx: Create venv '$path'$copt"
67-
docmdlog "$python -m venv $createoptions $path" /etc/sdm/apt.log || logtobothex "? Plugin $pfx: Python venv create returned an error"
60+
runcaptureout "$python -m venv $createoptions $path" /etc/sdm/apt.log || logtobothex "? Plugin $pfx: Python venv create returned an error"
6861
fi
6962

7063
[[ ! -d $path ]] || [[ ! -f $path/pyvenv.cfg ]] && logtobothex "? Plugin $pfx: Python venv $path does not exist"
@@ -95,7 +88,7 @@ function dovenv() {
9588
if [ "$list" != "" ]
9689
then
9790
logtoboth "> Plugin $pfx: $pip list venv '$path'"
98-
{ { { { $path/bin/$pip list 2>&1; echo $? >&3; } | venvpline >&4; } 3>&1; } | { read xs; exit $xs; } } 4>&1
91+
runcaptureout "$path/bin/$pip list" || logtobothex "? Error returned from '$path/bin/$pip list' ($?)"
9992
fi
10093
}
10194

sdm-cparse

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ function logit {
3434
# Writes message to /etc/sdm/history
3535
#
3636
# $1="message string"
37+
# $2=/path/to/log [/etc/sdm/history]
3738
#
38-
[ -f $SDMPT/etc/sdm/history ] && echo "$(thisdate) $1" >> $SDMPT/etc/sdm/history
39+
msg="$1" logf=${2:-/etc/sdm/history}
40+
[ -f $SDMPT/$logf ] && echo "$(thisdate) $msg" >> $SDMPT/$logf
3941
}
4042

4143
function logtoboth() {
@@ -44,18 +46,19 @@ function logtoboth() {
4446
#
4547
# $1="message string" which will be split up across multiple lines if needed
4648
# $2="nosplit" if lines should not be split up
49+
# $3=/path/to/logfile for alternate log
4750
#
48-
local msg="$1"
51+
local msg="$1" mods=$2 logf=${3:-/etc/sdm/history}
4952
local str=() i spc=""
50-
if [[ ${#msg} -le $logwidth ]] || [[ "$2" == "nosplit" ]]
53+
if [[ ${#msg} -le $logwidth ]] || [[ "$mods" == "nosplit" ]]
5154
then
52-
logit "$msg"
55+
logit "$msg" $logf
5356
echo "$msg"
5457
else
5558
readarray -t str <<< $(fold -s -w$logwidth <<< $(echo "$msg"))
5659
for (( i=0 ; i < ${#str[@]} ; i++))
5760
do
58-
logit "${spc}${str[$i]}"
61+
logit "${spc}${str[$i]}" $logf
5962
echo "${spc}${str[$i]}"
6063
spc=" "
6164
done
@@ -195,6 +198,8 @@ function doapt() {
195198
else
196199
# Technique from https://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another/73180#73180
197200
{ { { { DEBIAN_FRONTEND=noninteractive $aptcmd -o=Dpkg::Use-Pty=0 $options $1 2>&1; echo $? >&3; } | pline >&4; } 3>&1; } | { read xs; exit $xs; } } 4>&1
201+
# This V doesn't work when passed as argument ;(
202+
#runcaptureout "DEBIAN_FRONTEND=noninteractive $aptcmd -o=Dpkg::Use-Pty=0 $options $1"
198203
sts=$?
199204
fi
200205
fi
@@ -217,13 +222,13 @@ function runcaptureout() {
217222
#
218223
# Run command, capturing output via logtoboth
219224
#
220-
local cmd="$1"
225+
local cmd="$1" outlog="$2"
221226

222227
function pline() {
223228
local line
224229
while read line
225230
do
226-
logtoboth "$line"
231+
logtoboth "$line" $outlog
227232
done
228233
}
229234

@@ -309,13 +314,6 @@ function getpipver() {
309314
}
310315

311316
function installviapip() {
312-
function pline() {
313-
local line
314-
while read line
315-
do
316-
echo "$(thisdate) $line" >> /etc/sdm/apt.log
317-
done
318-
}
319317
# $1: package name
320318
# $2: /path/to/pip3 in the venv
321319
# $3: pip install options
@@ -331,11 +329,10 @@ function installviapip() {
331329
$vpip3 install --ignore-installed $options $pkg 2>&1 | tee -a /etc/sdm/apt.log
332330
sts=$?
333331
else
334-
# Technique from https://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another/73180#73180
335-
{ { { { $vpip3 install --ignore-installed $options $pkg 2>&1; echo $? >&3; } | pline >&4; } 3>&1; } | { read xs; exit $xs; } } 4>&1
332+
runcaptureout "$vpip3 install --ignore-installed $options $pkg"
336333
sts=$?
337334
fi
338-
[[ "$poptions" =~ "nologdates" ]] && td="" || td="$(thisdate) "
335+
#[[ "$poptions" =~ "nologdates" ]] && td="" || td="$(thisdate) "
339336
echo "${td}[Done] [$sts]" >> /etc/sdm/apt.log
340337
return $sts
341338
}

0 commit comments

Comments
 (0)