Skip to content

Commit

Permalink
pylinted passepartout.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AnEnglishmanInNorway committed Jul 14, 2024
1 parent 5a3fc6b commit 01f9167
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions passepartout.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
# from io import BytesIO
# from clpFile import ClpFile
from typing import List # Set, Dict, Tuple, Optional
from lxml import etree
from typing import NamedTuple
from lxml import etree

configlogger = logging.getLogger("cewe2pdf.config")

class Passepartout(object):
class Passepartout():
def __init__(self):
return

Expand Down Expand Up @@ -51,14 +51,15 @@ def extractInfoFromXml(xmlFileName: str, passepartoutid: int):
def extractAllInfosFromXml(xmlFileName: str):
# read information from xml file about passepartout

clipArtXml = open(xmlFileName, 'rb')
try:
xmlInfo = etree.parse(xmlFileName)
except: # noqa: E722
logging.error("Maybe not valid XML:{}".format(xmlFileName))
with open(xmlFileName, 'rb') as clipArtXml:
xmlInfo = etree.parse(clipArtXml)
except IOError as ioe:
logging.error(f"I/O error({ioe.errno}): {ioe.strerror}")
return None
except Exception as e: # handle other exceptions such as attribute errors
logging.error(f"Error: {e}")
return None
finally:
clipArtXml.close()

for decoration in xmlInfo.findall('decoration'):
decoration_id = decoration.get('id')
Expand Down Expand Up @@ -105,7 +106,7 @@ def buildElementIdIndex(directoryList: List[str]) -> dict:
# designElementId to .xml file

# a dictionary for passepartout element IDs to file name
passepartoutIdDict = dict()
passepartoutIdDict = {}

if directoryList is None:
configlogger.error("No directories passed to Passepartout.buildElementIdIndex!")
Expand All @@ -127,7 +128,7 @@ def buildElementIdIndex(directoryList: List[str]) -> dict:
for filename in (f for f in filenames if f.endswith(ext)):
xmlFileList.append(os.path.join(dirpath, filename))
# print(os.path.join(dirpath, filename))
configlogger.info("Found {:d} XML files.".format(len(xmlFileList)))
configlogger.info(f"Found {len(xmlFileList):d} XML files.")

# load each .xml file and extract the information
for curXmlFile in xmlFileList:
Expand Down

0 comments on commit 01f9167

Please sign in to comment.