summaryrefslogtreecommitdiff
path: root/plugins/externaltools
diff options
context:
space:
mode:
authorPaolo Borelli <pborelli@gnome.org>2014-03-29 22:08:39 +0100
committerPaolo Borelli <pborelli@gnome.org>2014-03-29 22:08:39 +0100
commit3b9fdc6bffd4f50072f4d452599e0db6114ed0d9 (patch)
tree552508f161236f15a3ce16851d53c8f56f15c6c3 /plugins/externaltools
parent0cbf5a45300aea89ba62617b1060e19210269845 (diff)
downloadgedit-3b9fdc6bffd4f50072f4d452599e0db6114ed0d9.tar.gz
externaltools: whitespace pep8 fixes
Diffstat (limited to 'plugins/externaltools')
-rw-r--r--plugins/externaltools/tools/filelookup.py8
-rw-r--r--plugins/externaltools/tools/functions.py74
-rw-r--r--plugins/externaltools/tools/library.py76
-rw-r--r--plugins/externaltools/tools/linkparsing.py12
-rw-r--r--plugins/externaltools/tools/linkparsing_test.py1
-rw-r--r--plugins/externaltools/tools/manager.py42
6 files changed, 133 insertions, 80 deletions
diff --git a/plugins/externaltools/tools/filelookup.py b/plugins/externaltools/tools/filelookup.py
index 0d88d51a3..f51583df1 100644
--- a/plugins/externaltools/tools/filelookup.py
+++ b/plugins/externaltools/tools/filelookup.py
@@ -20,11 +20,12 @@ import os
from gi.repository import Gio, Gedit
from .functions import *
+
class FileLookup:
"""
This class is responsible for looking up files given a part or the whole
- path of a real file. The lookup is delegated to providers wich use different
- methods of trying to find the real file.
+ path of a real file. The lookup is delegated to providers wich use
+ different methods of trying to find the real file.
"""
def __init__(self, window):
@@ -78,6 +79,7 @@ class AbsoluteFileLookupProvider(FileLookupProvider):
else:
return None
+
class BrowserRootFileLookupProvider(FileLookupProvider):
"""
This lookup provider tries to find a file specified by the path relative to
@@ -92,7 +94,7 @@ class BrowserRootFileLookupProvider(FileLookupProvider):
real_path = os.path.join(root, path)
if os.path.isfile(real_path):
return Gio.file_new_for_path(real_path)
-
+
return None
diff --git a/plugins/externaltools/tools/functions.py b/plugins/externaltools/tools/functions.py
index 2aedecd70..ba0960a08 100644
--- a/plugins/externaltools/tools/functions.py
+++ b/plugins/externaltools/tools/functions.py
@@ -20,24 +20,27 @@ import os
from gi.repository import Gio, Gtk, Gdk, GtkSource, Gedit
from .capture import *
+
def default(val, d):
if val is not None:
return val
else:
return d
+
def current_word(document):
piter = document.get_iter_at_mark(document.get_insert())
start = piter.copy()
-
+
if not piter.starts_word() and (piter.inside_word() or piter.ends_word()):
start.backward_word_start()
-
+
if not piter.ends_word() and piter.inside_word():
piter.forward_word_end()
-
+
return (start, piter)
+
def file_browser_root(window):
bus = window.get_message_bus()
@@ -49,67 +52,68 @@ def file_browser_root(window):
if browser_root and browser_root.is_native():
return browser_root.get_path()
-
+
return None
+
# ==== Capture related functions ====
def run_external_tool(window, panel, node):
# Configure capture environment
try:
cwd = os.getcwd()
except OSError:
- cwd = os.getenv('HOME');
+ cwd = os.getenv('HOME')
capture = Capture(node.command, cwd)
capture.env = os.environ.copy()
- capture.set_env(GEDIT_CWD = cwd)
+ capture.set_env(GEDIT_CWD=cwd)
view = window.get_active_view()
if view is not None:
# Environment vars relative to current document
document = view.get_buffer()
location = document.get_location()
-
+
# Current line number
piter = document.get_iter_at_mark(document.get_insert())
capture.set_env(GEDIT_CURRENT_LINE_NUMBER=str(piter.get_line() + 1))
-
+
# Current line text
piter.set_line_offset(0)
end = piter.copy()
-
+
if not end.ends_line():
end.forward_to_line_end()
-
+
capture.set_env(GEDIT_CURRENT_LINE=piter.get_text(end))
-
+
if document.get_language() is not None:
capture.set_env(GEDIT_CURRRENT_DOCUMENT_LANGUAGE=document.get_language().get_id())
# Selected text (only if input is not selection)
if node.input != 'selection' and node.input != 'selection-document':
bounds = document.get_selection_bounds()
-
+
if bounds:
capture.set_env(GEDIT_SELECTED_TEXT=bounds[0].get_text(bounds[1]))
-
+
bounds = current_word(document)
capture.set_env(GEDIT_CURRENT_WORD=bounds[0].get_text(bounds[1]))
-
+
capture.set_env(GEDIT_CURRENT_DOCUMENT_TYPE=document.get_mime_type())
-
+
if location is not None:
scheme = location.get_uri_scheme()
name = location.get_basename()
- capture.set_env(GEDIT_CURRENT_DOCUMENT_URI = location.get_uri(),
- GEDIT_CURRENT_DOCUMENT_NAME = name,
- GEDIT_CURRENT_DOCUMENT_SCHEME = scheme)
+ capture.set_env(GEDIT_CURRENT_DOCUMENT_URI=location.get_uri(),
+ GEDIT_CURRENT_DOCUMENT_NAME=name,
+ GEDIT_CURRENT_DOCUMENT_SCHEME=scheme)
if location.has_uri_scheme('file'):
path = location.get_path()
cwd = os.path.dirname(path)
capture.set_cwd(cwd)
- capture.set_env(GEDIT_CURRENT_DOCUMENT_PATH = path,
- GEDIT_CURRENT_DOCUMENT_DIR = cwd)
+ capture.set_env(GEDIT_CURRENT_DOCUMENT_PATH=path,
+ GEDIT_CURRENT_DOCUMENT_DIR=cwd)
documents_location = [doc.get_location()
for doc in window.get_documents()
@@ -120,16 +124,16 @@ def run_external_tool(window, panel, node):
documents_path = [location.get_path()
for location in documents_location
if location.has_uri_scheme('file')]
- capture.set_env(GEDIT_DOCUMENTS_URI = ' '.join(documents_uri),
- GEDIT_DOCUMENTS_PATH = ' '.join(documents_path))
+ capture.set_env(GEDIT_DOCUMENTS_URI=' '.join(documents_uri),
+ GEDIT_DOCUMENTS_PATH=' '.join(documents_path))
# set file browser root env var if possible
browser_root = file_browser_root(window)
if browser_root:
- capture.set_env(GEDIT_FILE_BROWSER_ROOT = browser_root)
+ capture.set_env(GEDIT_FILE_BROWSER_ROOT=browser_root)
flags = capture.CAPTURE_BOTH
-
+
if not node.has_hash_bang():
flags |= capture.CAPTURE_NEEDS_SHELL
@@ -163,7 +167,7 @@ def run_external_tool(window, panel, node):
else:
start = document.get_iter_at_mark(document.get_insert())
end = start.copy()
-
+
elif input_type == 'line':
start = document.get_iter_at_mark(document.get_insert())
end = start.copy()
@@ -232,6 +236,7 @@ def run_external_tool(window, panel, node):
if output_type != 'nothing':
document.end_user_action()
+
class MultipleDocumentsSaver:
def __init__(self, window, panel, all_docs, node):
self._window = window
@@ -247,7 +252,7 @@ class MultipleDocumentsSaver:
else:
docs = [window.get_active_document()]
- docs_to_save = [ doc for doc in docs if doc.get_modified() ]
+ docs_to_save = [doc for doc in docs if doc.get_modified()]
signals = {}
for doc in docs_to_save:
@@ -271,10 +276,10 @@ class MultipleDocumentsSaver:
def on_document_saved(self, doc, error):
if error:
self._error = True
-
+
doc.disconnect(self._signal_ids[doc])
del self._signal_ids[doc]
-
+
self._counter -= 1
self.run_tool()
@@ -283,6 +288,7 @@ class MultipleDocumentsSaver:
if self._counter == 0 and not self._error:
run_external_tool(self._window, self._panel, self._node)
+
def capture_menu_action(action, parameter, window, panel, node):
if node.save_files == 'document' and window.get_active_document():
MultipleDocumentsSaver(window, panel, False, node)
@@ -293,26 +299,29 @@ def capture_menu_action(action, parameter, window, panel, node):
run_external_tool(window, panel, node)
+
def capture_stderr_line_panel(capture, line, panel):
if not panel.visible():
panel.show()
panel.write(line, panel.error_tag)
+
def capture_begin_execute_panel(capture, panel, view, label):
if view:
view.get_window(Gtk.TextWindowType.TEXT).set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
panel['stop'].set_sensitive(True)
panel.clear()
- panel.write(_("Running tool:"), panel.italic_tag);
- panel.write(" %s\n\n" % label, panel.bold_tag);
+ panel.write(_("Running tool:"), panel.italic_tag)
+ panel.write(" %s\n\n" % label, panel.bold_tag)
+
def capture_end_execute_panel(capture, exit_code, panel, view, output_type):
panel['stop'].set_sensitive(False)
if view:
- if output_type in ('new-document','replace-document'):
+ if output_type in ('new-document', 'replace-document'):
doc = view.get_buffer()
start = doc.get_start_iter()
end = start.copy()
@@ -340,12 +349,15 @@ def capture_end_execute_panel(capture, exit_code, panel, view, output_type):
panel.write("\n" + _("Exited") + ":", panel.italic_tag)
panel.write(" %d\n" % exit_code, panel.bold_tag)
+
def capture_stdout_line_panel(capture, line, panel):
panel.write(line)
+
def capture_stdout_line_document(capture, line, document, pos):
document.insert(pos, line)
+
def capture_delayed_replace(capture, line, document, start_iter, end_iter):
document.delete(start_iter, end_iter)
diff --git a/plugins/externaltools/tools/library.py b/plugins/externaltools/tools/library.py
index b1f21136a..478b617be 100644
--- a/plugins/externaltools/tools/library.py
+++ b/plugins/externaltools/tools/library.py
@@ -22,21 +22,22 @@ import locale
import platform
from gi.repository import GLib
+
class Singleton(object):
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
- cls._instance = super(Singleton, cls).__new__(
- cls, *args, **kwargs)
+ cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
cls._instance.__init_once__()
return cls._instance
+
class ToolLibrary(Singleton):
def __init_once__(self):
self.locations = []
-
+
def set_locations(self, datadir):
self.locations = []
@@ -56,7 +57,7 @@ class ToolLibrary(Singleton):
else:
toolsdir = os.path.join(GLib.get_user_config_dir(), 'gedit/tools')
- self.locations.insert(0, toolsdir);
+ self.locations.insert(0, toolsdir)
if not os.path.isdir(self.locations[0]):
os.makedirs(self.locations[0])
@@ -111,7 +112,7 @@ class ToolLibrary(Singleton):
tool.save_with_script(xtool.text)
- def get_full_path(self, path, mode='r', system = True, local = True):
+ def get_full_path(self, path, mode='r', system=True, local=True):
assert (system or local)
if path is None:
return None
@@ -137,6 +138,7 @@ class ToolLibrary(Singleton):
os.mkdir(dirname)
return path
+
class ToolDirectory(object):
def __init__(self, parent, dirname):
super(ToolDirectory, self).__init__()
@@ -209,7 +211,7 @@ class ToolDirectory(object):
class Tool(object):
RE_KEY = re.compile('^([a-zA-Z_][a-zA-Z0-9_.\-]*)(\[([a-zA-Z_@]+)\])?$')
- def __init__(self, parent, filename = None):
+ def __init__(self, parent, filename=None):
super(Tool, self).__init__()
self.parent = parent
self.library = parent.library
@@ -226,7 +228,7 @@ class Tool(object):
return []
else:
return [x.strip() for x in value.split(',')]
-
+
def _from_list(self, value):
return ','.join(value)
@@ -252,8 +254,10 @@ class Tool(object):
if not in_block:
in_block = line.startswith('# [Gedit Tool]')
continue
- if line.startswith('##') or line.startswith('# #'): continue
- if not line.startswith('# '): break
+ if line.startswith('##') or line.startswith('# #'):
+ continue
+ if not line.startswith('# '):
+ break
try:
(key, value) = [i.strip() for i in line[2:].split('=', 1)]
@@ -266,7 +270,7 @@ class Tool(object):
break
fp.close()
self.changed = False
-
+
def _set_property_if_changed(self, key, value):
if value != self._properties.get(key):
self._properties[key] = value
@@ -297,66 +301,90 @@ class Tool(object):
def get_applicability(self):
applicability = self._properties.get('Applicability')
- if applicability: return applicability
+ if applicability:
+ return applicability
return 'all'
+
def set_applicability(self, value):
self._set_property_if_changed('Applicability', value)
+
applicability = property(get_applicability, set_applicability)
def get_name(self):
name = self._properties.get('Name')
- if name: return name
+ if name:
+ return name
return os.path.basename(self.filename)
+
def set_name(self, value):
self._set_property_if_changed('Name', value)
+
name = property(get_name, set_name)
def get_shortcut(self):
shortcut = self._properties.get('Shortcut')
- if shortcut: return shortcut
+ if shortcut:
+ return shortcut
return None
+
def set_shortcut(self, value):
self._set_property_if_changed('Shortcut', value)
+
shortcut = property(get_shortcut, set_shortcut)
def get_comment(self):
comment = self._properties.get('Comment')
- if comment: return comment
+ if comment:
+ return comment
return self.filename
+
def set_comment(self, value):
self._set_property_if_changed('Comment', value)
+
comment = property(get_comment, set_comment)
def get_input(self):
input = self._properties.get('Input')
- if input: return input
+ if input:
+ return input
return 'nothing'
+
def set_input(self, value):
self._set_property_if_changed('Input', value)
+
input = property(get_input, set_input)
def get_output(self):
output = self._properties.get('Output')
- if output: return output
+ if output:
+ return output
return 'output-panel'
+
def set_output(self, value):
self._set_property_if_changed('Output', value)
+
output = property(get_output, set_output)
def get_save_files(self):
save_files = self._properties.get('Save-files')
- if save_files: return save_files
+ if save_files:
+ return save_files
return 'nothing'
+
def set_save_files(self, value):
self._set_property_if_changed('Save-files', value)
+
save_files = property(get_save_files, set_save_files)
-
+
def get_languages(self):
languages = self._properties.get('Languages')
- if languages: return languages
+ if languages:
+ return languages
return []
+
def set_languages(self, value):
self._set_property_if_changed('Languages', value)
+
languages = property(get_languages, set_languages)
def has_hash_bang(self):
@@ -371,7 +399,6 @@ class Tool(object):
for line in fp:
if line.strip() == '':
continue
-
return line.startswith('#!')
# There is no property for this one because this function is quite
@@ -394,7 +421,8 @@ class Tool(object):
lines.append(line)
# in the block:
for line in fp:
- if line.startswith('##'): continue
+ if line.startswith('##'):
+ continue
if not (line.startswith('# ') and '=' in line):
# after the block: strip one emtpy line (if present)
if line.strip() != '':
@@ -417,7 +445,6 @@ class Tool(object):
def save_with_script(self, script):
filename = self.library.get_full_path(self.filename, 'w')
-
fp = open(filename, 'w', 1)
# Make sure to first print header (shebang, modeline), then
@@ -429,7 +456,6 @@ class Tool(object):
# Parse
for line in script:
line = line.rstrip("\n")
-
if not inheader:
content.append(line)
elif line.startswith('#!'):
@@ -444,10 +470,10 @@ class Tool(object):
# Write out header
for line in header:
fp.write(line + "\n")
-
+
fp.write(self._dump_properties())
fp.write("\n")
-
+
for line in content:
fp.write(line + "\n")
diff --git a/plugins/externaltools/tools/linkparsing.py b/plugins/externaltools/tools/linkparsing.py
index 77f9c67ad..66c9e254a 100644
--- a/plugins/externaltools/tools/linkparsing.py
+++ b/plugins/externaltools/tools/linkparsing.py
@@ -18,6 +18,7 @@
import re
+
class Link:
"""
This class represents a file link from within a string given by the
@@ -34,16 +35,17 @@ class Link:
start -- the index within the string that the link starts at
end -- the index within the string where the link ends at
"""
- self.path = path
+ self.path = path
self.line_nr = int(line_nr)
- self.col_nr = int(col_nr)
- self.start = start
- self.end = end
+ self.col_nr = int(col_nr)
+ self.start = start
+ self.end = end
def __repr__(self):
return "%s[%s][%s](%s:%s)" % (self.path, self.line_nr, self.col_nr,
self.start, self.end)
+
class LinkParser:
"""
Parses a text using different parsing providers with the goal of finding one
@@ -103,6 +105,7 @@ class LinkParser:
return links
+
class AbstractLinkParser(object):
"""The "abstract" base class for link parses"""
@@ -118,6 +121,7 @@ class AbstractLinkParser(object):
"""
raise NotImplementedError("need to implement a parse method")
+
class RegexpLinkParser(AbstractLinkParser):
"""
A class that represents parsers that only use one single regular expression.
diff --git a/plugins/externaltools/tools/linkparsing_test.py b/plugins/externaltools/tools/linkparsing_test.py
index 187a2f8e1..6072ee8a5 100644
--- a/plugins/externaltools/tools/linkparsing_test.py
+++ b/plugins/externaltools/tools/linkparsing_test.py
@@ -19,6 +19,7 @@
import unittest
from linkparsing import LinkParser
+
class LinkParserTest(unittest.TestCase):
def setUp(self):
diff --git a/plugins/externaltools/tools/manager.py b/plugins/externaltools/tools/manager.py
index e2675c66e..3408f5654 100644
--- a/plugins/externaltools/tools/manager.py
+++ b/plugins/externaltools/tools/manager.py
@@ -25,6 +25,7 @@ import hashlib
from xml.sax import saxutils
from gi.repository import Gio, GObject, Gtk, GtkSource, Gedit
+
class LanguagesPopup(Gtk.Popover):
__gtype_name__ = "LanguagePopup"
@@ -127,9 +128,10 @@ class LanguagesPopup(Gtk.Popover):
else:
self.model.set_value(self.model.get_iter_first(), self.COLUMN_ENABLED, False)
+
class Manager(GObject.Object):
- TOOL_COLUMN = 0 # For Tree
- NAME_COLUMN = 1 # For Combo
+ TOOL_COLUMN = 0 # For Tree
+ NAME_COLUMN = 1 # For Combo
__gsignals__ = {
'tools-updated': (GObject.SignalFlags.RUN_LAST, None, ())
@@ -150,17 +152,17 @@ class Manager(GObject.Object):
def build(self):
callbacks = {
- 'on_add_tool_button_clicked' : self.on_add_tool_button_clicked,
- 'on_remove_tool_button_clicked' : self.on_remove_tool_button_clicked,
- 'on_tool_manager_dialog_delete_event' : self.on_tool_manager_dialog_delete_event,
+ 'on_add_tool_button_clicked': self.on_add_tool_button_clicked,
+ 'on_remove_tool_button_clicked': self.on_remove_tool_button_clicked,
+ 'on_tool_manager_dialog_delete_event': self.on_tool_manager_dialog_delete_event,
'on_tool_manager_dialog_focus_out': self.on_tool_manager_dialog_focus_out,
'on_tool_manager_dialog_configure_event': self.on_tool_manager_dialog_configure_event,
- 'on_accelerator_key_press' : self.on_accelerator_key_press,
- 'on_accelerator_focus_in' : self.on_accelerator_focus_in,
- 'on_accelerator_focus_out' : self.on_accelerator_focus_out,
- 'on_accelerator_backspace' : self.on_accelerator_backspace,
- 'on_applicability_changed' : self.on_applicability_changed,
- 'on_languages_button_clicked' : self.on_languages_button_clicked
+ 'on_accelerator_key_press': self.on_accelerator_key_press,
+ 'on_accelerator_focus_in': self.on_accelerator_focus_in,
+ 'on_accelerator_focus_out': self.on_accelerator_focus_out,
+ 'on_accelerator_backspace': self.on_accelerator_backspace,
+ 'on_applicability_changed': self.on_applicability_changed,
+ 'on_languages_button_clicked': self.on_languages_button_clicked
}
# Load the "main-window" widget from the ui file.
@@ -208,7 +210,7 @@ class Manager(GObject.Object):
self.view.get_selection().select_path(row.get_path())
def run(self, window):
- if self.dialog == None:
+ if self.dialog is None:
self.build()
# Open up language
@@ -379,7 +381,7 @@ class Manager(GObject.Object):
def save_current_tool(self):
if self.current_node is None:
- return
+ return
if self.current_node.filename is None:
self.current_node.autoset_filename()
@@ -544,7 +546,9 @@ class Manager(GObject.Object):
piter = self.add_tool(self.current_node)
- self.view.set_cursor(self.model.get_path(piter), self.view.get_column(self.TOOL_COLUMN), True)
+ self.view.set_cursor(self.model.get_path(piter),
+ self.view.get_column(self.TOOL_COLUMN),
+ True)
self.fill_fields()
self['tool-grid'].set_sensitive(True)
@@ -552,7 +556,9 @@ class Manager(GObject.Object):
def tool_changed(self, tool, refresh=False):
for row in self._tool_rows[tool]:
- self.model.set_value(self.model.get_iter(row.get_path()), self.TOOL_COLUMN, tool)
+ self.model.set_value(self.model.get_iter(row.get_path()),
+ self.TOOL_COLUMN,
+ tool)
if refresh and tool == self.current_node:
self.fill_fields()
@@ -596,7 +602,9 @@ class Manager(GObject.Object):
self.script_hash = None
if self.model.iter_is_valid(piter):
- self.view.set_cursor(self.model.get_path(piter), self.view.get_column(self.TOOL_COLUMN), False)
+ self.view.set_cursor(self.model.get_path(piter),
+ self.view.get_column(self.TOOL_COLUMN),
+ False)
self.view.grab_focus()
@@ -727,7 +735,7 @@ class Manager(GObject.Object):
def on_tool_manager_dialog_delete_event(self, dialog, event):
self.save_current_tool()
return False
-
+
def on_tool_manager_dialog_focus_out(self, dialog, event):
self.save_current_tool()
self.emit('tools-updated')