Merge lp:~jtv/corpusfiltergraph/pyflakes-cleanup into lp:~domy/corpusfiltergraph/old-sourceforge-trunk

Proposed by Jeroen T. Vermeulen
Status: Needs review
Proposed branch: lp:~jtv/corpusfiltergraph/pyflakes-cleanup
Merge into: lp:~domy/corpusfiltergraph/old-sourceforge-trunk
Diff against target: 742 lines (+75/-43)
30 files modified
trunk/lib/corpusfg/cfgparser.py (+5/-3)
trunk/lib/corpusfg/common.py (+5/-4)
trunk/lib/corpusfg/filtergraph.py (+6/-3)
trunk/lib/corpusfg/flock.py (+1/-0)
trunk/lib/corpusfg/manager.py (+4/-3)
trunk/lib/corpusfg/plugins/add-line-numbers.py (+1/-0)
trunk/lib/corpusfg/plugins/aligner-passthrough.py (+0/-1)
trunk/lib/corpusfg/plugins/delete-files.py (+0/-1)
trunk/lib/corpusfg/plugins/ja/convert-ansi2full.py (+1/-0)
trunk/lib/corpusfg/plugins/ja/convert-full2ansi.py (+1/-2)
trunk/lib/corpusfg/plugins/null-copyfile.py (+10/-2)
trunk/lib/corpusfg/plugins/reader-null.py (+0/-3)
trunk/lib/corpusfg/plugins/reader-tab.py (+0/-3)
trunk/lib/corpusfg/plugins/reader-tmx.py (+0/-1)
trunk/lib/corpusfg/plugins/remove-multi-spaces.py (+2/-0)
trunk/lib/corpusfg/plugins/repair-escapes.py (+0/-1)
trunk/lib/corpusfg/plugins/special-join.py (+0/-1)
trunk/lib/corpusfg/plugins/special-secondary-output.py (+2/-1)
trunk/lib/corpusfg/plugins/special-split.py (+0/-1)
trunk/lib/corpusfg/plugins/subprocess-synch.py (+1/-0)
trunk/lib/corpusfg/plugins/writer-file.py (+0/-1)
trunk/lib/corpusfg/plugins/writer-null.py (+0/-4)
trunk/lib/corpusfg/plugins/writer-tab.py (+0/-1)
trunk/lib/corpusfg/plugins/writer-tmx.py (+0/-2)
trunk/lib/corpusfg/plugins/zh_cn/convert-zh2traditional.py (+1/-0)
trunk/lib/corpusfg/plugins/zh_hk/convert-zh2simplified.py (+1/-0)
trunk/lib/corpusfg/progress_bar.py (+1/-1)
trunk/lib/corpusfg/pstat.py (+3/-0)
trunk/lib/corpusfg/stats.py (+29/-4)
trunk/lib/corpusfg/unicode_block.py (+1/-0)
To merge this branch: bzr merge lp:~jtv/corpusfiltergraph/pyflakes-cleanup
Reviewer Review Type Date Requested Status
PTTools Support Approve
Review via email: mp+159302@code.launchpad.net

Commit message

Quick notes and cleanups based on pyflakes.

Description of the change

To prepare for an extraction of repeated code (the writing of status files), I ran all source files through the "pyflakes" code checker. It produced a large number of notes.

Here you see a few simple cleanups, but also many notes on undefined variables that look like they'd break the code. These may be in functions or code paths that aren't normally (or ever) used.

Jeroen

To post a comment you must log in.
Revision history for this message
PTTools Support (support-precisiontranslationtools) wrote :

DIFF Line 48
- i = 0
I remember adding the i = 0 because there was some odd case where the following list comprehension failed with index out of range. This fixed it.

#TODO: "me" is undefined.
It's defined and it equates to self. See filtergraph.py Line 386. I'm sure it's a horrible way to do this, but I needed to share information with other classes:
  global me
  me = self

stats.py is a dated module that I think eventually became numpy. I use for only a few functions.

We'll need to work through others one-by-one.

Revision history for this message
PTTools Support (support-precisiontranslationtools) wrote :

DIFF Line 48
- i = 0
I remember adding the i = 0 because there was some odd case where the following list comprehension failed with index out of range. This fixed it.

#TODO: "me" is undefined.
It's defined and it equates to self. See filtergraph.py Line 386. I'm sure it's a horrible way to do this, but I needed to share information with other classes:
  global me
  me = self

stats.py is a dated module that I think eventually became numpy. I use for only a few functions.

We'll need to work through others one-by-one.

review: Approve

Unmerged revisions

340. By Jeroen T. Vermeulen

Superficial notes and cleanups based on pyflakes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'trunk/lib/corpusfg/cfgparser.py'
2--- trunk/lib/corpusfg/cfgparser.py 2013-01-01 15:15:07 +0000
3+++ trunk/lib/corpusfg/cfgparser.py 2013-04-17 07:15:36 +0000
4@@ -231,7 +231,7 @@
5
6 try:
7 reader = ','.join([v.strip() for v in [k for k in config.keys() if ',reader-' in k.replace(' ','')][0].split(',')])
8- except IndexError,e:
9+ except IndexError:
10 errors.append([__name__,'missing','\"[reader]\" section not found'])
11 else:
12 if not 'stage' in config[reader]:
13@@ -245,7 +245,7 @@
14 writer = ','.join([v.strip() for v in [k for k in config.keys() if ',writer-' in k.replace(' ','')][0].split(',')])
15 if not 'stage' in config[writer]:
16 errors.append([__name__,'missing','\"[%s] stage=\" value not found'%(writer)])
17- except IndexError,e:
18+ except IndexError:
19 errors.append([__name__,'missing','\"[writer]\" section not found'])
20 else:
21 if not 'roottype' in config[writer]:
22@@ -437,7 +437,8 @@
23 pass
24 return list(datetime), {} # make_lastupdate(master,datetime)
25 else:
26- return [ lines[0], cf.str2datetime(lines[0]) ], dict([[os.sep.join([path,a[0]]),a[1]] for a in [path.split('\t') for path in lines[1:]]])
27+ # TODO: Two different "path" variables here. Tease them apart.
28+ return [ lines[0], cf.str2datetime(lines[0]) ], dict([[os.path.join(path,a[0]),a[1]] for a in [path.split('\t') for path in lines[1:]]])
29
30 # get date-time stamp from working folder
31 working_lastupdate, working_contents = get_lastupdate(working,epoch)
32@@ -494,6 +495,7 @@
33 except:
34 raise OSError('Error: failed to open %s'%(outputini))
35 if os.name == 'posix' and os.geteuid() == 0:
36+ # TODO: "working" is not defined!
37 cf.chmodrecurse(os.path.dirname(working),pwd.getpwnam(lrunas).pw_uid,pwd.getpwnam(lrunas).pw_gid)
38
39 def _copytreeif(src, dst, datetime, updates={}, lastupdates={}, lrunas=''):
40
41=== modified file 'trunk/lib/corpusfg/common.py'
42--- trunk/lib/corpusfg/common.py 2013-01-01 15:15:07 +0000
43+++ trunk/lib/corpusfg/common.py 2013-04-17 07:15:36 +0000
44@@ -230,7 +230,6 @@
45 if listsize >= popsize: listsize = 1
46 tmplist = random.sample(xrange(popsize),listsize*nbrlists)
47 tmplen = int(len(tmplist)/nbrlists)
48- i = 0
49 return [tmplist[i:i+tmplen] for i in range(i,listsize*nbrlists,tmplen)]
50
51 def samplesize(popsize,confidencelevel,confidenceinterval,estimate=0.5):
52@@ -589,8 +588,12 @@
53 if os.name == 'nt':
54 try:
55 # note: Windows only allows admin users read the C:\windows\temp folder
56- temp = os.listdir(os.sep.join([os.environ.get('SystemRoot',''),'temp']))
57+ # TODO: "temp" is unused.
58+ temp = os.listdir(os.path.join(os.environ.get('SystemRoot',''),'temp'))
59 except:
60+ # TODO: What kind of exception exactly? Is the
61+ # intention just to find out whether that temp directory
62+ # exists?
63 return (os.environ['USERNAME'],False)
64 else:
65 return (os.environ['USERNAME'],True)
66@@ -745,6 +748,4 @@
67 at: http://www.precisiontranslationtools.com'''
68
69 if __name__ == "__main__":
70- import os
71- import sys
72 sys.stdout.write(usage().encode('utf8')+'\n')
73
74=== modified file 'trunk/lib/corpusfg/filtergraph.py'
75--- trunk/lib/corpusfg/filtergraph.py 2013-01-01 15:15:07 +0000
76+++ trunk/lib/corpusfg/filtergraph.py 2013-04-17 07:15:36 +0000
77@@ -15,7 +15,6 @@
78 import logging
79 import flock
80 import fnmatch
81-import stat
82 import common as cf
83 import tempfile
84
85@@ -31,6 +30,7 @@
86 try:
87 return super(filtergraph.CustomInput,self).__getitem__(key)
88 except KeyError:
89+ # TODO: "me" is undefined. Should it be "self"?
90 if me.stage[0].lower() == 'none':
91 filelist = me.filelist[:cf.stage]+list(key)
92 else:
93@@ -72,6 +72,7 @@
94 try:
95 return super(filtergraph.CustomOutput,self).__getitem__(key)
96 except KeyError:
97+ # TODO: "me" is undefined. Should it be "self"?
98 fs,root = me.writer.getroot(me.writer.rootfolder) if me.writer.rootfolder else me.filelist[:cf.rttype]
99 if me.writer.stage.lower() == 'none':
100 filelist = [fs,root]+[me.writer.roottype]+list(key)
101@@ -113,6 +114,7 @@
102 try:
103 return super(filtergraph.CustomError,self).__getitem__(key)
104 except KeyError:
105+ # TODO: "me" is undefined. Should it be "self"?
106 fs,root = me.writer.getroot(me.writer.rootfolder) if me.writer.rootfolder else me.filelist[:cf.rttype]
107 if me.writer.stage.lower() == 'none':
108 filelist = [fs,root]+[me.writer.roottype]+['-'.join([key[0],'workbench'])]+list(key[1:])
109@@ -148,6 +150,7 @@
110 try:
111 return super(filtergraph.CustomExtract,self).__getitem__(key)
112 except KeyError:
113+ # TODO: "me" is undefined. Should it be "self"?
114 fs,root = me.writer.getroot(me.writer.rootfolder) if me.writer.rootfolder else me.filelist[:cf.rttype]
115 stage = me.filelist[cf.stage] if fnmatch.fnmatch(me.filelist[cf.stage],me.writer.stage) else me.writer.stage
116 filelist = [fs,root]+[me.writer.roottype]+['-'.join([stage,'extract'])]+list(key)
117@@ -953,7 +956,7 @@
118
119 try:
120 alts = bool([k for k in self.cfoutput.keys() if not k[cf.kind].lower().startswith('tm') and not k[cf.kind].lower().startswith('lm')])
121- except Exception,e:
122+ except Exception:
123 alts = True
124
125 if not alts:
126@@ -1024,7 +1027,7 @@
127
128 try:
129 alts = bool([k for k in self.cfoutput.keys() if not k[cf.kind].lower().startswith('tm') and not k[cf.kind].lower().startswith('lm')])
130- except Exception,e:
131+ except Exception:
132 alts = True
133
134 if not alts:
135
136=== modified file 'trunk/lib/corpusfg/flock.py'
137--- trunk/lib/corpusfg/flock.py 2013-01-01 15:15:07 +0000
138+++ trunk/lib/corpusfg/flock.py 2013-04-17 07:15:36 +0000
139@@ -9,6 +9,7 @@
140 import os
141 import socket
142
143+# TODO: There's also a "from flock import flock" further down... Which is it!?
144 class flock(object):
145 '''Class to handle creating and removing (pid) lockfiles'''
146
147
148=== modified file 'trunk/lib/corpusfg/manager.py'
149--- trunk/lib/corpusfg/manager.py 2013-01-01 15:15:07 +0000
150+++ trunk/lib/corpusfg/manager.py 2013-04-17 07:15:36 +0000
151@@ -8,12 +8,11 @@
152 #version:
153 #4.5.337 - version update
154
155+import codecs
156 import sys
157 import os
158 from flock import flock
159-import codecs
160 from progress_bar import ProgressBar
161-import shutil
162 import logging
163 from filtergraph import filtergraph
164 import common as cf
165@@ -91,6 +90,7 @@
166 # create file handler which logs messages
167 self.logfile = os.path.abspath(os.path.expanduser(os.sep.join([cfg['filtergraph']['graphs'],cfg['filtergraph']['graphname'],os.extsep.join([cfg['filtergraph']['graphname'],'log'])])))
168 if cfg['debug'] and not sum([1 for handler in logger.handlers if 'baseFilename' in dir(handler) and handler.baseFilename == self.logfile]):
169+ # TODO: Why re-import codecs!?
170 import codecs
171 import cfgparser
172 f = codecs.open(self.logfile,'w','utf8')
173@@ -99,6 +99,7 @@
174 useropts = cfgparser.getuseroptions(inistring)
175 inistring = cfgparser.setuseroptions(inistring,useropts)
176 f.write('##### Parsed config.ini file##### :\x0a%s\x0a##################################\x0a\x0a\x0a'%(inistring))
177+ # TODO: Why del(codecs)?
178 del(codecs)
179 del(cfgparser)
180 formatter = logging.Formatter("%(asctime)s\t%(levelname)s\t%(name)s\t%(lineno)s\t%(funcName)s()\t%(message)s")
181@@ -430,7 +431,7 @@
182 try:
183 result = self.filtergraph.buildqueue(self.srcqueue,list(self.files))
184
185- except KeyboardInterrupt,e:
186+ except KeyboardInterrupt:
187 logger.info('%s\t%s',*['stop','Ctrl-C user request'])
188 return 251
189
190
191=== modified file 'trunk/lib/corpusfg/plugins/add-line-numbers.py'
192--- trunk/lib/corpusfg/plugins/add-line-numbers.py 2013-01-01 15:15:07 +0000
193+++ trunk/lib/corpusfg/plugins/add-line-numbers.py 2013-04-17 07:15:36 +0000
194@@ -90,6 +90,7 @@
195 try:
196 # loop writes output line-by-line
197 for line in i:
198+ # TODO: linenum is undefined. Does this code work?
199 o.write('<s id=\"%d\">\t%s'%(linenum,line.rstrip('\r\n')))
200 progress.increment_amount()
201 sys.stderr.write(progress.bar)
202
203=== modified file 'trunk/lib/corpusfg/plugins/aligner-passthrough.py'
204--- trunk/lib/corpusfg/plugins/aligner-passthrough.py 2013-01-01 15:15:07 +0000
205+++ trunk/lib/corpusfg/plugins/aligner-passthrough.py 2013-04-17 07:15:36 +0000
206@@ -67,6 +67,5 @@
207 at: http://www.precisiontranslationtools.com'''
208
209 if __name__ == "__main__":
210- import os
211 import sys
212 sys.stdout.write(usage().encode('utf8')+'\n')
213
214=== modified file 'trunk/lib/corpusfg/plugins/delete-files.py'
215--- trunk/lib/corpusfg/plugins/delete-files.py 2013-01-01 15:15:07 +0000
216+++ trunk/lib/corpusfg/plugins/delete-files.py 2013-04-17 07:15:36 +0000
217@@ -11,7 +11,6 @@
218 import os
219 import sys
220 import logging
221-import shutil
222 import common as cf
223
224 logger = logging.getLogger('.'.join([os.path.splitext(os.path.basename(sys.argv[0]))[0],'manager','filtergraph',__name__]))
225
226=== modified file 'trunk/lib/corpusfg/plugins/ja/convert-ansi2full.py'
227--- trunk/lib/corpusfg/plugins/ja/convert-ansi2full.py 2013-01-01 15:15:07 +0000
228+++ trunk/lib/corpusfg/plugins/ja/convert-ansi2full.py 2013-04-17 07:15:36 +0000
229@@ -188,6 +188,7 @@
230
231 if self.exceptions:
232 for line in i:
233+ # TODO: unicodedata is undefined. Does this code work?
234 o.write('%s\n'%(u''.join([ch if ch in self.exception else unicodedata.normalize(self.form,ch) for ch in '\b'.join(line.rstrip('\r\n')).split('\b')])))
235 progress.increment_amount()
236 sys.stderr.write(progress.bar)
237
238=== modified file 'trunk/lib/corpusfg/plugins/ja/convert-full2ansi.py'
239--- trunk/lib/corpusfg/plugins/ja/convert-full2ansi.py 2013-01-01 15:15:07 +0000
240+++ trunk/lib/corpusfg/plugins/ja/convert-full2ansi.py 2013-04-17 07:15:36 +0000
241@@ -149,8 +149,6 @@
242 def close(self):
243 if skipclose: return
244
245- import os
246- import sys
247 import codecs
248 from progress_bar import ProgressBar
249
250@@ -190,6 +188,7 @@
251
252 if self.exceptions:
253 for line in i:
254+ # TODO: unicodedata is undefined. Does this code work?
255 o.write('%s\n'%(u''.join([ch if ch in self.exception else unicodedata.normalize(self.form,ch) for ch in '\b'.join(line.rstrip('\r\n')).split('\b')])))
256 progress.increment_amount()
257 sys.stderr.write(progress.bar)
258
259=== modified file 'trunk/lib/corpusfg/plugins/null-copyfile.py'
260--- trunk/lib/corpusfg/plugins/null-copyfile.py 2013-01-01 15:15:07 +0000
261+++ trunk/lib/corpusfg/plugins/null-copyfile.py 2013-04-17 07:15:36 +0000
262@@ -10,7 +10,16 @@
263
264 import os
265
266-import common as cf
267+# TODO: "logger" is used but undefined. This program will probably crash
268+# when trying to report anything out of the ordinary.
269+
270+# TODO: "filter" is not a good name for a class since there's already a
271+# standard function of that name.
272+
273+# TODO: This is used as a global variable, but might be more appropriate as a
274+# field inside the filter class.
275+skipclose = False
276+
277
278 class filter(object):
279
280@@ -98,6 +107,5 @@
281 at: http://www.precisiontranslationtools.com'''
282
283 if __name__ == "__main__":
284- import os
285 import sys
286 sys.stdout.write(usage().encode('utf8')+'\n')
287
288=== modified file 'trunk/lib/corpusfg/plugins/reader-null.py'
289--- trunk/lib/corpusfg/plugins/reader-null.py 2013-01-01 15:15:07 +0000
290+++ trunk/lib/corpusfg/plugins/reader-null.py 2013-04-17 07:15:36 +0000
291@@ -10,13 +10,10 @@
292
293 import sys
294 import os
295-import stat
296 import common as cf
297 import logging
298-import shutil
299 import codecs
300 from fnmatch import fnmatch
301-import glob
302 from progress_bar import ProgressBar
303
304 logger = logging.getLogger('.'.join([os.path.splitext(os.path.basename(sys.argv[0]))[0],'manager','filtergraph',__name__]))
305
306=== modified file 'trunk/lib/corpusfg/plugins/reader-tab.py'
307--- trunk/lib/corpusfg/plugins/reader-tab.py 2013-01-01 15:15:07 +0000
308+++ trunk/lib/corpusfg/plugins/reader-tab.py 2013-04-17 07:15:36 +0000
309@@ -276,8 +276,5 @@
310 at: http://www.precisiontranslationtools.com'''
311
312 if __name__ == "__main__":
313- import os
314- import sys
315- import sys
316 sys.stdout.write(usage().encode('utf8')+'\n')
317 sys.stdout.write(usage().encode('utf8')+'\n')
318
319=== modified file 'trunk/lib/corpusfg/plugins/reader-tmx.py'
320--- trunk/lib/corpusfg/plugins/reader-tmx.py 2013-01-01 15:15:07 +0000
321+++ trunk/lib/corpusfg/plugins/reader-tmx.py 2013-04-17 07:15:36 +0000
322@@ -13,7 +13,6 @@
323 import stat
324 import common as cf
325 import logging
326-import shutil
327 import codecs
328 import xml.etree.cElementTree as ElementTree
329 import re
330
331=== modified file 'trunk/lib/corpusfg/plugins/remove-multi-spaces.py'
332--- trunk/lib/corpusfg/plugins/remove-multi-spaces.py 2013-01-01 15:15:07 +0000
333+++ trunk/lib/corpusfg/plugins/remove-multi-spaces.py 2013-04-17 07:15:36 +0000
334@@ -14,6 +14,8 @@
335 import common as cf
336 import logging
337
338+from progress_bar import ProgressBar
339+
340 logger = logging.getLogger('.'.join([os.path.splitext(os.path.basename(sys.argv[0]))[0],'manager','filtergraph',__name__]))
341 skipclose = True
342
343
344=== modified file 'trunk/lib/corpusfg/plugins/repair-escapes.py'
345--- trunk/lib/corpusfg/plugins/repair-escapes.py 2013-01-01 15:15:07 +0000
346+++ trunk/lib/corpusfg/plugins/repair-escapes.py 2013-04-17 07:15:36 +0000
347@@ -12,7 +12,6 @@
348 import os
349 import sys
350 import re
351-import htmlentitydefs
352 import common as cf
353 import logging
354
355
356=== modified file 'trunk/lib/corpusfg/plugins/special-join.py'
357--- trunk/lib/corpusfg/plugins/special-join.py 2013-01-01 15:15:07 +0000
358+++ trunk/lib/corpusfg/plugins/special-join.py 2013-04-17 07:15:36 +0000
359@@ -9,7 +9,6 @@
360 #4.5.337 - version update
361
362 from copy import deepcopy
363-import common as cf
364
365 class filter(object):
366
367
368=== modified file 'trunk/lib/corpusfg/plugins/special-secondary-output.py'
369--- trunk/lib/corpusfg/plugins/special-secondary-output.py 2013-01-01 15:15:07 +0000
370+++ trunk/lib/corpusfg/plugins/special-secondary-output.py 2013-04-17 07:15:36 +0000
371@@ -53,7 +53,8 @@
372 self.cfextract[knew]['tempbuff'] = list(self.p.cfoutput[k]['tempbuff'])
373 try:
374 codecs.open(self.cfextract[knew]['tempname'],self.append,self.encoding).write(self.eol.join(self.cfextract[knew]['tempbuff'])+self.eol)
375- except Exception,e:
376+ except Exception:
377+ # TODO: Log the exception to help debugging.
378 return -2
379 else:
380 ext = self.p.writer.rendertypes
381
382=== modified file 'trunk/lib/corpusfg/plugins/special-split.py'
383--- trunk/lib/corpusfg/plugins/special-split.py 2013-01-01 15:15:07 +0000
384+++ trunk/lib/corpusfg/plugins/special-split.py 2013-04-17 07:15:36 +0000
385@@ -9,7 +9,6 @@
386 #4.5.337 - version update
387
388 from copy import deepcopy
389-import common as cf
390
391 class filter(object):
392
393
394=== modified file 'trunk/lib/corpusfg/plugins/subprocess-synch.py'
395--- trunk/lib/corpusfg/plugins/subprocess-synch.py 2013-01-01 15:15:07 +0000
396+++ trunk/lib/corpusfg/plugins/subprocess-synch.py 2013-04-17 07:15:36 +0000
397@@ -146,6 +146,7 @@
398 try:
399 # loop writes output line-by-line
400 for line in i:
401+ # TODO: tgtlang is undefined. Does this code work?
402 subproc[tgtlang]['popen'].stdin.write('%s\n'%(line.encode(self.encoding).strip()))
403 o.write('%s\n'%(subproc[tgtlang]['popen'].stdout.readline().rstrip('\r\n').decode(self.encoding)))
404 progress.increment_amount()
405
406=== modified file 'trunk/lib/corpusfg/plugins/writer-file.py'
407--- trunk/lib/corpusfg/plugins/writer-file.py 2013-01-01 15:15:07 +0000
408+++ trunk/lib/corpusfg/plugins/writer-file.py 2013-04-17 07:15:36 +0000
409@@ -13,7 +13,6 @@
410 import shutil
411 import codecs
412 from fnmatch import fnmatch
413-from flock import flock
414 import logging
415 import common as cf
416
417
418=== modified file 'trunk/lib/corpusfg/plugins/writer-null.py'
419--- trunk/lib/corpusfg/plugins/writer-null.py 2013-01-01 15:15:07 +0000
420+++ trunk/lib/corpusfg/plugins/writer-null.py 2013-04-17 07:15:36 +0000
421@@ -10,12 +10,8 @@
422
423 import sys
424 import os
425-import shutil
426-import codecs
427 from fnmatch import fnmatch
428-from flock import flock
429 import logging
430-import common as cf
431
432 logger = logging.getLogger('.'.join([os.path.splitext(os.path.basename(sys.argv[0]))[0],'manager','filtergraph',__name__]))
433
434
435=== modified file 'trunk/lib/corpusfg/plugins/writer-tab.py'
436--- trunk/lib/corpusfg/plugins/writer-tab.py 2013-01-01 15:15:07 +0000
437+++ trunk/lib/corpusfg/plugins/writer-tab.py 2013-04-17 07:15:36 +0000
438@@ -13,7 +13,6 @@
439 import shutil
440 import codecs
441 from fnmatch import fnmatch
442-from flock import flock
443 import logging
444 import common as cf
445
446
447=== modified file 'trunk/lib/corpusfg/plugins/writer-tmx.py'
448--- trunk/lib/corpusfg/plugins/writer-tmx.py 2013-01-01 15:15:07 +0000
449+++ trunk/lib/corpusfg/plugins/writer-tmx.py 2013-04-17 07:15:36 +0000
450@@ -11,9 +11,7 @@
451 import sys
452 import os
453 import shutil
454-import re
455 from fnmatch import fnmatch
456-from flock import flock
457 import xml.etree.cElementTree as ElementTree
458 from StringIO import StringIO
459 import logging
460
461=== modified file 'trunk/lib/corpusfg/plugins/zh_cn/convert-zh2traditional.py'
462--- trunk/lib/corpusfg/plugins/zh_cn/convert-zh2traditional.py 2013-01-01 15:15:07 +0000
463+++ trunk/lib/corpusfg/plugins/zh_cn/convert-zh2traditional.py 2013-04-17 07:15:36 +0000
464@@ -116,6 +116,7 @@
465
466 if self.exceptions:
467 for line in i:
468+ # TODO: unicodedata is undefined. Does this code work?
469 o.write('%s\n'%(u''.join([ch if ch in self.exception else unicodedata.normalize(self.form,ch) for ch in '\b'.join(line.rstrip('\r\n')).split('\b')])))
470 progress.increment_amount()
471 sys.stderr.write(progress.bar)
472
473=== modified file 'trunk/lib/corpusfg/plugins/zh_hk/convert-zh2simplified.py'
474--- trunk/lib/corpusfg/plugins/zh_hk/convert-zh2simplified.py 2013-01-01 15:15:07 +0000
475+++ trunk/lib/corpusfg/plugins/zh_hk/convert-zh2simplified.py 2013-04-17 07:15:36 +0000
476@@ -116,6 +116,7 @@
477
478 if self.exceptions:
479 for line in i:
480+ # TODO: unicodedata is undefined. Does this code work?
481 o.write('%s\n'%(u''.join([ch if ch in self.exception else unicodedata.normalize(self.form,ch) for ch in '\b'.join(line.rstrip('\r\n')).split('\b')])))
482 progress.increment_amount()
483 sys.stderr.write(progress.bar)
484
485=== modified file 'trunk/lib/corpusfg/progress_bar.py'
486--- trunk/lib/corpusfg/progress_bar.py 2013-01-01 15:15:07 +0000
487+++ trunk/lib/corpusfg/progress_bar.py 2013-04-17 07:15:36 +0000
488@@ -42,7 +42,7 @@
489 along with this program. If not, see http://www.gnu.org/licenses/.'''
490
491
492-import sys, os
493+import sys
494
495 class ProgressBar:
496
497
498=== modified file 'trunk/lib/corpusfg/pstat.py'
499--- trunk/lib/corpusfg/pstat.py 2012-05-02 15:46:23 +0000
500+++ trunk/lib/corpusfg/pstat.py 2013-04-17 07:15:36 +0000
501@@ -108,8 +108,10 @@
502 ##
503 ## 11/08/98 ... fixed aput to output large arrays correctly
504
505+# TODO: Why is stats required? It's not used in here.
506 import stats # required 3rd party module
507 import string, copy
508+# TODO: Is this import needed?
509 from types import *
510
511 __version__ = 0.4
512@@ -120,6 +122,7 @@
513 ### Array functions (for NumPy-enabled computers) appear below.
514 ###
515
516+# TODO: abut? Or about? Is this actually used?
517 def abut (source,*args):
518 '''
519 Like the |Stat abut command. It concatenates two lists side-by-side
520
521=== modified file 'trunk/lib/corpusfg/stats.py'
522--- trunk/lib/corpusfg/stats.py 2012-05-02 15:46:23 +0000
523+++ trunk/lib/corpusfg/stats.py 2013-04-17 07:15:36 +0000
524@@ -227,6 +227,7 @@
525
526 import pstat # required 3rd party module
527 import math, string, copy # required python modules
528+# TODO: Is this import needed?
529 from types import *
530
531 __version__ = 0.6
532@@ -420,7 +421,7 @@
533 '''
534 try:
535 x = moment(inlist,3)/pow(moment(inlist,2),1.5)
536- except Exception, e:
537+ except Exception:
538 x = 0
539 return x
540
541@@ -432,9 +433,10 @@
542
543 Usage: lkurtosis(inlist)
544 '''
545+ # TODO: This always returns 0. Is there a point?
546 try:
547 x = moment(inlist,4)/pow(moment(inlist,2),2.0)
548- except Exception, e:
549+ except Exception:
550 x = 0
551 return 0
552
553@@ -677,7 +679,7 @@
554 deviations[i] = inlist[i] - mn
555 try:
556 x = ss(deviations)/float(n-1)
557- except Exception, e:
558+ except Exception:
559 x = 0
560 return x
561
562@@ -859,6 +861,7 @@
563 n = len(x)
564 x = map(float,x)
565 y = map(float,y)
566+ # TODO: xmean and ymean are not used. Are they needed?
567 xmean = mean(x)
568 ymean = mean(y)
569 r_num = n*(summult(x,y)) - sum(x)*sum(y)
570@@ -892,6 +895,7 @@
571 Usage: lspearmanr(x,y) where x and y are equal-length lists
572 Returns: Spearman's r, two-tailed p-value
573 '''
574+ # TODO: TINY is not used. Is it needed?
575 TINY = 1e-30
576 if len(x) <> len(y):
577 raise ValueError, 'Input values not paired in spearmanr. Aborting.'
578@@ -927,6 +931,7 @@
579 raise ValueError, "Exactly 2 categories required for pointbiserialr()."
580 else: # there are 2 categories, continue
581 codemap = pstat.abut(categories,range(2))
582+ # TODO: recoded is not used. Is it needed?
583 recoded = pstat.recode(data,codemap,0)
584 x = pstat.linexand(data,0,categories[0])
585 y = pstat.linexand(data,0,categories[1])
586@@ -994,6 +999,7 @@
587 r_num = float(n*(summult(x,y)) - sum(x)*sum(y))
588 r_den = math.sqrt((n*ss(x) - square_of_sums(x))*(n*ss(y)-square_of_sums(y)))
589 r = r_num / r_den
590+ # TODO: z is not used. Is it needed?
591 z = 0.5*math.log((1.0+r+TINY)/(1.0-r+TINY))
592 df = n-2
593 t = r*math.sqrt(df/((1.0-r+TINY)*(1.0+r+TINY)))
594@@ -1175,6 +1181,7 @@
595 n2 = len(y)
596 ranked = rankdata(x+y)
597 rankx = ranked[0:n1] # get the x-ranks
598+ # TODO: ranky is not used. Is it needed?
599 ranky = ranked[n1:] # the rest are y-ranks
600 u1 = n1*n2 + (n1*(n1+1))/2.0 - sum(rankx) # calc U for x
601 u2 = n1*n2 - u1 # remainder is U for y
602@@ -1582,8 +1589,11 @@
603 ns = [0]*a
604 alldata = []
605 tmp = map(N.array,lists)
606+ # TODO: means is not used. Is it needed?
607 means = map(amean,tmp)
608+ # TODO: Assigning to vars is weird and scary. Can we avoid it?
609 vars = map(avar,tmp)
610+ # TODO: ns is not used. Is it needed?
611 ns = map(len,lists)
612 for i in range(len(lists)):
613 alldata = alldata + lists[i]
614@@ -1823,6 +1833,7 @@
615 '''
616 suffix = '' # for *s after the p-value
617 try:
618+ # TODO: x is not used. Is it needed?
619 x = prob.shape
620 prob = prob[0]
621 except:
622@@ -2037,6 +2048,7 @@
623 if keepdims == 1:
624 shp = list(inarray.shape)
625 shp[dimension] = 1
626+ # TODO: Is this meant to override sum()!?
627 sum = N.reshape(sum,shp)
628 else: # must be a SEQUENCE of dims to average over
629 dims = list(dimension)
630@@ -2371,6 +2383,7 @@
631 mask = lowerfcn(a,limits[0])
632 elif limits[0]<>None and limits[1]<>None:
633 mask = lowerfcn(a,limits[0])*upperfcn(a,limits[1])
634+ # TODO: term1 is not used. Is it needed?
635 term1 = N.add.reduce(N.ravel(a*a*mask))
636 n = float(N.add.reduce(N.ravel(mask)))
637 return sd/math.sqrt(n)
638@@ -2468,6 +2481,7 @@
639 mm = (N.minimum.reduce(inarray),N.maximum.reduce(inarray))
640 m = amean(inarray,dimension)
641 sd = astdev(inarray,dimension)
642+ # TODO: skew is not used. Is it needed?
643 skew = askew(inarray,dimension)
644 kurt = akurtosis(inarray,dimension)
645 # return n, mm, m, sd, skew, kurt
646@@ -3137,6 +3151,7 @@
647 '''
648 TINY = 1.0e-20
649 n = len(x)
650+ # TODO: xmean and ymean are not used. Are they needed?
651 xmean = amean(x)
652 ymean = amean(y)
653 r_num = n*(N.add.reduce(x*y)) - N.add.reduce(x)*N.add.reduce(y)
654@@ -3156,6 +3171,7 @@
655 Usage: aspearmanr(x,y) where x,y are equal-length arrays
656 Returns: Spearman's r, two-tailed p-value
657 '''
658+ # TODO: TINY is not used. Is it needed?
659 TINY = 1e-30
660 n = len(x)
661 rankx = rankdata(x)
662@@ -3186,6 +3202,7 @@
663 raise ValueError, "Exactly 2 categories required (in x) for pointbiserialr()."
664 else: # there are 2 categories, continue
665 codemap = pstat.aabut(categories,N.arange(2))
666+ # TODO: recoded is not used. Is it needed?
667 recoded = pstat.arecode(data,codemap,0)
668 x = pstat.alinexand(data,0,categories[0])
669 y = pstat.alinexand(data,0,categories[1])
670@@ -3262,6 +3279,7 @@
671 r_num = n*(N.add.reduce(x*y)) - N.add.reduce(x)*N.add.reduce(y)
672 r_den = math.sqrt((n*ass(x) - asquare_of_sums(x))*(n*ass(y)-asquare_of_sums(y)))
673 r = r_num / r_den
674+ # TODO: z is not used. Is it needed?
675 z = 0.5*math.log((1.0+r+TINY)/(1.0-r+TINY))
676 df = n-2
677 t = r*math.sqrt(df/((1.0-r+TINY)*(1.0+r+TINY)))
678@@ -3304,6 +3322,7 @@
679 r_den = N.where(zerodivproblem,1,r_den) # avoid zero-division in 1st place
680 r = r_num / r_den # need to do this nicely for matrix division
681 r = N.where(zerodivproblem,0.0,r)
682+ # TODO: z is not used. Is it needed?
683 z = 0.5*N.log((1.0+r+TINY)/(1.0-r+TINY))
684 df = n-2
685 t = r*N.sqrt(df/((1.0-r+TINY)*(1.0+r+TINY)))
686@@ -3555,6 +3574,7 @@
687 n2 = len(y)
688 ranked = rankdata(N.concatenate((x,y)))
689 rankx = ranked[0:n1] # get the x-ranks
690+ # TODO: ranky is not used. Is it needed?
691 ranky = ranked[n1:] # the rest are y-ranks
692 u1 = n1*n2 + (n1*(n1+1))/2.0 - sum(rankx) # calc U for x
693 u2 = n1*n2 - u1 # remainder is U for y
694@@ -3725,6 +3745,7 @@
695 exponents = N.where(N.less(x,-BIG),-BIG,x)
696 return N.exp(exponents)
697
698+ # TODO: arrayflag is not used. Is it needed?
699 if type(chisq) == N.ndarray:
700 arrayflag = 1
701 else:
702@@ -4017,7 +4038,7 @@
703 ####### AANOVA CALCULATIONS #######
704 #####################################
705
706- import LinearAlgebra, operator
707+ import LinearAlgebra
708 LA = LinearAlgebra
709
710 def aglm(data,para):
711@@ -4069,8 +4090,11 @@
712 ns = [0]*na
713 alldata = []
714 tmp = map(N.array,args)
715+ # TODO: means is never used. Is it needed?
716 means = map(amean,tmp)
717+ # TODO: Assigning to vars is weird and scary. Can we avoid it?
718 vars = map(avar,tmp)
719+ # TODO: ns is never used. Is it needed?
720 ns = map(len,args)
721 alldata = N.concatenate(args)
722 bign = len(alldata)
723@@ -4281,6 +4305,7 @@
724 Returns: sum[ravel(a-b)**2]
725 '''
726 if dimension == None:
727+ # TODO: inarray is never used. Is it needed?
728 inarray = N.ravel(a)
729 dimension = 0
730 return asum((a-b)**2,dimension,keepdims)
731
732=== modified file 'trunk/lib/corpusfg/unicode_block.py'
733--- trunk/lib/corpusfg/unicode_block.py 2012-05-02 15:46:23 +0000
734+++ trunk/lib/corpusfg/unicode_block.py 2013-04-17 07:15:36 +0000
735@@ -6,6 +6,7 @@
736 if type(ch) == type(''): ch = unicode(ch)
737 assert isinstance(ch, unicode) and len(ch) == 1, repr(ch)
738 cp = ord(ch)
739+ # TODO: _blocks is undefined. Is this function used?
740 for start, end, name in _blocks:
741 if start <= cp <= end:
742 return unicode(name)

Subscribers

People subscribed via source and target branches

to all changes: