add tox_savefile_test.bash

This commit is contained in:
emdee 2022-10-03 01:13:26 +00:00
parent 337bf49eeb
commit dee30e905f
3 changed files with 124 additions and 4 deletions

View File

@ -3,7 +3,7 @@
Read and manipulate tox profile files. It started as a simple script from
<https://stackoverflow.com/questions/30901873/what-format-are-tox-files-stored-in>
For the moment logging_tox_savefile.py just reads a Tox profile and
For the moment tox_savefile.py just reads a Tox profile and
prints to stdout various things that it finds. Then it writes what it
found in YAML to stderr. Later it can be extended to print out JSON
or YAML, and then extended to accept JSON or YAML to write a profile.
@ -22,7 +22,7 @@ to stdout
a profile
```
usage: logging_tox_savefile.py [-h] [--output OUTPUT]
usage: tox_savefile.py [-h] [--output OUTPUT]
[--command {info,decrypt,nodes}]
[--indent INDENT]
[--info {info,repr,yaml,json,pprint,nmap_udp,nmap_tcp}]

View File

@ -421,7 +421,7 @@ def process_chunk(index, state, oArgs=None):
section,num,key,val = oArgs.edit.split(',',3)
diff = index - len(bOUT)
if diff > 0:
if bDEBUG and diff > 0:
LOG.warn(f"PROCESS_CHUNK {label} index={index} bOUT={len(bOUT)} delta={diff} length={length}")
elif bDEBUG:
LOG.trace(f"PROCESS_CHUNK {label} index={index} bOUT={len(bOUT)} delta={diff} length={length}")
@ -841,7 +841,7 @@ if __name__ == '__main__':
LOG.info(f"{oArgs.info}ing iRet={iRet} to {oArgs.output}")
elif oArgs.info == 'json' and json:
LOG.debug(f"{oArgs.command} saving to {oArgs.output}")
oStream = open(oArgs.output, 'wb', encoding=None)
oStream = open(oArgs.output, 'wt', encoding=sENC)
json.dump(aOUT, oStream, indent=oArgs.indent)
if oStream.write('\n') > 0: iRet = 0
LOG.info(f"{oArgs.info}ing iRet={iRet} to {oArgs.output}")

120
tox_savefile_test.bash Executable file
View File

@ -0,0 +1,120 @@
#!/bin/sh -e
# -*- mode: sh; fill-column: 75; tab-width: 8; coding: utf-8-unix -*-
PREFIX=/o/var/local/src
EXE=python3.sh
WRAPPER=$PREFIX/toxygen_wrapper
[ -f /usr/local/bin/usr_local_tput.bash ] && \
. /usr/local/bin/usr_local_tput.bash || {
DEBUG() { echo DEBUG $* ; }
INFO() { echo INFO $* ; }
WARN() { echo WARN $* ; }
ERROR() { echo ERROR $* ; }
}
set -- -e
target=$PREFIX/tox_profile/logging_tox_savefile.py
[ -s $target ] || exit 1
tox=$HOME/.config/tox/toxic_profile.tox
[ -s $tox ] || exit 2
json=$HOME/.config/tox/DHTnodes.json
[ -s $json ] || exit 3
[ -d $WRAPPER ] || { ERROR wrapper is required https://git.plastiras.org/emdee/toxygen_wrapper ; exit 5 ; }
export PYTHONPATH=$WRAPPER
which jq > /dev/null && HAVE_JQ=1 || HAVE_JQ=0
which nmap > /dev/null && HAVE_NMAP=1 || HAVE_NMAP=0
sudo rm -f /tmp/toxic_profile.* /tmp/toxic_nodes.*
[ "$HAVE_JQ" = 0 ] || \
jq . < $json >/tmp/toxic_nodes.json || { ERROR jq $json ; exit 4 ; }
[ -f /tmp/toxic_nodes.json ] || cp -p $json /tmp/toxic_nodes.json
json=/tmp/toxic_nodes.json
# required password
INFO decrypt /tmp/toxic_profile.bin
$EXE $target --command decrypt --output /tmp/toxic_profile.bin $tox || exit 11
[ -s /tmp/toxic_profile.bin ] || exit 12
tox=/tmp/toxic_profile.bin
INFO info $tox
$EXE $target --command info --info info $tox 2>/tmp/toxic_profile.info || exit 13
[ -s /tmp/toxic_profile.info ] || exit 14
INFO /tmp/toxic_profile.save
$EXE $target --command info --info save --output /tmp/toxic_profile.save $tox 2>/dev/null || exit 15
[ -s /tmp/toxic_profile.save ] || exit 16
for the_tox in /tmp/toxic_profile.save ; do
the_base=`echo $the_tox | sed -e 's/.save$//' -e 's/.tox$//'`
for elt in json yaml pprint repr ; do
INFO $the_base.$elt
[ "$DEBUG" != 1 ] || echo DEBUG $EXE $target \
--command info --info $elt \
--output $the_base.$elt $the_tox
$EXE $target --command info --info $elt \
--output $the_base.$elt $the_tox 2>/dev/null || exit 20
[ -s $the_base.$elt ] || exit 21
done
$EXE $target --command edit --edit help $the_tox 2>/dev/null || exit 22
INFO $the_base.edit1 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic'
$EXE $target --command edit --edit 'STATUSMESSAGE,.,Status_message,Toxxed on Toxic' \
--output $the_base.edit1.tox $the_tox 2>&1|grep EDIT
[ -s $the_base.edit1.tox ] || exit 23
$EXE $target --command info $the_base.edit1.tox 2>&1|grep Toxxed || exit 24
INFO $the_base.edit2 'NAME,.,Nick_name,FooBar'
$EXE $target --command edit --edit 'NAME,.,Nick_name,FooBar' \
--output $the_base.edit2.tox $the_tox 2>&1|grep EDIT
[ -s $the_base.edit2.tox ] || exit 25
$EXE $target --command info $the_base.edit2.tox 2>&1|grep FooBar || exit 26
done
the_tox=$json
the_base=`echo $the_tox | sed -e 's/.save$//' -e 's/.json$//'`
[ "$HAVE_JQ" = 0 ] || \
for nmap in select_tcp select_udp select_version ; do
INFO $the_base.$nmap
$EXE $target --command nodes --nodes $nmap \
--output $the_base.$nmap.json $the_tox || exit 31
[ -s $the_base.$nmap.json ] || exit 32
done
grep '"status_tcp": false' $the_base.select_tcp.json && exit 33
grep '"status_udp": false' $the_base.select_udp.json && exit 34
ls -l /tmp/toxic_profile.* /tmp/toxic_nodes.*
/usr/local/bin/proxy_ping_test.bash tor || exit 0
the_tox=$tox
the_base=`echo $the_tox | sed -e 's/.save$//' -e 's/.tox$//'`
[ "$HAVE_JQ" = 0 ] || \
[ "$HAVE_NMAP" = 0 ] || \
for nmap in nmap_tcp nmap_udp nmap_onion ; do
INFO $the_base.$nmap
$EXE $target --command info --info $nmap \
--output $the_base.$nmap $the_tox.json || exit 40
[ -s $the_base.$nmap.json ] || exit 41
done
the_json=$json
the_base=`echo $json | sed -e 's/.save$//' -e 's/.json$//'`
[ "$HAVE_JQ" = 0 ] || \
for nmap in nmap_tcp nmap_udp ; do
INFO $the_base.$nmap
$EXE $target --command nodes --nodes $nmap \
--output $the_base.$nmap.json $the_json || exit 51
[ -s $the_base.$nmap.json ] || exit 52
done
exit 0