Skip to content

Commit abaced0

Browse files
authored
Merge pull request #890 from CDLUC3/develop
Merge Develop to the main branch
2 parents 59e4ae2 + 5d92a35 commit abaced0

3 files changed

Lines changed: 69 additions & 3 deletions

File tree

ezidapp/management/commands/proc-link-checker.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@
6060
6161
The link checker notices within a few seconds when the exclusion file has been modified.
6262
Examine the link checker's log file to confirm that it has been reloaded successfully.
63+
64+
There is also the option to exclude identifiers based on what they start with which will
65+
usually be used to exclude shoulders.
66+
67+
LINKCHECKER_ID_EXCLUSION_ENABLED = True
68+
LINKCHECKER_ID_EXCLUSION_FILE = 'path/to/id_exclusion_file.txt'
6369
"""
6470

6571
# noinspection PyUnresolvedReferences
@@ -119,12 +125,22 @@ def __init__(self):
119125
self._temporaryExcludes = []
120126
self._exclusionFile = None
121127

128+
self._idExclusionFileModifyTime = -1
129+
self._idLastExclusionFileCheckTime = -1
130+
self._idExclusionFile = None
131+
self._idExclusionTuple = None
132+
122133
def run(self):
123134
if django.conf.settings.LINKCHECKER_EXCLUSION_ENABLED:
124135
if django.conf.settings.LINKCHECKER_EXCLUSION_FILE is not None:
125136
self._exclusionFile = django.conf.settings.LINKCHECKER_EXCLUSION_FILE
126137
log.info(f"Link checker exclusion enabled with file: {self._exclusionFile}")
127138

139+
if django.conf.settings.LINKCHECKER_ID_EXCLUSION_ENABLED:
140+
if django.conf.settings.LINKCHECKER_ID_EXCLUSION_FILE is not None:
141+
self._idExclusionFile = django.conf.settings.LINKCHECKER_ID_EXCLUSION_FILE
142+
log.info(f"Link checker ID exclusion enabled with file: {self._idExclusionFile}")
143+
128144
while not self.terminated():
129145
self.check_all()
130146

@@ -227,6 +243,44 @@ def remaining(self, start, cycle):
227243
def daysSince(self, when):
228244
return int((self.now() - when) / 86400)
229245

246+
def loadIdExclusionFile(self):
247+
if self._idExclusionFile is None:
248+
return
249+
if self.now_int() - self._idLastExclusionFileCheckTime < 10:
250+
return
251+
self._idLastExclusionFileCheckTime = self.now_int()
252+
f = None
253+
s = None
254+
try:
255+
# noinspection PyTypeChecker
256+
s = os.stat(self._idExclusionFile)
257+
if s.st_mtime == self._idExclusionFileModifyTime:
258+
return
259+
# noinspection PyTypeChecker
260+
f = open(self._idExclusionFile)
261+
262+
id_exclusion = []
263+
n = 0
264+
for l in f:
265+
n += 1
266+
if l.strip() == "" or l.startswith("#"):
267+
continue
268+
269+
id_exclusion.append(l.strip().casefold()) # Store as lowercase for case-insensitive matching
270+
271+
self._idExclusionTuple = tuple(id_exclusion)
272+
self._exclusionFileModifyTime = s.st_mtime
273+
log.info("id exclusion file successfully loaded")
274+
except Exception as e:
275+
log.error('Exception')
276+
if s is not None:
277+
self._exclusionFileModifyTime = s.st_mtime
278+
log.error("error loading exclusion file: " + str(e))
279+
finally:
280+
if f is not None:
281+
f.close()
282+
283+
230284
def loadExclusionFile(self):
231285
if self._exclusionFile is None:
232286
return
@@ -288,14 +342,20 @@ def harvest(self, model, only=None, filter=None):
288342
if len(qs) == 0:
289343
break
290344
for o in qs:
345+
# added to exclude ID patterns if they match the id exclusion tuple in addition to normal filtering
291346
if filter is None or filter(o):
292-
# log.debug(f'Generator returning: {str(o)}')
293-
yield o
347+
if self._idExclusionTuple is None or (o.identifier is not None and
348+
not o.identifier.casefold().startswith(self._idExclusionTuple)):
349+
yield o
350+
else:
351+
log.debug('Skipping identifier %s due to ID shoulder exclusion', o.identifier)
352+
294353
lastIdentifier = qs[-1].identifier
295354
yield None
296355

297356
def updateDatabaseTable(self):
298357
self.loadExclusionFile()
358+
self.loadIdExclusionFile()
299359
log.info("begin update table")
300360
numIdentifiers = 0
301361
numAdditions = 0
@@ -413,6 +473,7 @@ def updateDatabaseTable(self):
413473
def loadWorkset(self):
414474
self._workset = None
415475
self.loadExclusionFile()
476+
self.loadIdExclusionFile()
416477
log.info("begin load workset")
417478
_workset = []
418479
numOwnersCapped = 0
@@ -490,6 +551,7 @@ def getNextLink(self):
490551
_lock.acquire()
491552
try:
492553
self.loadExclusionFile()
554+
self.loadIdExclusionFile()
493555
startingIndex = self._index
494556
allFinished = True
495557
t = self.now()

settings/settings.py.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,14 @@ LINKCHECKER_MAX_READ = 104_857_600
529529
# EZID Link checker e-mails
530530
LINK_CHECKER_ADMIN = {{ link_checker_admin }}
531531
LINKCHECKER_EXCLUSION_ENABLED = True
532+
LINKCHECKER_ID_EXCLUSION_ENABLED = True
532533
# Full path to the file containing the list of user accounts to be excluded from link checking.
533534
# None or empty string means no exclusion file.
534535
LINKCHECKER_EXCLUSION_FILE = DATA_DIR / 'link_check_exclusion_list.txt'
535536

537+
# the ID exclusion file contains startswith identifier patterns to be excluded.
538+
LINKCHECKER_ID_EXCLUSION_FILE = DATA_DIR / 'linkchecker_id_exclusion_list.txt'
539+
536540
# Internal settings
537541

538542
# Changes in these settings may require corresponding source code modifications.

templates/manage/details.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ <h2 class="heading__icon-9">{% trans "About the Identified Object" %}</h2>
117117
<hr/>
118118
<div class="row vertical-buffer-bot">
119119
<div class="inline-header">
120-
<h2 class="heading__icon-4">{% trans "About the Identifier's Status" %} kdlkjklsjfkslj</h2>
120+
<h2 class="heading__icon-4">{% trans "About the Identifier's Status" %}</h2>
121121
</div>
122122
</div>
123123
<div class="row vertical-buffer-bot">

0 commit comments

Comments
 (0)