Merge lp:~stefanor/ibid/pyfiglet-0.6 into lp:ibid

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
Approved revision: 1004
Merged at revision: 1032
Proposed branch: lp:~stefanor/ibid/pyfiglet-0.6
Merge into: lp:ibid
Diff against target: 95 lines (+7/-35)
1 file modified
ibid/plugins/ascii.py (+7/-35)
To merge this branch: bzr merge lp:~stefanor/ibid/pyfiglet-0.6
Reviewer Review Type Date Requested Status
Max Rabkin Approve
Review via email: mp+65127@code.launchpad.net

This proposal supersedes a proposal from 2011-06-19.

Commit message

Support pyfiglet 0.6. With a totally different API...

Description of the change

There's a new pyfiglet, with a much improved (and incompatible) API.

I haven't uploaded it to Debian yet, as I wanted a patch for Ibid first (I think I wrote this months ago and forgot about it)

It's available in the ~ibid-dev PPA:
https://launchpad.net/~ibid-dev/+archive/ppa

To post a comment you must log in.
Revision history for this message
Max Rabkin (max-rabkin) wrote :

Always nice to have patches remove more code than they add!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/ascii.py'
2--- ibid/plugins/ascii.py 2010-11-07 15:14:12 +0000
3+++ ibid/plugins/ascii.py 2011-06-19 15:15:57 +0000
4@@ -3,19 +3,17 @@
5
6 from BaseHTTPServer import BaseHTTPRequestHandler
7 from cStringIO import StringIO
8-import fnmatch
9 import Image
10-from os import listdir, remove
11+from os import remove
12 import os.path
13 from random import choice
14 import subprocess
15 from tempfile import mkstemp
16 from urllib2 import HTTPError, URLError, urlopen
17 from urlparse import urlparse
18-from zipfile import ZipFile
19
20 from aalib import AsciiScreen
21-from pyfiglet import Figlet, FontNotFound
22+from pyfiglet import Figlet
23
24 from ibid.config import Option, IntOption, ListOption
25 from ibid.plugins import Processor, match
26@@ -158,8 +156,6 @@
27 features = ('figlet',)
28
29 max_width = IntOption('max_width', 'Maximum width for ascii output', 60)
30- fonts_ = Option('fonts', 'Directory or Zip file containing figlet fonts',
31- '/usr/share/figlet')
32 preferred_fonts = ListOption('preferred_fonts',
33 'List of default figlet fonts',
34 ('slant', 'letter'))
35@@ -168,29 +164,8 @@
36 self.fonts = None
37
38 def _find_fonts(self):
39- if self.fonts is not None:
40- return
41-
42- if os.path.isdir(self.fonts_):
43- self.fontstore = 'dir'
44- fonts = listdir(self.fonts_)
45- else:
46- self.fontstore = 'zip'
47- zip = ZipFile(self.fonts_)
48- fonts = zip.namelist()
49- fonts = fnmatch.filter(fonts, '*.[tf]lf')
50-
51- self.fonts = {}
52- for font in fonts:
53- font = os.path.splitext(font)[0]
54- # Not all fonts are compatible with pyfiglet
55- # (e.g. TLFs with colour):
56- try:
57- self._render('test', font)
58- except FontNotFound:
59- continue
60- name = os.path.split(font)[-1]
61- self.fonts[name] = font
62+ if self.fonts is None:
63+ self.fonts = Figlet().getFonts()
64
65 @match(r'^list\s+figlet\s+fonts(?:\s+from\s+(\d+))?$')
66 def list_fonts(self, event, index):
67@@ -201,7 +176,7 @@
68 if index >= len(self.fonts):
69 event.addresponse(u'I wish I had that many fonts installed')
70 return
71- event.addresponse(unicode(', '.join(self.fonts.keys()[int(index):])))
72+ event.addresponse(unicode(', '.join(self.fonts[int(index):])))
73
74 @match(r'^figlet\s+(.+?)(\s+in\s+(\S+))?$', 'deaddressed')
75 def write(self, event, text, font_phrase, font):
76@@ -215,17 +190,14 @@
77 if font in self.fonts:
78 break
79 else:
80- font = choice(self.fonts.keys())
81+ font = choice(self.fonts)
82 else:
83 event.addresponse(u"I'm afraid I have no fonts available")
84 return
85 self._write(event, text, font)
86
87 def _render(self, text, font):
88- if self.fontstore == 'dir':
89- figlet = Figlet(font=font, dir=self.fonts_)
90- else:
91- figlet = Figlet(font=font, zipfile=self.fonts_)
92+ figlet = Figlet(font=font)
93 return figlet.renderText(text)
94
95 def _write(self, event, text, font):

Subscribers

People subscribed via source and target branches

to all changes: