mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-02-08 07:28:45 +00:00
refactored filename extensions
This commit is contained in:
@@ -126,3 +126,22 @@ class DrawingsPathlibTests(TestCase):
|
|||||||
|
|
||||||
di = DataIssue.objects.filter(parser='Tunnel', message__contains="files named 'unique'")
|
di = DataIssue.objects.filter(parser='Tunnel', message__contains="files named 'unique'")
|
||||||
self.assertFalse(di.exists())
|
self.assertFalse(di.exists())
|
||||||
|
|
||||||
|
def test_extension_helpers_and_constants(self):
|
||||||
|
# Helpers should recognise supported/image suffixes (case-insensitive)
|
||||||
|
self.assertTrue(drawings._is_supported_suffix('.png'))
|
||||||
|
self.assertTrue(drawings._is_supported_suffix('.xml'))
|
||||||
|
self.assertTrue(drawings._is_supported_suffix('.TH'))
|
||||||
|
self.assertFalse(drawings._is_supported_suffix(''))
|
||||||
|
self.assertFalse(drawings._is_supported_suffix('.exe'))
|
||||||
|
|
||||||
|
self.assertTrue(drawings._is_image_suffix('.png'))
|
||||||
|
self.assertTrue(drawings._is_image_suffix('.JPEG'))
|
||||||
|
self.assertFalse(drawings._is_image_suffix('.xml'))
|
||||||
|
self.assertFalse(drawings._is_image_suffix(''))
|
||||||
|
|
||||||
|
# Constants should include expected values and be consistent
|
||||||
|
self.assertIn('.png', drawings.IMAGE_EXTS)
|
||||||
|
self.assertEqual(set(drawings.IMAGE_LIKE_EXTS), set(drawings.IMAGE_EXTS))
|
||||||
|
self.assertIn('.th', drawings.SUPPORTED_EXTENSIONS)
|
||||||
|
self.assertIn('.png', drawings.SUPPORTED_EXTENSIONS)
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ for tunnel and therion files
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
todo = """
|
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)
|
- implement: findimportinsert(therionfile, imp)
|
||||||
Tries to link the scrap (Therion format) to the referenced therion scrap
|
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;([^&]*)')
|
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"""
|
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
|
# 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
|
# 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
|
# Not a wallet reference; check image extension and possibly drawing-to-drawing reference
|
||||||
suffix = Path(path).suffix.lower()
|
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
|
# It's an image/scanned file type; we don't treat it as a referenced drawing
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
@@ -325,8 +348,6 @@ def load_drawings_files():
|
|||||||
if os.path.isfile("therionrefs.log"):
|
if os.path.isfile("therionrefs.log"):
|
||||||
os.remove("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
|
# Walk the tree with pathlib, skip hidden and backup files
|
||||||
files_meta = [] # list of tuples (ext, rel_path, dwgname, pathobj)
|
files_meta = [] # list of tuples (ext, rel_path, dwgname, pathobj)
|
||||||
for p in drawdatadir.rglob('*'):
|
for p in drawdatadir.rglob('*'):
|
||||||
@@ -339,7 +360,7 @@ def load_drawings_files():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
suffix = p.suffix.lower()
|
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()
|
rel = p.relative_to(drawdatadir).as_posix()
|
||||||
if suffix == '':
|
if suffix == '':
|
||||||
dwgname = p.name
|
dwgname = p.name
|
||||||
|
|||||||
Reference in New Issue
Block a user