Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pylint and ruff cleanups #3088

Merged
merged 4 commits into from
Dec 14, 2024
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
4 changes: 2 additions & 2 deletions ci/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def matrix_build(shared_libs, ccs, build_types, cmake_bin, cmake_options,
os.path.join(
"build",
"_".join(
map(lambda p: str(p) if p is not None else "", params)
map(str, filter(None, params))
)
)
)
Expand All @@ -46,7 +46,7 @@ def matrix_build(shared_libs, ccs, build_types, cmake_bin, cmake_options,
cmake_options, cmake_bin=cmake_bin, build_type=build_type,
lib_type=lib_type, tests="ON" if tests else "OFF"
)
make = "make -j " + str(NCPUS)
make = f"make -j {str(NCPUS)}"
make_tests = "make tests"
unit_test_binary = os.path.join(cwd, "bin", "unit_tests")

Expand Down
56 changes: 30 additions & 26 deletions doc/templates/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,54 @@
vardir = "."
date_format = "%d-%b-%Y"


# ----------------------------------------------------------------------
# functions
def usage():
print("""Usage: gen.py file.in [...]
Substitute placeholders in input files with content
""")
print("""Usage: gen.py file.in [...]
Substitute placeholders in input files with content
""")


def gen_html(file):
"""Replace variables in the file with their content"""
text = open(file).read()
for var in vars:
vartext = open(vardir + "/" + var).read()
text = text.replace(var, vartext)
text = last_modified(text)
return text
"""Replace variables in the file with their content"""
text = open(file, encoding=None).read()
for var in vars:
vartext = open(f"{vardir}/{var}", encoding=None).read()
text = text.replace(var, vartext)
text = last_modified(text)
return text


def last_modified(text):
"""Substitute variable __last_modified__ with the current date"""
date = time.strftime(date_format, time.localtime())
text = text.replace("__last_modified__", date)
return text
"""Substitute variable __last_modified__ with the current date"""
date = time.strftime(date_format, time.localtime())
text = text.replace("__last_modified__", date)
return text


# ----------------------------------------------------------------------
# main
# Check command line arguments
if len(sys.argv) == 1:
usage()
sys.exit()
usage()
sys.exit()

# The input files from the command line
input = sys.argv[1:]

# Get a list of all variables (files in the form __*__) from vardir
# Get a list of all variables (files in the form __*__) from vardir
vars = os.listdir(vardir)
for i in range(len(vars)-1, -1, -1):
if re.match("^__.*__$", vars[i]):
continue
del vars[i]
for i in range(len(vars) - 1, -1, -1):
if re.match("^__.*__$", vars[i]):
continue
del vars[i]
vars.sort()

# Substitute variables in all input files
print("Substituting variables {0}".format(vars))
print(f"Substituting variables {vars}")
for file in input:
print("Processing {0}...".format(file))
text = gen_html(file)
file = file.replace(".in", "")
open(file, 'w').write(text)
print(f"Processing {file}...")
text = gen_html(file)
file = file.replace(".in", "")
open(file, "w", encoding=None).write(text)
24 changes: 12 additions & 12 deletions doc/templates/iptc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
data = sys.stdin.readlines()
for line in csv.reader(data,quotechar='"',skipinitialspace=True):
row=row+1
print(" <ROW num=\"%d\">" % row)
print(" <tagname>" + line[ 0] + "</tagname>")
print(" <tagdec>" + line[ 1] + "</tagdec>")
print(" <taghex>" + line[ 2] + "</taghex>")
print(" <recname>" + line[ 3] + "</recname>")
print(" <mandatory>" + line[ 4] + "</mandatory>")
print(" <repeatable>" + line[ 5] + "</repeatable>")
print(" <minbytes>" + line[ 6] + "</minbytes>")
print(" <maxbytes>" + line[ 7] + "</maxbytes>")
print(" <key>" + line[ 8] + "</key>")
print(" <type>" + line[ 9] + "</type>")
print(" <tagdesc>" + line[10] + "</tagdesc>")
print(f" <ROW num=\"{int(row)}\">")
print(f" <tagname>{line[0]}</tagname>")
print(f" <tagdec>{line[1]}</tagdec>")
print(f" <taghex>{line[2]}</taghex>")
print(f" <recname>{line[3]}</recname>")
print(f" <mandatory>{line[4]}</mandatory>")
print(f" <repeatable>{line[5]}</repeatable>")
print(f" <minbytes>{line[6]}</minbytes>")
print(f" <maxbytes>{line[7]}</maxbytes>")
print(f" <key>{line[8]}</key>")
print(f" <type>{line[9]}</type>")
print(f" <tagdesc>{line[10]}</tagdesc>")
print(" </ROW>")

print("</ROWSET>")
Expand Down
16 changes: 8 additions & 8 deletions doc/templates/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
data = sys.stdin.readlines()
for line in csv.reader(data,quotechar='"',skipinitialspace=True):
row=row+1
print(" <ROW num=\"%d\">" % row)
print(" <tagname>" + line[0] + "</tagname>")
print(" <tagdec>" + line[1] + "</tagdec>")
print(" <taghex>" + line[2] + "</taghex>")
print(" <ifd>" + line[3] + "</ifd>")
print(" <key>" + line[4] + "</key>")
print(" <type>" + line[5] + "</type>")
print(" <tagdesc>" + line[6] + "</tagdesc>")
print(f" <ROW num=\"{int(row)}\">")
print(f" <tagname>{line[0]}</tagname>")
print(f" <tagdec>{line[1]}</tagdec>")
print(f" <taghex>{line[2]}</taghex>")
print(f" <ifd>{line[3]}</ifd>")
print(f" <key>{line[4]}</key>")
print(f" <type>{line[5]}</type>")
print(f" <tagdesc>{line[6]}</tagdesc>")
print(" </ROW>")

print("</ROWSET>")
Expand Down
14 changes: 7 additions & 7 deletions doc/templates/xmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
print(data)
for line in csv.reader(data,quotechar='"',skipinitialspace=True):
row=row+1
print(" <ROW num=\"%d\">" % row)
print(" <tagname>" + line[0] + "</tagname>")
print(" <title>" + line[1] + "</title>")
print(" <xmpvaltype>" + line[2] + "</xmpvaltype>")
print(" <type>" + line[3] + "</type>")
print(" <category>" + line[4] + "</category>")
print(" <tagdesc>" + line[5] + "</tagdesc>")
print(f" <ROW num=\"{int(row)}\">")
print(f" <tagname>{line[0]}</tagname>")
print(f" <title>{line[1]}</title>")
print(f" <xmpvaltype>{line[2]}</xmpvaltype>")
print(f" <type>{line[3]}</type>")
print(f" <category>{line[4]}</category>")
print(f" <tagdesc>{line[5]}</tagdesc>")
print(" </ROW>")

print("</ROWSET>")
Expand Down
21 changes: 10 additions & 11 deletions fuzz/mkdictionary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python3

# Utility for generating a fuzzing dictionary for Exiv2.
# See README.md (in this directory) for more information.
Expand All @@ -11,22 +11,21 @@
def escapeChar(c):
if c == '\\':
return '\\\\'
elif c == '"':
if c == '"':
return '\\"'
elif c.isascii() and c.isprintable():
if c.isascii() and c.isprintable():
return c
else:
return '\\x{:02X}'.format(ord(c))
return f'\\x{ord(c):02X}'

def escapeString(str):
return ''.join(map(lambda c: escapeChar(chr(c)), bytes(str, 'utf-8')))
return ''.join(map(escapeChar, bytes(str, 'utf-8')))

if len(sys.argv) < 2:
print("usage: mkdict.py dict.json")
sys.exit(1)

f = open(sys.argv[1], 'r')
dict_json = json.loads(f.read())
tuples = dict_json["#select"]["tuples"]
for r in tuples:
print('"' + escapeString(r[0]) + '"')
with open(sys.argv[1], 'r', encoding=None) as f:
dict_json = json.loads(f.read())
tuples = dict_json["#select"]["tuples"]
for r in tuples:
print(f"\"{escapeString(r[0])}\"")
Loading
Loading