Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/validate-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're here, we could replace this printf with echo (and remove the ::error file=%s:: bit since it's a bit redundant).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the idea in 2921ddd was to use GitHub Actions annotations, so that it would annotate the problematic file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, fair enough, it should probably stay then. I still think we should move away from printf to echo but I won't block on this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have been happy to change the printf to echo. I can do so if/when I make another PR, if I remember. I see this PR as a first step towards #135/#169.

done
exit 1
fi

- name: Validate XML content
run: |
Expand Down
31 changes: 14 additions & 17 deletions tools/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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():
Expand All @@ -73,19 +71,18 @@ 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.
failed_files: Dict[str, Exception] = {}

for f in args.file:
try:
if is_dir(os.stat(f).st_mode):
if os.path.isdir(f):
continue

if f == "README":
Expand All @@ -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:
Expand All @@ -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__":
Expand Down
5 changes: 3 additions & 2 deletions tools/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import sys
from typing import List

from lxml import etree


Expand All @@ -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.
Expand All @@ -44,7 +45,7 @@ def main():
print(f"File {f} did not parse: {e}")
ret = 1

exit(ret)
sys.exit(ret)


if __name__ == "__main__":
Expand Down