publishers_4.py 718 B

1234567891011121314151617181920
  1. def purge_publishers():
  2. """Removes records from publisher table which no longer have corresponding
  3. folder on the file system. If the folder does not exist, we assume that
  4. the publisher has been deleted. In any case, one cannot execute the
  5. publisher if the publisher's folder has been removed.
  6. """
  7. pubs = models.Publisher.objects.all()
  8. # for each record, test for corresponding folder
  9. for pub in pubs:
  10. # if folder does not exist
  11. if not os.path.isdir(pub.path):
  12. # remove this record
  13. pub.delete()
  14. logger.info(
  15. "Deleting publisher %s which no longer exists at %s"
  16. % (pub.name, pub.path)
  17. )