diff options
author | Agustin Zubiaga <olpc@xo-1b-99-29.localdomain> | 2011-12-06 00:39:31 (GMT) |
---|---|---|
committer | Agustin Zubiaga <olpc@xo-1b-99-29.localdomain> | 2011-12-06 00:39:31 (GMT) |
commit | a60de6a2365987d4c223a22c801f6984297e0927 (patch) | |
tree | 464dd7f9f69bd32839af8aadf83519720f5383bd /pep8_check.py | |
parent | b124747fd79b14b6b4fa7b3d89724339b1ba7d5b (diff) |
PEP8 now works, but has lot of bugs
Diffstat (limited to 'pep8_check.py')
-rw-r--r-- | pep8_check.py | 80 |
1 files changed, 66 insertions, 14 deletions
diff --git a/pep8_check.py b/pep8_check.py index 04954e4..ec2d5ca 100644 --- a/pep8_check.py +++ b/pep8_check.py @@ -1,6 +1,27 @@ #!/usr/bin/env python +# pep8_check.py by/por: +# Agustin Zubiaga <aguzubiaga97@gmail.com> +# Daniel Francis <santiago.danielfrancis@gmail.com> +# Sugarlabs - CeibalJAM! - Uruguay + +# 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 3 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 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, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + import logging +import gtk log = logging.getLogger('EditJam') log.setLevel(logging.DEBUG) @@ -9,40 +30,71 @@ import commands class PEP8_Check(): + def __init__(self, activity): self.activity = activity + def check_file(self, text, editor): tmp_file = open("/tmp/jamedit-pep8-chk.py", "w") - tmp_file.write(text) - tmp_file.close() + tmp_file.write(text) + tmp_file.close() - chk = self.get_check() + chk = self.get_check() - self.highlight_errors(editor, chk) + self.highlight_errors(editor, chk) def highlight_errors(self, editor, chk): - for key in chk.keys(): - # Here highlight errors whit tag pep8-error - log.debug('%s: %s' % (key, chk[key])) + text = editor._get_all_text() + editor.buffer.set_text("") + num = -1 + for line in text.split("\n"): + num += 1 + if str(num) in chk: + line_iter = editor.buffer.get_iter_at_line(num-1) + + editor.buffer.insert_with_tags(line_iter, line+"\n", editor.error_tag) + elif not num in chk: + char = 0 + line_iter = editor.buffer.get_iter_at_line(num) + if num != len(text.split("\n")): + editor.buffer.insert_with_tags_by_name(line_iter, line+"\n") + else: + editor.buffer.insert_with_tags_by_name(line_iter, line) + editor.connect("move-cursor", self.set_bar_text, chk) def get_check(self): (status, output) = commands.getstatusoutput( - "pep8 -r /tmp/jamedit-pep8-chk.py") + "python pep8/pep8.pyc --repeat /tmp/jamedit-pep8-chk.py") check = self.interpret_output(output) return check def interpret_output(self, output): checks = {} - outputs = output.split("\n") - for out in outputs: + outputs = output.split("\n") + for out in outputs: try: splits = out.split(":") - line = splits[1] + line = splits[1] character = splits[2] - error = splits[3] + error = splits[3] if line not in checks: checks[line] = '%s:%s' % (character, error) else: checks[line] = '%s; %s:%s' % ( checks[line], character, error) - except: pass + except: pass + + return checks - return checks + def set_bar_text(self, widget, step_size, count, extend_selection, check): + if step_size == gtk.MOVEMENT_DISPLAY_LINES: + cursor_position = widget.buffer.get_property("cursor-position") + offset_iter = widget.buffer.get_iter_at_offset(cursor_position) + line = offset_iter.get_line() + print line + if str(line) in check: + this_line_error = check[str(line)] + char = this_line_error.split(":")[0] + this_line_error = this_line_error.split(":")[1] + self.activity.pep8_bar.label.set_text(str(line)+":"+char+" "+this_line_error) + print this_line_error + self.activity.pep8_bar.show_all() + else: self.activity.pep8_bar.hide()
\ No newline at end of file |