Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a check to verify that all QR codes were found (none are skipped) #11

Open
jose1711 opened this issue Dec 15, 2019 · 4 comments

Comments

@jose1711
Copy link

Even with a perfect QR code it could happen that zbarimg fails to detect it (mchehab/zbar#65). Since the codes are numbered it would be nice if paperrestore.sh contains a check whether there is no gap in the sequence.

@intra2net
Copy link
Collaborator

Good idea.

We tried to keep the restore code very simplistic so that it can easily be ported to other systems (think restoring an old backup several years in the future).

I think to implement it we'd have to break the pipe in paperrestore after the sort, store the sorted results of zbarimg in a tempfile and then check the contents (compare wc -l vs. the barcode number in the last line).

Or do you see a way to do it without a tempfile?

@jose1711
Copy link
Author

One idea would be to use awk. With NR special variable it could do a check for each line - whether it matches the number at the beginning of each line. The next question would be whether the error is just reported and processing terminated, data is skipped or empty values are filled with zeroes.

@jose1711
Copy link
Author

Here a POC:

/usr/bin/zbarimg --raw -Sdisable -Sqrcode.enable "$SCANNEDFILE" 2>/dev/null \
    | sed -e "s/\^/\x0/g" \
    | sort -z -n \
    | awk 'BEGIN{ORS="\0"; RS="\0"} $1 {lines[$1]=$0; last=$1} END{printf "%s", "\0"; for(i=1; i<=last;i++){if (lines[i]){print lines[i]} else {print i" MISSING_DATA\n"}}}' \
    | sed ':a;N;$!ba;s/\n\x0[0-9]* //g;s/\x0[0-9]* //g;s/\n\x0//g'

@anarcat
Copy link

anarcat commented Mar 3, 2023

i agree with @intra2net that the restore code should be simple, or at least that there should be a simple version of it, ideally printed alongside the document (#16).

that said, if we're going to add awk to the already complex and difficult to read pipeline here, i think we'd be better serve by adding a restore option to the python program itself, keeping a fallback copy as a shell script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants