def purge_publishers(): """Removes records from publisher table which no longer have corresponding folder on the file system. If the folder does not exist, we assume that the publisher has been deleted. In any case, one cannot execute the publisher if the publisher's folder has been removed. """ pubs = models.Publisher.objects.all() # for each record, test for corresponding folder for pub in pubs: # if folder does not exist if not os.path.isdir(pub.path): # remove this record pub.delete() logger.info( "Deleting publisher %s which no longer exists at %s" % (pub.name, pub.path) )