OSDN Git Service

セットアップ中の例外をExceptionのサブクラスに v0.3.0.0
authordyknon <dyknon@users.sourceforge.jp>
Thu, 27 Mar 2014 13:30:07 +0000 (22:30 +0900)
committerdyknon <dyknon@users.sourceforge.jp>
Thu, 27 Mar 2014 13:30:07 +0000 (22:30 +0900)
setup.py

index ed9d8ff..1550b19 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -25,6 +25,12 @@ import struct
 import sys
 import os
 
+class TtfError(Exception):
+       def __init__(self, val=""):
+               self.value = val
+       def __str__(self):
+               return repr(self.value)
+
 class TtfReader:
        def __init__(self, filehandle, offset=0):
                self.fh = filehandle
@@ -44,7 +50,7 @@ class TtfReader:
        def read_ttc_head(self):
                self.fh.seek(self.offset, os.SEEK_SET)
                if self.fh.read(8) != b"ttcf\x00\x01\x00\x00":
-                       raise "TTCファイルヘッダ読み込みエラー"
+                       raise TtfError("TTCファイルヘッダ読み込みエラー")
                self.tttable = []
                numfn = struct.unpack(">L", self.fh.read(4))[0]
                for i in range(numfn):
@@ -54,7 +60,7 @@ class TtfReader:
        def read_ttf_head(self):
                self.fh.seek(self.offset, os.SEEK_SET)
                if self.fh.read(4) != b"\x00\x01\x00\x00":
-                       raise "TTFファイルヘッダ読み込みエラー"
+                       raise TtfError("TTFファイルヘッダ読み込みエラー")
                (num_tables, search_range, entry_selector, range_shift) \
                        = struct.unpack(">HHHH", self.fh.read(8))
                self.table_list = {}
@@ -123,7 +129,7 @@ class TtfReader:
                elif self.tables["head"]["indexToLocFormat"] == 1:
                        table_format = struct.Struct(">L")
                else:
-                       raise "headテーブルのindexToLocFormat値が不正。"
+                       raise TtfError("headテーブルのindexToLocFormat値が不正。")
                self.tables["loca"] = []
                for i in range(self.tables["maxp"]["numGlyphs"]+1):
                        offset = table_format.unpack(self.fh.read(table_format.size))
@@ -181,7 +187,7 @@ class TtfReader:
                self.fh.seek(self.table_list["cmap"]["o"], os.SEEK_SET)
                (version, num_tables) = struct.unpack(">HH", self.fh.read(4));
                if version != 0:
-                       raise "cmapテーブルのバージョンがあたらしすぎまっす。"
+                       raise TtfError("cmapテーブルのバージョンがあたらしすぎまっす。")
                encoding_records = []
                maxscore = 0
                no = -1
@@ -203,7 +209,7 @@ class TtfReader:
                                "offset": offset
                        })
                if no < 0:
-                       raise "文字マップのエンコード方式に非対応のものしかありません"
+                       raise TtfError("文字マップのエンコード方式に非対応のものしかありません")
                encoding = None
                if encoding_records[no]["platformID"] == 3:
                        if encoding_records[no]["encodingID"] == 0:
@@ -213,7 +219,7 @@ class TtfReader:
                        if encoding_records[no]["encodingID"] == 2:
                                encoding = "sjis"
                if encoding == None:
-                       raise "文字マップのエンコード方式に非対応のものしかありません"
+                       raise TtfError("文字マップのエンコード方式に非対応のものしかありません")
                self.fh.seek(self.table_list["cmap"]["o"]
                        + encoding_records[no]["offset"], os.SEEK_SET)
                maptype = struct.unpack(">H", self.fh.read(2))[0]
@@ -289,7 +295,7 @@ class TtfReader:
                                                code = code.decode(encoding, "replace")
                                                mapdict[code] = (glyph_index + delta) % 65536
                else:
-                       raise "ID{}の文字マップには対応していません".format(maptype)
+                       raise TtfError("ID{}の文字マップには対応していません".format(maptype))
                self.tables["cmap"] = mapdict
                return self.tables["cmap"]
 
@@ -310,7 +316,7 @@ class TtfReader:
                        self.tables["maxp"]["numGlyphs"] \
                                = struct.unpack(">S", self.fh.read(2))[0]
                else:
-                       raise "maxpテーブルのバージョンが非対応なやつです"
+                       raise TtfError("maxpテーブルのバージョンが非対応なやつです")
 
        def get_table_hhea(self):
                if not "hhea" in self.tables:
@@ -515,7 +521,7 @@ def gen_fontwidth_py(outputfile):
        if not(font_can_HW and font_can_gothic and
                font_can_mincho and font_can_marumoji):
                print("適切なフォントをfonts/に入れてください。(README参照)")
-               raise "必要なフォントを自動検出できんかったよ"
+               raise TtfError("必要なフォントを自動検出できんかったよ")
        hwfont_reader = font_can_HW
        fwfont_readers = [font_can_gothic, font_can_mincho, font_can_marumoji]
        fwfont_replacers = {