Пример #1
0
def cleanup_font_files():
    """Remove stale fonts."""
    try:
        files = FONT_STORAGE.listdir(".")[1]
    except OSError:
        return
    for name in files:
        if name == "fonts.conf":
            continue
        if not Font.objects.filter(font=name).exists():
            FONT_STORAGE.delete(name)
Пример #2
0
 def test_cleanup(self):
     configure_fontconfig()
     cleanup_font_files()
     # There should always be fonts.conf present
     self.assertEqual(len(FONT_STORAGE.listdir(".")[1]), 1)
     font = self.add_font()
     self.assertEqual(len(FONT_STORAGE.listdir(".")[1]), 2)
     cleanup_font_files()
     self.assertEqual(len(FONT_STORAGE.listdir(".")[1]), 2)
     font.delete()
     self.assertEqual(len(FONT_STORAGE.listdir(".")[1]), 2)
     cleanup_font_files()
     self.assertEqual(len(FONT_STORAGE.listdir(".")[1]), 1)
Пример #3
0
 def assert_font_files(self, expected: int):
     result = 0
     excluded = {"fonts.conf", ".uuid"}
     for name in FONT_STORAGE.listdir(".")[1]:
         if name not in excluded:
             result += 1
     self.assertEqual(result, expected)
Пример #4
0
 def add_font(self):
     with open(FONT, "rb") as handle:
         fontfile = FONT_STORAGE.save("DroidSansFallback.ttf", handle)
     return Font.objects.create(font=fontfile, project=self.project, user=self.user)