From 5c968b80aee6bbc0f5817ffd14a1d99475c63e0f Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Sat, 6 May 2023 08:22:42 +0200 Subject: [PATCH 1/2] font-patcher: Do not fail on ro filesystem [why] When font-patcher is on a read only filesystem the pacher can not run. This is for example the case when fontforge is a AppImage. [how] Try if the logfile can be written, and if not disable logging into a file. Reported-by: Bliss X. Xu Signed-off-by: Fini Jastrow --- font-patcher | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/font-patcher b/font-patcher index 26bd60523..cc3f9f843 100755 --- a/font-patcher +++ b/font-patcher @@ -6,7 +6,7 @@ from __future__ import absolute_import, print_function, unicode_literals # Change the script version when you edit this script: -script_version = "4.1.4" +script_version = "4.1.5" version = "3.0.0" projectName = "Nerd Fonts" @@ -1955,9 +1955,13 @@ def main(): global logger logger = logging.getLogger(os.path.basename(args.font)) logger.setLevel(logging.DEBUG) - f_handler = logging.FileHandler('font-patcher-log.txt') - f_handler.setFormatter(logging.Formatter('%(levelname)s: %(name)s %(message)s')) - logger.addHandler(f_handler) + log_to_file = True + try: + f_handler = logging.FileHandler('font-patcher-log.txt') + f_handler.setFormatter(logging.Formatter('%(levelname)s: %(name)s %(message)s')) + logger.addHandler(f_handler) + except: + log_to_file = False logger.debug(allversions) logger.debug("Options %s", repr(sys.argv[1:])) c_handler = logging.StreamHandler(stream=sys.stdout) @@ -1965,6 +1969,8 @@ def main(): if not args.debugmode: c_handler.setLevel(logging.INFO) logger.addHandler(c_handler) + if not log_to_file: + logger.info("Can not write logfile, disabling") logger.debug("Naming mode %d", args.makegroups) patcher = font_patcher(args) From 80664a90fe9411c0ae1db6070f2e4d10230d69b2 Mon Sep 17 00:00:00 2001 From: Fini Jastrow Date: Sat, 6 May 2023 08:55:04 +0200 Subject: [PATCH 2/2] font-patcher: Do not log to file always [why] Maybe it is not a good idea to always create the log file, as most people will never look into it. The main reason for it was the gotta-patch-em script so that one can check after lots of runs what the details were. [how] Introduce parameter to --debug option. 0 = no debug output 1 = log to file only (previously always selected) 2 = log to stdout only 3 = log to file and stdout (previous default for --debug) Just specifying --default equals now --debug 2. The gotta-patch-em runs now with --debug 1. Signed-off-by: Fini Jastrow --- .../gotta-patch-em-all-font-patcher!.sh | 4 ++- font-patcher | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/bin/scripts/gotta-patch-em-all-font-patcher!.sh b/bin/scripts/gotta-patch-em-all-font-patcher!.sh index 6f8c8b814..910c029fd 100755 --- a/bin/scripts/gotta-patch-em-all-font-patcher!.sh +++ b/bin/scripts/gotta-patch-em-all-font-patcher!.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # Nerd Fonts Version: 3.0.0 -# Script Version: 1.4.4 +# Script Version: 1.4.5 # # You can supply options to the font-patcher via environment variable NERDFONTS # That option will override the defaults (also defaults of THIS script). @@ -246,6 +246,8 @@ function patch_font { echo >&2 "# Could not find project parent directory" exit 3 } + # Add logfile always (but can be overridden by config_patch_flags in config.cfg and env var NERDFONTS) + config_patch_flags="--debug 1 ${config_patch_flags}" # Use absolute path to allow fontforge being an AppImage (used in CI) PWD=`pwd` # Create "Nerd Font" diff --git a/font-patcher b/font-patcher index cc3f9f843..eddc0936d 100755 --- a/font-patcher +++ b/font-patcher @@ -1832,7 +1832,7 @@ def setup_arguments(): progressbars_group_parser.add_argument('--progressbars', dest='progressbars', action='store_true', help='Show percentage completion progress bars per Glyph Set (default)') progressbars_group_parser.add_argument('--no-progressbars', dest='progressbars', action='store_false', help='Don\'t show percentage completion progress bars per Glyph Set') parser.set_defaults(progressbars=True) - parser.add_argument('--debug', dest='debugmode', default=False, action='store_true', help='Verbose mode') + parser.add_argument('--debug', dest='debugmode', default=0, type=int, nargs='?', help='Verbose mode (optional: 1=just to file; 2*=just to terminal; 3=display and file)', const=2, choices=range(0, 3 + 1)) parser.add_argument('--dry', dest='dry_run', default=False, action='store_true', help='Do neither patch nor store the font, to check naming') parser.add_argument('--xavgcharwidth', dest='xavgwidth', default=None, type=int, nargs='?', help='Adjust xAvgCharWidth (optional: concrete value)', const=True) # --xavgcharwidth for compatibility with old applications like notepad and non-latin fonts @@ -1955,21 +1955,22 @@ def main(): global logger logger = logging.getLogger(os.path.basename(args.font)) logger.setLevel(logging.DEBUG) - log_to_file = True - try: - f_handler = logging.FileHandler('font-patcher-log.txt') - f_handler.setFormatter(logging.Formatter('%(levelname)s: %(name)s %(message)s')) - logger.addHandler(f_handler) - except: - log_to_file = False - logger.debug(allversions) - logger.debug("Options %s", repr(sys.argv[1:])) + log_to_file = (args.debugmode & 1 == 1) + if log_to_file: + try: + f_handler = logging.FileHandler('font-patcher-log.txt') + f_handler.setFormatter(logging.Formatter('%(levelname)s: %(name)s %(message)s')) + logger.addHandler(f_handler) + except: + log_to_file = False + logger.debug(allversions) + logger.debug("Options %s", repr(sys.argv[1:])) c_handler = logging.StreamHandler(stream=sys.stdout) c_handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s')) - if not args.debugmode: + if not (args.debugmode & 2 == 2): c_handler.setLevel(logging.INFO) logger.addHandler(c_handler) - if not log_to_file: + if (args.debugmode & 1 == 1) and not log_to_file: logger.info("Can not write logfile, disabling") logger.debug("Naming mode %d", args.makegroups)