za3k / qr-backup

Paper backup of files using QR codes
Other
128 stars 12 forks source link

Port to OS X #37

Closed za3k closed 1 month ago

za3k commented 2 years ago

This might work already. Find out.

vonProteus commented 1 month ago

after runing this

#!/bin/bash -e

rm -rf ./venv || echo no venv

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

echo setup ok

./qr-backup --verbose --encrypt secretPass Dockerfile
echo backup done 

./qr-backup --restore --verbose --encrypt secretPass Dockerfile.qr.pdf
echo backup restored
result ```shell Collecting pillow (from -r requirements.txt (line 1)) Using cached pillow-10.4.0-cp312-cp312-macosx_11_0_arm64.whl.metadata (9.2 kB) Collecting qrcode (from -r requirements.txt (line 2)) Using cached qrcode-7.4.2-py3-none-any.whl.metadata (17 kB) Collecting reedsolo (from -r requirements.txt (line 3)) Using cached reedsolo-1.7.0-py3-none-any.whl.metadata (23 kB) Collecting typing-extensions (from qrcode->-r requirements.txt (line 2)) Using cached typing_extensions-4.12.2-py3-none-any.whl.metadata (3.0 kB) Collecting pypng (from qrcode->-r requirements.txt (line 2)) Using cached pypng-0.20220715.0-py3-none-any.whl.metadata (13 kB) Using cached pillow-10.4.0-cp312-cp312-macosx_11_0_arm64.whl (3.4 MB) Using cached qrcode-7.4.2-py3-none-any.whl (46 kB) Using cached reedsolo-1.7.0-py3-none-any.whl (32 kB) Using cached pypng-0.20220715.0-py3-none-any.whl (58 kB) Using cached typing_extensions-4.12.2-py3-none-any.whl (37 kB) Installing collected packages: reedsolo, pypng, typing-extensions, pillow, qrcode Successfully installed pillow-10.4.0 pypng-0.20220715.0 qrcode-7.4.2 reedsolo-1.7.0 typing-extensions-4.12.2 setup ok INFO: Original arguments were: [] INFO: Command arguments parsed. Equivalent command: qr-backup --qr-version 10 --dpi 300 --scale 5 --error-correction L --page 500 600 --compress --filename Dockerfile --encrypt ??? --use-erasure-coding --shuffle Dockerfile.qr.pdf INFO: read file Dockerfile (sha d88c43acca8a3aed93d4be1a487186f361771e352d51ff9b0cbba034869d0a21, 0.825KB) INFO: generate_erasure: perform self-test INFO: generate_erasure: deleted first few symbols, restore works fine INFO: Restore command is: sort -u | grep "^N" | cut -c6- | base64 -d | tail -c +5 | head -c 505 | gpg --decrypt | gunzip INFO: 6 qr codes (at version 10) total INFO: QR code (including label) is: 285x285px INFO: Page is: 2083x2500px INFO: 6 x 6 qr codes (at version 10) per page. 1 pages total INFO: 509 compressed bytes in 1 page(s). 0.82KB/page including compression, 0.51KB/page without compression INFO: 4.95KB/page theory without compression) INFO: Outputting: Dockerfile.qr.pdf INFO: Restore command used in Linux CLI test: sort -u | grep "^N" | cut -c6- | base64 -d | tail -c +5 | head -c 505 | gpg --decrypt --no-symkey-cache --batch --passphrase 'secretPass' | gunzip INFO: self-test using files INFO: Performing linux CLI restore check... INFO: Linux CLI command was: convert -density 600 Dockerfile.qr.pdf tif:- | zbarimg --raw -q -Sdisable -Sqrcode.enable - | sort -u | grep "^N" | cut -c6- | base64 -d | tail -c +5 | head -c 505 | gpg --decrypt --no-symkey-cache --batch --passphrase 'secretPass' | gunzip | cmp Dockerfile INFO: Linux CLI exit code was: True INFO: Test command was: convert -density 600 Dockerfile.qr.pdf tif:- | zbarimg --raw -q -Sdisable -Sqrcode.enable - | wc -l INFO: Performing qr-backup restore check... INFO: Self-test command was: ['python3', './qr-backup', '--restore', '--sha256', 'd88c43acca8a3aed93d4be1a487186f361771e352d51ff9b0cbba034869d0a21', 'Dockerfile.qr.pdf', '--encrypt', 'secretPass'] INFO: Self-test exit code was: True INFO: Read 6/6 qrs (100.00%) INFO: Automatic digital restore verification succeeded. backup done CRITICAL: WARNING: Printing file directly to interactive stdout. You probably want to run qr-backup >filename. Press Control-C to exit. INFO: image restore selected INFO: Converting to tif: Dockerfile.qr.pdf INFO: Read new code b'N2' INFO: 1/4? complete INFO: Read new code b'P1' INFO: 2/4? complete INFO: Read new code b'N1' INFO: 3/4? complete INFO: Read new code b'P2' INFO: 4/4? complete INFO: 4/4? complete INFO: restored sha256sum: d88c43acca8a3aed93d4be1a487186f361771e352d51ff9b0cbba034869d0a21 sha256sum was as follows, please check against your paper backup: d88c43acca8a3aed93d4be1a487186f361771e352d51ff9b0cbba034869d0a21 FROM python:3.12 RUN apt-get update \ && apt-get install -y \ fonts-dejavu \ ghostscript \ gnupg2 \ imagemagick \ python3-pillow \ python3-qrcode \ zbar-tools \ sed \ && printf "deb http://http.us.debian.org/debian/ testing non-free contrib main\n" > /etc/apt/sources.list.d/testing.list \ && apt-get update \ && apt-get install -y -t testing \ python3-reedsolo \ && apt-get autopurge -y \ && apt-get autoclean -y \ && sed -i 's///g' /etc/ImageMagick-6/policy.xml COPY ./requirements.txt /src/ RUN pip install -r /src/requirements.txt COPY ./ /src RUN cd /src \ && make install WORKDIR /work ENTRYPOINT [ "qr-backup" ] CMD [ "--help" ] backup restored ```

so i would say its work under mac os after installing font from repo (DejaVuSansMono.ttf) and zbar

za3k commented 1 month ago

Thanks. Could you run the test suite, to make sure everything works?

Then I can document how to get it working. Also I would love a link to show people how to install the font. I don't have a mac so I'm not sure how it works.

vonProteus commented 1 month ago

to install font you double click it and press install font ^_^

im afraid tests fails

make test ```shell python3 tests/test.py backup-regression 100b zeros 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 result: 79e5f17c7b76c001df65a52760e0d2d06ad7ceafed1d8924f782cc662e305f93 != ed26a865598955e799e310c3bb38549b68ea951a11af2ae9c3a887ab427e9288 correct-restore 100b zeros 2s backup-regression default options 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --dpi 300 --compress --erasure-coding --filename file --instructions page --num-copies 1 --output - --page 500 600 --qr-version 10 --scale 5 --shuffle result: 79e5f17c7b76c001df65a52760e0d2d06ad7ceafed1d8924f782cc662e305f93 != ed26a865598955e799e310c3bb38549b68ea951a11af2ae9c3a887ab427e9288 correct-restore default options 2s backup-regression --no-compress 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --no-compress result: d361cda72bc477e721dde1ad8553a27d869b2dd48ef95d4869932ab3d94003c5 != af282809a01c4a163372f9237b07e36e779f039c383a9b324d149674b07cfb40 correct-restore --no-compress 2s backup-regression --dpi 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --dpi 50 result: 78a3960961f8f981ddc56ebcc75416fdee8dabd137e5ed84e60ddf01e9dd331a != 0b9bab6921925979a3c4e88e59e51e6d63b5c0830a7c0ff77a7aad2475b4502c correct-restore --dpi 3s correct-restore --encrypt 3s correct-restore --encrypt-print-passphrase 3s backup-regression --no-erasure-coding 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --no-erasure-coding result: 16a052e049edfa8896b7af5bdf471e1c6e15a75418a6d939fff006b71ae8edf4 != c0a08d86b71280517d1ff3cf56c7bbb998fdece72e3f996546877b1ca1df485e correct-restore --no-erasure-coding 2s too-fast --no-erasure-coding 2s, <2^1 backup-regression --error-correction L 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --error-correction L result: a732511a8980c17c1b4a46dc5e0065807496c6f701e293526228740a26731c4d != b1043946459cb7367baa4214edd062671f6c78a6937e0287c7ca2f832ceacece correct-restore --error-correction L 2s backup-regression --error-correction Q 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --error-correction Q result: 2dec863ef38d43505262451783946e6e6f119d08c4151eb7d95940030ddc6e0e != a3efa49a970267cadb5d4dd3f0fcb67d69bc5069d51809f16754f06dc74de286 correct-restore --error-correction Q 2s backup-regression --error-correction H 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --error-correction H result: 7d90383a1671d3baab25f19121675e19be5eb5547ed950ed90b8307dcb3803f3 != 2caa340d11e530a7e770caf71a3d0efee85defe4f5aec315b9c00bda6658089f correct-restore --error-correction H 2s backup-regression --filename 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --filename TEST_FILENAME result: 49d4ccfe1e861bcc5f7153fc368ae420f244796b5969d5d44b153b7672b5b9c1 != 9a61e8185bfcf9b9c3d2901baea7430b448ed6e0e03759619045b61a38e29d4e correct-restore --filename 2s backup-regression --instructions both 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --instructions both result: 046ab44faeeaa995a8fb7a1aaa4478fd2c63907f35e6055e8706c7f3ecf998cb != 6ad4661009ebda82e6618f81caaa2fa43df1ac7d4a938ef3a7818588a8cc3c6b correct-restore --instructions both 3s backup-regression --instructions cover 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --instructions cover result: b679d6129ee181aeb48daaf417028fc37afa1410b88f0a2e6dd997cb7e94686a != 452f3e23a7f71e1f9d1892d64910ff185f12799dc5093f29f085fe003bd69629 correct-restore --instructions cover 3s backup-regression --instructions none 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --instructions none result: f2997ebd8eaba6078b38b04c09410536ec88f7317d028989c80b8a0df831ad11 != c66fdd3e1a7fd3107f95daab2d07b65cfe5e4b679fef5b2dca73d004baee494d correct-restore --instructions none 2s backup-regression --note (1) 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --note A result: 1a305390efc66f4ed3e2e2e1f0a98e21ca060f34de16965fd9922d61841177c9 != 6cdf1ba777d47c68a92eb1f49f35b8bd186431e639d560b6f1bacee2a3ee03e3 correct-restore --note (1) 2s backup-regression --note (2) 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --note A --note B result: 475d95ef09ebea1ec60b2557a977ad0b3dfcf46affd3edc2028ca07cfd62bb5d != 8085233b46a4c61477fae0e9abea0c7f751f829763eaeaee36a3de3e6046ad9d correct-restore --note (2) 2s backup-regression --num-copies 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --num-copies 3 result: d16ed2e01b6d21decca35137f8addcae21b4e277246d3de695ec816944351255 != 7c705557390d346eb87bb08ea437ed8a42198b2ceeea296fbf891c1b20c695e2 correct-restore --num-copies 2s backup-regression --page 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --page 100 200 result: 109b0a46242c7ad3e2d32377df23e64b6e9d06e0288258856df318535121294d != 8b3cfdb1e5b07ec72c552f6ab95ab39c04d419d23afad31b7b78fda395d435e9 correct-restore --page 1s backup-regression --qr-version 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --qr-version 15 result: a1532ec5c01d6876e4a2e06ad7ce6df26f01c4df9f77c8650a32abd4911b6c40 != 1add32b1947948f32d6baab525a5621930a46cc2438012953b8992e930adea70 correct-restore --qr-version 2s backup-regression --scale 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --scale 10 result: 99e8ae15c1f5ec5e807e1f498c3cfab3428871d90383c88f1dd6224cf3fc3e9d != 4cc28752038be68e69bd9b52ef3ab1aa310ce216be7af86e5cdfa0582c61e9b1 correct-restore --scale 2s backup-regression --no-shuffle 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --no-shuffle result: 830517c77f7323cb2270cef150482526702e834a42966c7cd3317d3bf83e8fa7 != 10559366e0b5590660838b5c7893f1a3fb22fefab39e943dc667cfc34c82d6c9 correct-restore --no-shuffle 2s backup-regression 1K zeros 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 result: 126e7642ebf8705a75de9dd7ef4b5c8e93aefd7028782dfc1cb209a9c218dfbe != 0f5da5bd812284e6a18f974af3187b442c4fed0cc595c231b96a5bdd4b0cd965 correct-restore 1K zeros 2s backup-regression 10K zeros 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 result: de53663bcdf037bd239d20f5bf58f2fc3c8ba8e0b818fc7e42311c19111df688 != 68328734a28dcc05d9884641c591f0592920f5efb861062a17877a0557400e0c correct-restore 10K zeros 2s backup-regression 100K zeros 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 result: f0613c8f9f33fe21f63ee5813ff927156472b7f358d89613dbc53adf036dcf23 != b3fa3458bdf24863d1450d0c3b407c2b7f4847c2dc9d841b9a88c20e89f720b1 correct-restore 100K zeros 2s backup-regression 100b random 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 result: 75a49a7263c21d2e1ad4196071f3530c5c9cf7efd26e31eca49110b8bc1bb967 != 59512f3c17bdeb122b652c4fb130e4094f21159d965bea73847177ac51237417 correct-restore 100b random 2s backup-regression 1K random 1s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 result: 4f670108ba96fee8be13f20b9ed4a18cd4bc7228742de1c75e9dbedad2fe1dff != 7f9aeeea1ba41b6f6044bdeda64e87b626942dbead4ba409bc1a3f2195b91a2a correct-restore 1K random 2s backup-regression 10K random 2s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 result: 38fa91423204a1e7f1e27e8de8d82a8c33966f507e57e269c561667f57f6c8fa != 63222f94ba30f2e887deb0a85ab032d0fe5c6e87737552d5b151c0b0556888b0 too-fast 10K random 2s, <2^1 correct-restore 10K random 6s backup-regression 50K random 7s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 result: 744e4e2fb3a95634ec99b8135fbd6e2e99a932690dc286f689427c33609a24a6 != 4198a84b9a35f62108c26bd698295d1937d7257382e47db6f79ac8c8613a29a4 too-fast 50K random 7s, <2^3 correct-restore 50K random 31s too-fast 50K random 31s, <2^5 backup-regression 1K zeros, self-check 5s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --no-skip-checks result: 126e7642ebf8705a75de9dd7ef4b5c8e93aefd7028782dfc1cb209a9c218dfbe != 0f5da5bd812284e6a18f974af3187b442c4fed0cc595c231b96a5bdd4b0cd965 too-fast 1K zeros, self-check 5s, <2^3 correct-restore 1K zeros, self-check 2s backup-regression 1K random, self-check 5s command: python3 qr-backup --skip-checks - --backup-date 2022-09-22 --no-skip-checks result: 4f670108ba96fee8be13f20b9ed4a18cd4bc7228742de1c75e9dbedad2fe1dff != 7f9aeeea1ba41b6f6044bdeda64e87b626942dbead4ba409bc1a3f2195b91a2a too-fast 1K random, self-check 5s, <2^3 correct-restore 1K random, self-check 2s NEW BLESSED_OUTPUT = { '100b zeros': '79e5f17c7b76c001df65a52760e0d2d06ad7ceafed1d8924f782cc662e305f93', 'default options': '79e5f17c7b76c001df65a52760e0d2d06ad7ceafed1d8924f782cc662e305f93', '--no-compress': 'd361cda72bc477e721dde1ad8553a27d869b2dd48ef95d4869932ab3d94003c5', '--dpi': '78a3960961f8f981ddc56ebcc75416fdee8dabd137e5ed84e60ddf01e9dd331a', '--no-erasure-coding': '16a052e049edfa8896b7af5bdf471e1c6e15a75418a6d939fff006b71ae8edf4', '--error-correction L': 'a732511a8980c17c1b4a46dc5e0065807496c6f701e293526228740a26731c4d', '--error-correction Q': '2dec863ef38d43505262451783946e6e6f119d08c4151eb7d95940030ddc6e0e', '--error-correction H': '7d90383a1671d3baab25f19121675e19be5eb5547ed950ed90b8307dcb3803f3', '--filename': '49d4ccfe1e861bcc5f7153fc368ae420f244796b5969d5d44b153b7672b5b9c1', '--instructions both': '046ab44faeeaa995a8fb7a1aaa4478fd2c63907f35e6055e8706c7f3ecf998cb', '--instructions cover': 'b679d6129ee181aeb48daaf417028fc37afa1410b88f0a2e6dd997cb7e94686a', '--instructions none': 'f2997ebd8eaba6078b38b04c09410536ec88f7317d028989c80b8a0df831ad11', '--note (1)': '1a305390efc66f4ed3e2e2e1f0a98e21ca060f34de16965fd9922d61841177c9', '--note (2)': '475d95ef09ebea1ec60b2557a977ad0b3dfcf46affd3edc2028ca07cfd62bb5d', '--num-copies': 'd16ed2e01b6d21decca35137f8addcae21b4e277246d3de695ec816944351255', '--page': '109b0a46242c7ad3e2d32377df23e64b6e9d06e0288258856df318535121294d', '--qr-version': 'a1532ec5c01d6876e4a2e06ad7ce6df26f01c4df9f77c8650a32abd4911b6c40', '--scale': '99e8ae15c1f5ec5e807e1f498c3cfab3428871d90383c88f1dd6224cf3fc3e9d', '--no-shuffle': '830517c77f7323cb2270cef150482526702e834a42966c7cd3317d3bf83e8fa7', '1K zeros': '126e7642ebf8705a75de9dd7ef4b5c8e93aefd7028782dfc1cb209a9c218dfbe', '10K zeros': 'de53663bcdf037bd239d20f5bf58f2fc3c8ba8e0b818fc7e42311c19111df688', '100K zeros': 'f0613c8f9f33fe21f63ee5813ff927156472b7f358d89613dbc53adf036dcf23', '100b random': '75a49a7263c21d2e1ad4196071f3530c5c9cf7efd26e31eca49110b8bc1bb967', '1K random': '4f670108ba96fee8be13f20b9ed4a18cd4bc7228742de1c75e9dbedad2fe1dff', '10K random': '38fa91423204a1e7f1e27e8de8d82a8c33966f507e57e269c561667f57f6c8fa', '50K random': '744e4e2fb3a95634ec99b8135fbd6e2e99a932690dc286f689427c33609a24a6', '1K zeros, self-check': '126e7642ebf8705a75de9dd7ef4b5c8e93aefd7028782dfc1cb209a9c218dfbe', '1K random, self-check': '4f670108ba96fee8be13f20b9ed4a18cd4bc7228742de1c75e9dbedad2fe1dff', } 28 failures make: *** [test] Error 1 ```
b8two commented 1 month ago

Instead of specifiying the font,

PIL.ImageFont.truetype("DejaVuSansMono.ttf"

Could you by default, load the default and if a font is specified, then use that? PIL.ImageFont.load_default()

This way you can drop a depenancy