python - Using tkFont from tkinter to identify if a font (Helvetica-Light) is available/installed -


we have django application, , utilize html pdf generation tool build pdf documents. have run problems fonts not existing on server converting html pdfs, , want add unit test can verify if font exists on hosting server.

from have learned, should using tkinter's tkfont module available fonts list, , confirm fonts using found within list.

class verifyfontsexistonserver(basetransactiontestcase):     def test_if_font_exists(self):         import tkinter         import tkfont         tkinter.tk()         installed_font_families =[i in tkfont.families()                                   if 'helvetica' in                                   or 'courier' in                                   or 'dejavuserif' in                                   or 'ocra' in i]          font in installed_font_families:             log.info('{0}'.format(font)) 

but when list items out, helvetica font, not helvetica-light. believe part of family, there way identify if particular font style of family exists?

i ended writing shell based method call fc-list terminal command:

def verify_fonts_are_installed_for_statements():     import subprocess     os import path     potential_locations = [         '/usr/bin/fc-list',         '/usr/sbin/fc-list',         '/usr/local/sbin/fc-list',         '/usr/local/bin/fc-list',     ]     valid_path = none     file_path in potential_locations:         if path.exists(file_path):             valid_path = file_path             break     if valid_path none:         raise ioerror('could not find fc-list verify fonts exist.')      cmd = [valid_path]     output = subprocess.popen(cmd, stdout=subprocess.pipe).communicate()[0]      if 'helvetica neue' not in output:         raise fontnotinstalledexception('helvetica neue')     if 'courier' not in output:         raise fontnotinstalledexception('courier')      log.debug('courier , helvetica neue found installed.') 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -