From 5995546c4972d2e95f80d6f26a3b826d89e216f4 Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Sat, 3 Jan 2026 04:37:38 -0800 Subject: [PATCH 1/2] Fixed linting errors with Python scripts. --- tools/convert.py | 31 ++++++++++++++----------------- tools/validate.py | 5 +++-- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/tools/convert.py b/tools/convert.py index a407002..c4b2c91 100644 --- a/tools/convert.py +++ b/tools/convert.py @@ -27,16 +27,15 @@ # ***** END LICENSE BLOCK ***** import argparse -import codecs import os.path -import stat import sys from typing import Dict + import lxml.etree as ET def read_config(file, convertTime): - return (ET.parse(file), max(os.stat(file).st_mtime, convertTime)) + return (ET.parse(file), max(os.path.getmtime(file), convertTime)) def doc_to_bytestring(doc): @@ -48,19 +47,18 @@ def print_config(doc): def write_config(outData, time, filename=None): - if os.path.exists(filename) and os.stat(filename).st_mtime >= time: + if os.path.exists(filename) and os.path.getmtime(filename) >= time: return - print("Writing %s" % filename) - file = codecs.open(filename, "wb") - file.write(outData) - file.write(b"\n") - file.close() + print(f"Writing {filename}") + with open(filename, "wb") as file: + file.write(outData) + file.write(b"\n") def write_domains(doc, time, output_dir="."): outData = doc_to_bytestring(doc) for d in doc.getroot().findall(".//domain"): - write_config(outData, time, output_dir + "/" + d.text) + write_config(outData, time, os.path.join(output_dir, d.text)) def main(): @@ -73,11 +71,10 @@ def main(): parser.add_argument( "file", nargs="*", help="input file(s) to process, wildcards allowed" ) - args = parser.parse_args(sys.argv[1:]) + args = parser.parse_args() # process arguments - convertTime = os.stat(sys.argv[0]).st_mtime - is_dir = stat.S_ISDIR + convertTime = os.path.getmtime(sys.argv[0]) # Record the files that failed to be processed and the errors related to # them. @@ -85,7 +82,7 @@ def main(): for f in args.file: try: - if is_dir(os.stat(f).st_mode): + if os.path.isdir(f): continue if f == "README": @@ -103,10 +100,10 @@ def main(): print("should also specify an output directory") print("using -d dir") parser.print_usage() - exit(2) + sys.exit(2) elif args.d: outData = doc_to_bytestring(doc) - write_config(outData, time, args.d + "/" + os.path.basename(f)) + write_config(outData, time, os.path.join(args.d, os.path.basename(f))) else: print_config(doc) except Exception as e: @@ -122,7 +119,7 @@ def main(): for file, exc in failed_files.items(): print(f"{file}: {exc}") - exit(1) + sys.exit(1) if __name__ == "__main__": diff --git a/tools/validate.py b/tools/validate.py index 9604470..5a04456 100644 --- a/tools/validate.py +++ b/tools/validate.py @@ -9,6 +9,7 @@ import os import sys from typing import List + from lxml import etree @@ -17,7 +18,7 @@ def main(): parser.add_argument( "file", nargs="*", help="input file(s) to process, wildcards allowed" ) - args = parser.parse_args(sys.argv[1:]) + args = parser.parse_args() # Defining `files` here isn't strictly necessary, but the extra typing # (which we can't really get otherwise) helps with maintenance. @@ -44,7 +45,7 @@ def main(): print(f"File {f} did not parse: {e}") ret = 1 - exit(ret) + sys.exit(ret) if __name__ == "__main__": From 6e42e4a8d0306732beaa34f0794a0cce9a579608 Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Sat, 3 Jan 2026 04:39:32 -0800 Subject: [PATCH 2/2] Updated CI and fixed linting error with Bash code. --- .github/workflows/validate-config.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/validate-config.yml b/.github/workflows/validate-config.yml index 9ebc696..d41af32 100644 --- a/.github/workflows/validate-config.yml +++ b/.github/workflows/validate-config.yml @@ -6,8 +6,11 @@ jobs: validate_config: runs-on: ubuntu-latest + env: + PYTHONDEVMODE: 1 + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v6 - name: BOM check run: | @@ -16,7 +19,14 @@ jobs: - name: Validate file extensions run: | set -o pipefail - ls -1 ispdb/ | grep -v '\.xml$' | awk '{print "::error file=ispdb/"$0"::File name \"ispdb/"$0"\" does not end in .xml – Please rename!"}' && exit 1 || true + shopt -s extglob nullglob + files=( ispdb/!(*.xml) ) + if (( ${#files[*]} )); then + for file in "${files[@]}"; do + printf '::error file=%s::File name "%s" does not end in .xml – Please rename!\n' "$file" "$file" + done + exit 1 + fi - name: Validate XML content run: |