~ubuntu-branches/ubuntu/maverick/pyfiglet/maverick

« back to all changes in this revision

Viewing changes to debian/patches/tlf-support.diff

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Rivera
  • Date: 2010-01-28 13:00:41 UTC
  • Revision ID: james.westby@ubuntu.com-20100128130041-1bfzkpkap84x1vwq
Tags: 0.4+dfsg-1
Initial release (Closes: #564609)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: Add support for toilet's .tlf files.
 
2
 There are .tlf files which are compatible with figlet.
 
3
Author: Stefano Rivera <stefano@rivera.za.net>
 
4
Forwarded: https://sourceforge.net/tracker/?func=detail&aid=2939616&group_id=200820&atid=975076
 
5
Last Update: 2010-01-25
 
6
 
 
7
--- a/pyfiglet.py
 
8
+++ b/pyfiglet.py
 
9
@@ -62,7 +62,7 @@
 
10
                self.width = {}
 
11
                self.data = None
 
12
 
 
13
-               self.reMagicNumber = re.compile(r'^flf2.')
 
14
+               self.reMagicNumber = re.compile(r'^[ft]lf2.')
 
15
                self.reEndMarker = re.compile(r'(.)\s*$')
 
16
 
 
17
                self.readFontFile()
 
18
@@ -73,8 +73,11 @@
 
19
        a superclass to create different font sources.
 
20
        """
 
21
        def readFontFile(self):
 
22
-               fontPath = '%s/%s.flf' % (self.dir, self.font)
 
23
-               if os.path.exists(fontPath) is False:
 
24
+               for ext in ('flf', 'tlf'):
 
25
+                       fontPath = '%s/%s.%s' % (self.dir, self.font, ext)
 
26
+                       if os.path.exists(fontPath):
 
27
+                               break
 
28
+               else:
 
29
                        raise FontNotFound, "%s doesn't exist" % fontPath
 
30
 
 
31
                try:
 
32
@@ -86,7 +89,8 @@
 
33
                finally: fo.close()
 
34
 
 
35
        def getFonts(self):
 
36
-               return [font[:-4] for font in os.walk(self.dir).next()[2] if font.endswith('.flf')]
 
37
+               return [font[:-4] for font in os.walk(self.dir).next()[2]
 
38
+                       if font.endswith('.flf') or font.endswith('.tlf')]
 
39
                
 
40
 
 
41
 
 
42
@@ -228,25 +232,27 @@
 
43
                if os.path.exists(self.zipfile) is False:
 
44
                        raise FontNotFound, "%s doesn't exist" % self.zipfile
 
45
 
 
46
-               fontPath = 'fonts/%s.flf' % self.font
 
47
+               for ext in ('.flf', '.tlf'):
 
48
+                       fontPath = 'fonts/%s.%s' % (self.font, ext)
 
49
 
 
50
-               try:
 
51
-                       z = ZipFile(self.zipfile, 'r')
 
52
-                       files = z.namelist()
 
53
-                       if fontPath not in files:
 
54
-                               raise FontNotFound, '%s not found in %s' % (self.font, self.zipfile)
 
55
+                       try:
 
56
+                               z = ZipFile(self.zipfile, 'r')
 
57
+                               files = z.namelist()
 
58
+                               if fontPath not in files:
 
59
+                                       raise FontNotFound, '%s not found in %s' % (self.font, self.zipfile)
 
60
 
 
61
-                       self.data = z.read(fontPath)
 
62
+                               self.data = z.read(fontPath)
 
63
 
 
64
-               except Exception, e:
 
65
-                       raise FontError, "couldn't open %s: %s" % (fontPath, e)
 
66
+                       except Exception, e:
 
67
+                               raise FontError, "couldn't open %s: %s" % (fontPath, e)
 
68
 
 
69
        def getFonts(self):
 
70
                if os.path.exists(self.zipfile) is False:
 
71
                        raise FontNotFound, "%s doesn't exist" % self.zipfile
 
72
 
 
73
                z = ZipFile(self.zipfile, 'r')
 
74
-               return [font[6:-4] for font in z.namelist() if font.endswith('.flf')]
 
75
+               return [font[6:-4] for font in z.namelist()
 
76
+                       if font.endswith('.flf') and font.endswith('.tlf')]
 
77
 
 
78
 
 
79