summaryrefslogtreecommitdiff
path: root/po/fi/make-fi-all.py
blob: 0a288ec3427d7d4abbbc22dc8724e2da249fefa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Make a list of words that enchant spell checker does not
approve. Words are parsed from the files given as arguments.
One or more word list files can be given, those words are deemed
OK even if enchant would flag them wrong.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Library General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author: Tapio Lehtonen <tale@debian.org> 
"""

def handleCommandLine():
    """ Get arguments and options from command line. """
    from optparse import OptionParser

    usage = """usage: %prog [options] filename
Print out unknown words found in filename. Options
-p and --wordlist can be given several times."""
    lhelpstr = """What language is the text to proofread? For example fi_FI."""
    parser = OptionParser(usage=usage)
    parser.set_defaults(verbose=False)
    parser.add_option("-p", "--wordlist", 
                      action="append", type="string", dest="wordlists",
                      help="File with OK words one per line.",
                      metavar="Wordlist")
    parser.add_option("-d", "--language", 
                      action="store", type="string", dest="language",
                      help=lhelpstr)
    parser.add_option("-v", action="store_true", dest="verbose",
                      help="Be verbose.")
    parser.add_option("-q", action="store_false", dest="verbose",
                      help="Be quiet.")

    (options, args) = parser.parse_args()
    if len(args) != 1:
        parser.error("incorrect number of arguments")
    if options.verbose:
        if (options.wordlists == [] or options.wordlists == None):
            print "No extra wordlist files."
        else:
            print "Extra wordlists: ",
            for f in options.wordlists:
                print f + " ",
            print
        if options.language:
            print "Proofreading using language ", options.language, "."
        else:
            print "Proofreading using default language."
    
    return (options, args)


if __name__ == "__main__":
    
    from enchant.checker import SpellChecker

    o, a = handleCommandLine()
    if o.verbose:
        print "options   ", o
        print "arguments ", a

    try:
        textF = open(a[0], "r")
    except IOError, value:
        print "Erroria", value
        sys.exit(4)

    #text = textF.readlines()
    if o.verbose:
        import sys
        print "Language is", o.language
        print "STDOUT encoding ", sys.stdout.encoding
        print "sys default encoding", sys.getdefaultencoding()
    checker = SpellChecker(o.language)
    if o.verbose:
        if checker.wants_unicode:
            print "Checker wants Unicode text to check."
        else:
            print "Checker wants normal strings text to check."
    for text in textF.readlines():
        utext = unicode(text, "utf-8")
        if o.verbose:
            print "Text as read:"
            print text 
            print "Text to check is:"
            for u in utext:
                print u.encode("utf-8"),
            print
        checker.set_text(utext)
        for err in checker:
            print err.word.encode("utf-8")

    textF.close()