From b56c4dad1c0a9a63484e563bc6e282a0cd6c92d6 Mon Sep 17 00:00:00 2001 From: nodlek-ctrl Date: Wed, 12 Apr 2023 17:43:24 +1000 Subject: [PATCH 01/10] Fix --- README.md | 12 ++++++++++++ printer.py | 2 ++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 55337f3..69b7dbc 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,18 @@ On Arch Linux based distros you may install `bluez` first, as it may not be inst sudo pacman -S bluez bluez-utils ``` +You may or may not need to install ImageMagick and Ghostscript, depending on your distro. +```bash +sudo apt install imagemagick ghostscript +``` +Or the package manager of your distro. + +Extra configuration is required for ImageMagick to work. Because IM is made for external webserver, a strict security policy is applied. You need to add the following line to `/etc/ImageMagick-6/policy.xml` before ``: +```xml + +``` +Because this script is only accesible by localhost, or at most your local network, this is safe. + *Packaging is also on the way!* ### MacOS diff --git a/printer.py b/printer.py index 08eb97c..701b065 100644 --- a/printer.py +++ b/printer.py @@ -567,6 +567,8 @@ def fallback_program(*programs): return None _MagickExe = fallback_program('magick', 'magick.exe', 'convert', 'convert.exe') +if _MagickExe is None: + error('ImageMagic not found. Please install and configure as per readme.') def magick_text(stdin, image_width, font_size, font_family): 'Pipe an io to ImageMagick for processing text to image, return output io' From d53bbef482dcf2e93339f021b665c345e5172f81 Mon Sep 17 00:00:00 2001 From: nodlek-ctrl Date: Thu, 13 Apr 2023 11:51:53 +1000 Subject: [PATCH 02/10] begin localising the IM error --- printer.py | 2 +- www/lang/en-US.json | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/printer.py b/printer.py index 429801b..06b35a3 100644 --- a/printer.py +++ b/printer.py @@ -593,7 +593,7 @@ def fallback_program(*programs): _MagickExe = fallback_program('magick', 'magick.exe', 'convert', 'convert.exe') if _MagickExe is None: - error('ImageMagic not found. Please install and configure as per readme.') + error(i18n("imagemagick-not-found")) def magick_text(stdin, image_width, font_size, font_family): 'Pipe an io to ImageMagick for processing text to image, return output io' diff --git a/www/lang/en-US.json b/www/lang/en-US.json index dd15e87..5102b76 100644 --- a/www/lang/en-US.json +++ b/www/lang/en-US.json @@ -159,5 +159,7 @@ "test-unknown-device": "Test Unknown Device", "scan": "Scan", "now-will-scan-for-all-bluetooth-devices-nearby": "Scan set to search for all bluetooth devides nearby.", - "pf2-font-not-found-or-broken-0": "PF2 font not found or broken: '{0}'" + "pf2-font-not-found-or-broken-0": "PF2 font not found or broken: '{0}'", + "imagemagick-not-found": "ImageMagick not found, please install it before trying any command line hackery." + } \ No newline at end of file From 705206b106f92c9529348097ac50e260eb38754d Mon Sep 17 00:00:00 2001 From: nodlek-ctrl Date: Thu, 13 Apr 2023 12:10:52 +1000 Subject: [PATCH 03/10] localise imagemagick error --- www/lang/lolcat.json | 4 +++- www/lang/zh-CN.json | 3 ++- www/lang/zh-HK.json | 3 ++- www/lang/zh-Hant-CN.json | 3 ++- www/lang/zh-TW.json | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/www/lang/lolcat.json b/www/lang/lolcat.json index b58e117..d1a0141 100644 --- a/www/lang/lolcat.json +++ b/www/lang/lolcat.json @@ -137,5 +137,7 @@ "test-unknown-device": "I HAV STRENGE KITTE", "now-will-scan-for-all-bluetooth-devices-nearby": "WIL FIND ALL THINY KITTE OR NOT", "scan": "FIND", - "pf2-font-not-found-or-broken-0": "KITTE FONT LOST OR DEAD> {0}" + "pf2-font-not-found-or-broken-0": "KITTE FONT LOST OR DEAD> {0}", + "image-magick-not-found": "IMAGEMAGICK NOT FINDZ, PLZ INSTALL IT BEFORE TRYIN ANY COMMAND LINE FEATUREZ." + } diff --git a/www/lang/zh-CN.json b/www/lang/zh-CN.json index 2b565ca..c900570 100644 --- a/www/lang/zh-CN.json +++ b/www/lang/zh-CN.json @@ -149,5 +149,6 @@ "javascript-catprinter-description": "猫咪打印机 (Cat-Printer) 主脚本", "free-software": "自由软件", "free-software-description": "尊重您计算自由的软件。", - "pf2-font-not-found-or-broken-0": "PF2 字体丢失或损坏:'{0}'" + "pf2-font-not-found-or-broken-0": "PF2 字体丢失或损坏:'{0}'", + "image-magick-not-found": "未找到 ImageMagick,请在尝试任何命令行功能之前安装它。" } \ No newline at end of file diff --git a/www/lang/zh-HK.json b/www/lang/zh-HK.json index 77a71e7..eae6d33 100644 --- a/www/lang/zh-HK.json +++ b/www/lang/zh-HK.json @@ -149,5 +149,6 @@ "javascript-catprinter-description": "貓咪打印機 (Cat-Printer) 主腳本", "free-software": "自由軟件", "free-software-description": "尊重您計算自由的軟件。", - "pf2-font-not-found-or-broken-0": "PF2 字體丟失或損壞:'{0}'" + "pf2-font-not-found-or-broken-0": "PF2 字體丟失或損壞:'{0}'", + "imagemagick-not-found": "未找到 ImageMagick,請在嘗試任何命令行功能之前安裝它。" } \ No newline at end of file diff --git a/www/lang/zh-Hant-CN.json b/www/lang/zh-Hant-CN.json index b4f6eb5..205021b 100644 --- a/www/lang/zh-Hant-CN.json +++ b/www/lang/zh-Hant-CN.json @@ -149,5 +149,6 @@ "javascript-catprinter-description": "貓咪打印機 (Cat-Printer) 主腳本", "free-software": "自由軟件", "free-software-description": "尊重您計算自由的軟件。", - "pf2-font-not-found-or-broken-0": "PF2 字體丟失或損壞:'{0}'" + "pf2-font-not-found-or-broken-0": "PF2 字體丟失或損壞:'{0}'", + "imagemagick-not-found": "未找到 ImageMagick,請在嘗試任何命令行功能之前安裝它。" } \ No newline at end of file diff --git a/www/lang/zh-TW.json b/www/lang/zh-TW.json index 02f946b..011a2b3 100644 --- a/www/lang/zh-TW.json +++ b/www/lang/zh-TW.json @@ -149,5 +149,5 @@ "javascript-catprinter-description": "貓咪印表機 (Cat-Printer) 主指令碼", "free-software": "自由軟體", "free-software-description": "尊重您計算自由的軟體。", - "pf2-font-not-found-or-broken-0": "PF2 字型丟失或損壞:'{0}'" + "pf2-font-not-found-or-broken-0": "未找到 ImageMagick,請在嘗試任何命令行功能之前安裝它。" } \ No newline at end of file From 86d8b2d55ccb328e362d2fb4381f4871f4b335c6 Mon Sep 17 00:00:00 2001 From: nodlek-ctrl Date: Thu, 13 Apr 2023 12:32:09 +1000 Subject: [PATCH 04/10] put the IM config in a expandable box thingo --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 69b7dbc..4dfb623 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,9 @@ On Arch Linux based distros you may install `bluez` first, as it may not be inst ```bash sudo pacman -S bluez bluez-utils ``` - +
+Further steps +You may want to use the command line interface for hackiness... … You may or may not need to install ImageMagick and Ghostscript, depending on your distro. ```bash sudo apt install imagemagick ghostscript @@ -93,6 +95,7 @@ Extra configuration is required for ImageMagick to work. Because IM is made for ``` Because this script is only accesible by localhost, or at most your local network, this is safe. +
*Packaging is also on the way!* From 9cba46a41661ec6f46ba8dcf34596faee383b61d Mon Sep 17 00:00:00 2001 From: nodlek-ctrl Date: Thu, 13 Apr 2023 12:41:13 +1000 Subject: [PATCH 05/10] fix expander --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4dfb623..34beb6e 100644 --- a/README.md +++ b/README.md @@ -83,12 +83,13 @@ sudo pacman -S bluez bluez-utils ```
Further steps -You may want to use the command line interface for hackiness... … +You may want to use the command line interface for hackiness... + You may or may not need to install ImageMagick and Ghostscript, depending on your distro. + ```bash sudo apt install imagemagick ghostscript ``` -Or the package manager of your distro. Extra configuration is required for ImageMagick to work. Because IM is made for external webserver, a strict security policy is applied. You need to add the following line to `/etc/ImageMagick-6/policy.xml` before ``: ```xml From 87272092a56a9a71a60cda2aaeda09542f9dfb9c Mon Sep 17 00:00:00 2001 From: nodlek-ctrl Date: Thu, 13 Apr 2023 12:43:15 +1000 Subject: [PATCH 06/10] fix expander 2 --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 34beb6e..0f34bc1 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ sudo pacman -S bluez bluez-utils ```
Further steps + + You may want to use the command line interface for hackiness... You may or may not need to install ImageMagick and Ghostscript, depending on your distro. @@ -90,6 +92,8 @@ You may or may not need to install ImageMagick and Ghostscript, depending on you ```bash sudo apt install imagemagick ghostscript ``` +or use your distro's package manager. + Extra configuration is required for ImageMagick to work. Because IM is made for external webserver, a strict security policy is applied. You need to add the following line to `/etc/ImageMagick-6/policy.xml` before ``: ```xml @@ -98,6 +102,8 @@ Extra configuration is required for ImageMagick to work. Because IM is made for Because this script is only accesible by localhost, or at most your local network, this is safe.
+ + *Packaging is also on the way!* ### MacOS From 1b9f8cef90db8c6e14715c9665ea0f402001943b Mon Sep 17 00:00:00 2001 From: nodlek-ctrl Date: Thu, 13 Apr 2023 12:47:26 +1000 Subject: [PATCH 07/10] finally master the art of new md lines --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0f34bc1..aee1b70 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,8 @@ On Arch Linux based distros you may install `bluez` first, as it may not be inst ```bash sudo pacman -S bluez bluez-utils ``` + +
Further steps @@ -94,15 +96,16 @@ sudo apt install imagemagick ghostscript ``` or use your distro's package manager. - + Extra configuration is required for ImageMagick to work. Because IM is made for external webserver, a strict security policy is applied. You need to add the following line to `/etc/ImageMagick-6/policy.xml` before ``: ```xml ``` + Because this script is only accesible by localhost, or at most your local network, this is safe.
- - + + *Packaging is also on the way!* From b01ab117ae78df340d0e2b8827405a7f1574cd13 Mon Sep 17 00:00:00 2001 From: nodlek-ctrl Date: Thu, 13 Apr 2023 12:51:13 +1000 Subject: [PATCH 08/10] more formatting --- README.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index aee1b70..50940e1 100644 --- a/README.md +++ b/README.md @@ -81,31 +81,26 @@ On Arch Linux based distros you may install `bluez` first, as it may not be inst ```bash sudo pacman -S bluez bluez-utils ``` -
Further steps - -You may want to use the command line interface for hackiness... +You may want to use the command line interface for hackiness... You may or may not need to install ImageMagick and Ghostscript, depending on your distro. ```bash sudo apt install imagemagick ghostscript ``` -or use your distro's package manager. +or use your distro's package manager. - Extra configuration is required for ImageMagick to work. Because IM is made for external webserver, a strict security policy is applied. You need to add the following line to `/etc/ImageMagick-6/policy.xml` before ``: ```xml ``` - + Because this script is only accesible by localhost, or at most your local network, this is safe.
- - *Packaging is also on the way!* From 2e152c2bd406f40fb7fa33c8802b9adc15e8dcb3 Mon Sep 17 00:00:00 2001 From: nodlek-ctrl Date: Thu, 13 Apr 2023 20:43:40 +1000 Subject: [PATCH 09/10] make it so error only happens when using cli --- printer.py | 8 ++++++-- www/lang/en-US.json | 2 +- www/lang/lolcat.json | 2 +- www/lang/zh-CN.json | 2 +- www/lang/zh-HK.json | 2 +- www/lang/zh-Hant-CN.json | 2 +- www/lang/zh-TW.json | 2 +- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/printer.py b/printer.py index 06b35a3..3eab310 100644 --- a/printer.py +++ b/printer.py @@ -592,12 +592,13 @@ def fallback_program(*programs): return None _MagickExe = fallback_program('magick', 'magick.exe', 'convert', 'convert.exe') -if _MagickExe is None: - error(i18n("imagemagick-not-found")) def magick_text(stdin, image_width, font_size, font_family): 'Pipe an io to ImageMagick for processing text to image, return output io' read_fd, write_fd = os.pipe() + if _MagickExe is None: + error(i18n("imagemagick-not-found")) + exit(129) subprocess.Popen([_MagickExe, '-background', 'white', '-fill', 'black', '-size', f'{image_width}x', '-font', font_family, '-pointsize', str(font_size), 'caption:@-', 'pbm:-'], @@ -607,6 +608,9 @@ def magick_text(stdin, image_width, font_size, font_family): def magick_image(stdin, image_width, dither): 'Pipe an io to ImageMagick for processing "usual" image to pbm, return output io' read_fd, write_fd = os.pipe() + if _MagickExe is None: + error(i18n("imagemagick-not-found")) + exit(129) subprocess.Popen([_MagickExe, '-', '-fill', 'white', '-opaque', 'transparent', '-resize', f'{image_width}x', '-dither', dither, '-monochrome', 'pbm:-'], stdin=stdin, stdout=io.FileIO(write_fd, 'w')) diff --git a/www/lang/en-US.json b/www/lang/en-US.json index 5102b76..6da2fba 100644 --- a/www/lang/en-US.json +++ b/www/lang/en-US.json @@ -160,6 +160,6 @@ "scan": "Scan", "now-will-scan-for-all-bluetooth-devices-nearby": "Scan set to search for all bluetooth devides nearby.", "pf2-font-not-found-or-broken-0": "PF2 font not found or broken: '{0}'", - "imagemagick-not-found": "ImageMagick not found, please install it before trying any command line hackery." + "imagemagick-not-found": "ImageMagick not found, please install it and retry." } \ No newline at end of file diff --git a/www/lang/lolcat.json b/www/lang/lolcat.json index d1a0141..f898bf2 100644 --- a/www/lang/lolcat.json +++ b/www/lang/lolcat.json @@ -138,6 +138,6 @@ "now-will-scan-for-all-bluetooth-devices-nearby": "WIL FIND ALL THINY KITTE OR NOT", "scan": "FIND", "pf2-font-not-found-or-broken-0": "KITTE FONT LOST OR DEAD> {0}", - "image-magick-not-found": "IMAGEMAGICK NOT FINDZ, PLZ INSTALL IT BEFORE TRYIN ANY COMMAND LINE FEATUREZ." + "image-magick-not-found": "IMAGEMAGICK NOT FINDZ, PLZ INSTALL IT AND HAVES ANODA GO." } diff --git a/www/lang/zh-CN.json b/www/lang/zh-CN.json index c900570..629b585 100644 --- a/www/lang/zh-CN.json +++ b/www/lang/zh-CN.json @@ -150,5 +150,5 @@ "free-software": "自由软件", "free-software-description": "尊重您计算自由的软件。", "pf2-font-not-found-or-broken-0": "PF2 字体丢失或损坏:'{0}'", - "image-magick-not-found": "未找到 ImageMagick,请在尝试任何命令行功能之前安装它。" + "image-magick-not-found": "未找到 ImageMagick,请安装并重试。" } \ No newline at end of file diff --git a/www/lang/zh-HK.json b/www/lang/zh-HK.json index eae6d33..d793ed6 100644 --- a/www/lang/zh-HK.json +++ b/www/lang/zh-HK.json @@ -150,5 +150,5 @@ "free-software": "自由軟件", "free-software-description": "尊重您計算自由的軟件。", "pf2-font-not-found-or-broken-0": "PF2 字體丟失或損壞:'{0}'", - "imagemagick-not-found": "未找到 ImageMagick,請在嘗試任何命令行功能之前安裝它。" + "imagemagick-not-found": "未找到 ImageMagick,請安裝並重試。" } \ No newline at end of file diff --git a/www/lang/zh-Hant-CN.json b/www/lang/zh-Hant-CN.json index 205021b..1afb3a3 100644 --- a/www/lang/zh-Hant-CN.json +++ b/www/lang/zh-Hant-CN.json @@ -150,5 +150,5 @@ "free-software": "自由軟件", "free-software-description": "尊重您計算自由的軟件。", "pf2-font-not-found-or-broken-0": "PF2 字體丟失或損壞:'{0}'", - "imagemagick-not-found": "未找到 ImageMagick,請在嘗試任何命令行功能之前安裝它。" + "imagemagick-not-found": "未找到 ImageMagick,請安裝並重試。" } \ No newline at end of file diff --git a/www/lang/zh-TW.json b/www/lang/zh-TW.json index 011a2b3..2081b97 100644 --- a/www/lang/zh-TW.json +++ b/www/lang/zh-TW.json @@ -149,5 +149,5 @@ "javascript-catprinter-description": "貓咪印表機 (Cat-Printer) 主指令碼", "free-software": "自由軟體", "free-software-description": "尊重您計算自由的軟體。", - "pf2-font-not-found-or-broken-0": "未找到 ImageMagick,請在嘗試任何命令行功能之前安裝它。" + "pf2-font-not-found-or-broken-0": "未找到 ImageMagick,請安裝並重試。" } \ No newline at end of file From a025d3ac5f0793af99bf0703a2639967e4789bee Mon Sep 17 00:00:00 2001 From: nodlek-ctrl Date: Thu, 13 Apr 2023 21:03:43 +1000 Subject: [PATCH 10/10] replace with fatal error --- printer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/printer.py b/printer.py index 3eab310..5d35a52 100644 --- a/printer.py +++ b/printer.py @@ -597,8 +597,8 @@ def magick_text(stdin, image_width, font_size, font_family): 'Pipe an io to ImageMagick for processing text to image, return output io' read_fd, write_fd = os.pipe() if _MagickExe is None: - error(i18n("imagemagick-not-found")) - exit(129) + fatal(i18n("imagemagick-not-found"), code=129) + subprocess.Popen([_MagickExe, '-background', 'white', '-fill', 'black', '-size', f'{image_width}x', '-font', font_family, '-pointsize', str(font_size), 'caption:@-', 'pbm:-'], @@ -609,8 +609,8 @@ def magick_image(stdin, image_width, dither): 'Pipe an io to ImageMagick for processing "usual" image to pbm, return output io' read_fd, write_fd = os.pipe() if _MagickExe is None: - error(i18n("imagemagick-not-found")) - exit(129) + fatal(i18n("imagemagick-not-found"), code=129) + subprocess.Popen([_MagickExe, '-', '-fill', 'white', '-opaque', 'transparent', '-resize', f'{image_width}x', '-dither', dither, '-monochrome', 'pbm:-'], stdin=stdin, stdout=io.FileIO(write_fd, 'w'))