~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/tools/spell_check_source.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
Currently only python source is checked.
28
28
"""
29
29
 
 
30
import os
 
31
PRINT_QTC_TASKFORMAT = False
 
32
if "USE_QTC_TASK" in os.environ:
 
33
    PRINT_QTC_TASKFORMAT = True
 
34
 
30
35
ONLY_ONCE = True
 
36
USE_COLOR = True
31
37
_only_once_ids = set()
32
38
 
 
39
if USE_COLOR:
 
40
    COLOR_WORD = "\033[92m"
 
41
    COLOR_ENDC = "\033[0m"
 
42
else:
 
43
    COLOR_FAIL = ""
 
44
    COLOR_ENDC = ""
 
45
 
 
46
 
33
47
import enchant
34
48
dict_spelling = enchant.Dict("en_US")
35
49
 
44
58
    text = text.strip("#'\"")
45
59
    text = text.replace("/", " ")
46
60
    text = text.replace("-", " ")
 
61
    text = text.replace("+", " ")
 
62
    text = text.replace("%", " ")
47
63
    text = text.replace(",", " ")
 
64
    text = text.replace("|", " ")
48
65
    words = text.split()
49
66
 
50
67
    # filter words
114
131
 
115
132
def extract_py_comments(filepath):
116
133
 
117
 
    import sys
118
134
    import token
119
135
    import tokenize
120
136
 
141
157
    Extracts comments like this:
142
158
 
143
159
        /*
144
 
         * This is a multiline comment, notice the '*'s are aligned.
 
160
         * This is a multi-line comment, notice the '*'s are aligned.
145
161
         */
146
162
    """
147
163
    i = 0
167
183
    # http://doc.qt.nokia.com/qtcreator-2.4/creator-task-lists.html#task-list-file-format
168
184
    # file\tline\ttype\tdescription
169
185
    # ... > foobar.tasks
170
 
    PRINT_QTC_TASKFORMAT = True
171
186
 
172
187
    # reverse these to find blocks we won't parse
173
188
    PRINT_NON_ALIGNED = False
179
194
            for directive in STRIP_DOXY_DIRECTIVES:
180
195
                if directive in l:
181
196
                    l_split = l.split()
182
 
                    value = l_split[l_split.index(directive) + 1]
183
 
                    # print("remove:", value)
184
 
                    l = l.replace(value, " ")
 
197
                    l_split[l_split.index(directive) + 1] = " "
185
198
            block_split[i] = l
186
199
 
187
200
    comments = []
198
211
 
199
212
                block = text[i:i_next + len(END)]
200
213
 
201
 
                # add whitespace infront of the block (for alignment test)
 
214
                # add whitespace in front of the block (for alignment test)
202
215
                ws = []
203
216
                j = i
204
217
                while j > 0 and text[j - 1] != "\n":
280
293
                    else:
281
294
                        _only_once_ids.add(w_lower)
282
295
 
283
 
                print("%s:%d: %s, suggest (%s)" %
284
 
                      (comment.file,
285
 
                       comment.line,
286
 
                       w,
287
 
                       " ".join(dict_spelling.suggest(w)),
288
 
                       ))
 
296
                if PRINT_QTC_TASKFORMAT:
 
297
                    print("%s\t%d\t%s\t%s, suggest (%s)" %
 
298
                          (comment.file,
 
299
                           comment.line,
 
300
                           "comment",
 
301
                           w,
 
302
                           " ".join(dict_spelling.suggest(w)),
 
303
                           ))
 
304
                else:
 
305
                    print("%s:%d: %s%s%s, suggest (%s)" %
 
306
                          (comment.file,
 
307
                           comment.line,
 
308
                           COLOR_WORD,
 
309
                           w,
 
310
                           COLOR_ENDC,
 
311
                           " ".join(dict_spelling.suggest(w)),
 
312
                           ))
289
313
 
290
314
 
291
315
def spell_check_comments_recursive(dirpath):
305
329
 
306
330
    def is_source(filename):
307
331
        ext = splitext(filename)[1]
308
 
        return (ext in {".c", ".inl", ".cpp", ".cxx", ".hpp", ".hxx", ".h"})
 
332
        return (ext in {".c", ".inl", ".cpp", ".cxx", ".hpp", ".hxx", ".h", ".osl", ".py"})
309
333
 
310
334
    for filepath in source_list(dirpath, is_source):
311
335
        spell_check_comments(filepath)