Skip to content

Instantly share code, notes, and snippets.

@v6ak
Last active January 27, 2024 08:47
Show Gist options
  • Save v6ak/9e128b5a3d4ae634160bcf8bc7d2e07b to your computer and use it in GitHub Desktop.
Save v6ak/9e128b5a3d4ae634160bcf8bc7d2e07b to your computer and use it in GitHub Desktop.
Failure handler hello world addon for madduck/Docspell
#!/usr/bin/env bash
set -x
exec 2>> /tmp/debug.log
# Debug output
for i in $(seq 10); do echo >&2; done
echo ====================================================================== >> /tmp/debug.log
echo args: $# "$@" >&2
echo ITEM_ARGS_JSON >&2
cat $ITEM_ARGS_JSON >&2
echo >&2
echo ITEM_PDF_JSON >&2
cat $ITEM_PDF_JSON >&2
echo >&2
echo ITEM_DATA_JSON >&2
cat $ITEM_DATA_JSON >&2
echo >&2
echo ITEM_ORIGINAL_JSON >&2
cat $ITEM_ORIGINAL_JSON >&2
echo >&2
echo >&2
env >&2
# I can't use mktemp, because such file would be deleted by Docspell.
replacement=/tmp/asdf.$$.$RANDOM
cp "$(dirname "$(realpath "$0")")"/sample.vcf $replacement >&2
# Create the output JSON
jq '
{
"note": [
"Other keys than attachmentFix key should not be there.",
"They can cause undefined behavior. They might be ignored or used in a useless way…",
null
],
"attachmentFix": "'$replacement'"
}
' $ITEM_DATA_JSON |
tee -a /dev/fd/2 # also log it
meta:
name: "failure-handler"
version: "$VERSION"
triggers:
- failed-attachment
runner:
trivial:
enable: true
exec: addon.sh
options:
# If true, the stdout of the program is parsed into a JSON structure
# that is interpreted as actions executed by the task that runs the
# addon. If the addon runs side effects only, set this to `false`
# and the output is ignored.
#
# It is recommended to use this approach, if possible. It allows
# docspell itself to apply any changes and the addon can run
# completely isolated.
#
# Default is true.
collectOutput: true
networking: false
target/addon.zip: docspell-addon.yaml addon.sh sample.vcf
# prepare
mkdir -p target
rm -rf target/unpacked
mkdir target/unpacked
# addon.sh + sample.vcf
cp addon.sh sample.vcf target/unpacked
chmod +x target/unpacked/addon.sh
# docspell-addon.yaml
cat docspell-addon.yaml | sed 's#$$VERSION#0.$(shell date +%s)#' > target/unpacked/docspell-addon.yaml
# zip
env -C target/unpacked zip -r ../addon.zip.new .
# commit
mv target/addon.zip.new target/addon.zip
server:
mkdir -p target
echo Download the addon from http://localhost:8000/addon.zip
env -C target python3 -m http.server
##fileformat=VCFv4.0
##fileDate=20090805
##source=myImputationProgramV3.1
##reference=1000GenomesPilot-NCBI36
##phasing=partial
##INFO=<ID=NS,Number=1,Type=Integer,Description="Number of Samples With Data">
##INFO=<ID=AN,Number=1,Type=Integer,Description="Total number of alleles in called genotypes">
##INFO=<ID=AC,Number=.,Type=Integer,Description="Allele count in genotypes, for each ALT allele, in the same order as listed">
##INFO=<ID=DP,Number=1,Type=Integer,Description="Total Depth">
##INFO=<ID=AF,Number=.,Type=Float,Description="Allele Frequency">
##INFO=<ID=AA,Number=1,Type=String,Description="Ancestral Allele">
##INFO=<ID=DB,Number=0,Type=Flag,Description="dbSNP membership, build 129">
##INFO=<ID=H2,Number=0,Type=Flag,Description="HapMap2 membership">
##FILTER=<ID=q10,Description="Quality below 10">
##FILTER=<ID=s50,Description="Less than 50% of samples have data">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##FORMAT=<ID=GQ,Number=1,Type=Integer,Description="Genotype Quality">
##FORMAT=<ID=DP,Number=1,Type=Integer,Description="Read Depth">
##FORMAT=<ID=HQ,Number=2,Type=Integer,Description="Haplotype Quality">
##ALT=<ID=DEL:ME:ALU,Description="Deletion of ALU element">
##ALT=<ID=CNV,Description="Copy number variable region">
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT NA00001 NA00002 NA00003
19 111 . A C 9.6 . . GT:HQ 0|0:10,10 0|0:10,10 0/1:3,3
19 112 . A G 10 . . GT:HQ 0|0:10,10 0|0:10,10 0/1:3,3
20 14370 rs6054257 G A 29 PASS NS=3;DP=14;AF=0.5;DB;H2 GT:GQ:DP:HQ 0|0:48:1:51,51 1|0:48:8:51,51 1/1:43:5:.,.
20 17330 . T A 3 q10 NS=3;DP=11;AF=0.017 GT:GQ:DP:HQ 0|0:49:3:58,50 0|1:3:5:65,3 0/0:41:3:.,.
20 1110696 rs6040355 A G,T 67 PASS NS=2;DP=10;AF=0.333,0.667;AA=T;DB GT:GQ:DP:HQ 1|2:21:6:23,27 2|1:2:0:18,2 2/2:35:4:.,.
20 1230237 . T . 47 PASS NS=3;DP=13;AA=T GT:GQ:DP:HQ 0|0:54:.:56,60 0|0:48:4:51,51 0/0:61:2:.,.
20 1234567 microsat1 G GA,GAC 50 PASS NS=3;DP=9;AA=G;AN=6;AC=3,1 GT:GQ:DP 0/1:.:4 0/2:17:2 1/1:40:3
20 1235237 . T . . . . GT 0/0 0|0 ./.
X 10 rsTest AC A,ATG 10 PASS . GT 0 0/1 0|2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment