mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-19 12:17:04 +00:00
refactored filename extensions
This commit is contained in:
@@ -12,8 +12,7 @@ for tunnel and therion files
|
||||
"""
|
||||
|
||||
todo = """
|
||||
- Rename functions more consistently between tunnel and therion variants
|
||||
|
||||
- Fix lost links to 1999 wallets now they have been renamed
|
||||
|
||||
- implement: findimportinsert(therionfile, imp)
|
||||
Tries to link the scrap (Therion format) to the referenced therion scrap
|
||||
@@ -30,7 +29,31 @@ rx_pcpath = re.compile(r'<pcarea area_signal="frame".*?sfsketch="([^"]*)" sfstyl
|
||||
rx_pctext = re.compile(r'pctext.*?\*ref&space;([^&]*)')
|
||||
|
||||
|
||||
IMAGE_EXTS = {".png", ".jpg", ".jpeg", ".pdf", ".gif", ".txt", ".svg"}
|
||||
# Supported suffixes are stored with a leading dot and lowercase (matches Path.suffix)
|
||||
# We factor out the image-like extensions which are common to both sets so they
|
||||
# are defined once and then reused to build the other sets.
|
||||
IMAGE_LIKE_EXTS = {".png", ".jpg", ".jpeg", ".pdf", ".gif", ".txt", ".svg"}
|
||||
|
||||
# Extensions that we treat as "image-like" for the purposes of reference parsing
|
||||
IMAGE_EXTS = set(IMAGE_LIKE_EXTS)
|
||||
|
||||
# Supported extensions include image-like ones plus drawing/text-specific ones
|
||||
SUPPORTED_EXTENSIONS = IMAGE_LIKE_EXTS.union({".xml", ".th", ".th2"})
|
||||
|
||||
|
||||
def _is_supported_suffix(suffix: str) -> bool:
|
||||
"""Return True if `suffix` (e.g. '.png') is a supported drawings extension."""
|
||||
if not suffix:
|
||||
return False
|
||||
return suffix.lower() in SUPPORTED_EXTENSIONS
|
||||
|
||||
|
||||
def _is_image_suffix(suffix: str) -> bool:
|
||||
"""Return True if `suffix` looks like an image/scan-type suffix."""
|
||||
if not suffix:
|
||||
return False
|
||||
return suffix.lower() in IMAGE_EXTS
|
||||
|
||||
rx_wallet = re.compile(r"""
|
||||
# r"(\d\d\d\d#X?\d+\w?|1995-96kh|92-94Surveybookkh|1991surveybook|smkhs)/(.*?(?:png|jpg|pdf|jpeg|gif|txt))$", path
|
||||
# This regex is designed to extract a specific directory prefix and a filename
|
||||
@@ -154,7 +177,7 @@ def _process_reference(dwgfile, path, parser_label="Tunnel"):
|
||||
|
||||
# Not a wallet reference; check image extension and possibly drawing-to-drawing reference
|
||||
suffix = Path(path).suffix.lower()
|
||||
if suffix in IMAGE_EXTS:
|
||||
if _is_image_suffix(suffix):
|
||||
# It's an image/scanned file type; we don't treat it as a referenced drawing
|
||||
return None, None
|
||||
|
||||
@@ -325,8 +348,6 @@ def load_drawings_files():
|
||||
if os.path.isfile("therionrefs.log"):
|
||||
os.remove("therionrefs.log")
|
||||
|
||||
supported_extensions = {".txt", ".xml", ".th", ".th2", ".pdf", ".png", ".svg", ".jpg"}
|
||||
|
||||
# Walk the tree with pathlib, skip hidden and backup files
|
||||
files_meta = [] # list of tuples (ext, rel_path, dwgname, pathobj)
|
||||
for p in drawdatadir.rglob('*'):
|
||||
@@ -339,7 +360,7 @@ def load_drawings_files():
|
||||
continue
|
||||
|
||||
suffix = p.suffix.lower()
|
||||
if suffix in supported_extensions or suffix == '':
|
||||
if _is_supported_suffix(suffix) or suffix == '':
|
||||
rel = p.relative_to(drawdatadir).as_posix()
|
||||
if suffix == '':
|
||||
dwgname = p.name
|
||||
|
||||
Reference in New Issue
Block a user