Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'attribute': 0.07; 'linux,': 0.07; 'skip:` 10': 0.07; 'python:': 0.09; 'subject:How': 0.10; 'devise': 0.16; 'exists,': 0.16; 'fancy': 0.16; 'gpg': 0.16; 'portable': 0.16; 'skip:[ 30': 0.16; 'subject: \n ': 0.16; 'tags.': 0.16; 'tool.': 0.16; 'windows:': 0.16; 'subject:python': 0.16; 'apps': 0.16; 'wrote:': 0.18; 'commit': 0.19; 'thu,': 0.19; 'install': 0.23; 'header:User- Agent:1': 0.23; 'parse': 0.24; 'skip:% 10': 0.24; 'file.': 0.24; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'subject:) ': 0.29; 'xml': 0.29; 'url:mailman': 0.30; '-0700,': 0.31; 'font': 0.31; 'file': 0.32; 'probably': 0.32; 'checked': 0.32; 'stuff': 0.32; 'text': 0.33; 'open': 0.33; 'url:python': 0.33; 'running': 0.33; 'checking': 0.33; 'mac': 0.33; 'subject:the': 0.34; 'skip:s 30': 0.35; 'received:google.com': 0.35; 'url:support': 0.36; 'url:listinfo': 0.36; 'useful': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'virtual': 0.37; 'easiest': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'skip:o 30': 0.61; 'from:charset:utf-8': 0.61; 'first': 0.61; 'content- disposition:inline': 0.62; 'hints': 0.68; 'rendering': 0.68; 'jul': 0.74; 'received:178': 0.74; 'guaranteed': 0.75; 'skip:$ 10': 0.81; 'subject:get': 0.81; 'etc..': 0.84; 'fonts': 0.84; 'it\xe2\x80\x99s': 0.84; 'oh:': 0.84; 'subject:Platform': 0.84; 'do:': 0.91; 'url:tk': 0.95; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=9Q8YuwNfGd65SGwY+6lRRsE+7pvvsb2g2Yd8d92HXpY=; b=op9Y064g2hzygsb2TNxhebtZRqtKAYOsww2idOAmZf33dTkL8qYAuFdP359Ke+8BQN NeJHwzUmMQbDS8SwbbwmP4wueFsiwMdjh2DsAbkP4JHJ5hd3Sg83uwe9K/40HDqtj0hi 90Y9bgPW0yQvkOnIQCLcEJvsPVVdxmq7rak7X2y7K6i+TbPqfzgcT+Fgr+GQrMHhhJ0A 2lAqFI2/2U4sB8IiKtj5I1Q4y+Jr5rsa1pBhOUbiIVsgURBAl3u/k8bX6Yvw4ZcAc29D WDd7e2Ov7TiogNau1OAmW39NH/UMOp9pPD78NoHUY57KEnR8UE4J3S3atVyUT1eVCSDm sJaQ== X-Received: by 10.204.228.207 with SMTP id jf15mr5830197bkb.16.1373559176946; Thu, 11 Jul 2013 09:12:56 -0700 (PDT) Date: Thu, 11 Jul 2013 18:12:43 +0200 From: Chris =?utf-8?B?4oCcS3dwb2xza2HigJ0=?= Warrick To: python-list@python.org Subject: Re: How do I get the OS System Font Directory(Cross-Platform) in python? References: <3d97de86-f690-40ad-aba8-972120af7ff3@googlegroups.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="jI8keyz6grp/JLjh" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 70 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373559184 news.xs4all.nl 15969 [2001:888:2000:d::a6]:60062 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50462 --jI8keyz6grp/JLjh Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 11, 2013 at 08:54:17AM -0700, Metallicow wrote: > For a portable font install tool. >=20 > Finding if a particular font exists, > useful when testing apps in virtual environent, > rendering text from a font, > Font file manipulations, > etc.. > --=20 > http://mail.python.org/mailman/listinfo/python-list Then do a nice little `if` checking the user=E2=80=99s OS. http://docs.python.org/2/library/sys.html#sys.platform hints what to use, and you need to do: if sys.platform.startswith('win') or sys.platform.startswith('cygwin'): FONTDIRS =3D [os.path.join(os.environ['WINDIR'], 'Fonts') elif sys.platform.startswith('darwin'): # [see below and devise it yourself] else: # linux, *bsd and everything else # [see below, commit suicide and develop this bit] Windows: The easiest of those three, all the fonts are in %WINDIR%/Fonts. In Python: os.path.join(os.environ['WINDIR'], 'Fonts') Mac OS X: http://support.apple.com/kb/ht2435 (and not all of them are guaranteed to exist). `os.expanduser()` may be useful for that first one. Linux, and everything else running that fancy open stuff (eg. *BSD): Hardcore. You just need to parse a nice tiny 155-line XML file. It=E2=80=99s /etc/fonts/fonts.conf, and it has some tags. Some of them may have a `prefix=3D"xdg"` attribute which makes you prepend the value with $XDG_DATA_HOME (~/.local/share if that is empty). You also need `os.expanduser()`. Oh: and you need to go recursively through them, as subdirectories are also checked for fonts (and it probably goes further) --=20 Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html --jI8keyz6grp/JLjh Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (GNU/Linux) iQEcBAEBAgAGBQJR3tl4AAoJEHECPb1equoW6H8IAK5oDUsJ0QCvzJzokstoYJte FewqkDVoBj5X1VDoazDRqZ2IDvcEv1VgDqfqk6js8kf7dFb/oEQNh03+evegxupq kei0SN8dQ6a7zrUHiYEsVSLp8pWHGylxJ/K6aYtpL8si2h06xxnrYIxsOtOm7Ii8 fXS98gQy8s6j8O0YaGQYkTxQo6GLbyiFvi9i2ZyrbuNo+5Xf9XjXsGO6o6SeMw2A 8FUnl3TBD5isNN9wAonOv4iw4cQ15KG9Zjfjqr4A0wSnrGI9JAXFCubJxDpu28xj eI1/hbk/3jUTGFK3x8ANiqL3ndf88J/aeqUxlfDRsmO4A+YWX3Hp1aOUuqItLY4= =pjFt -----END PGP SIGNATURE----- --jI8keyz6grp/JLjh--