Anonymous avatar Anonymous committed 41c9e39

Adjustments according to pyling remarks

Comments (0)

Files changed (1)

 # -*- coding: utf-8 -*-
+"""Sublime Text editor plugin providing Mercurial and HG Tortoise features as 
+editor commands. Provides following Sublime Text commands: 
 
-import os
-import sys
-import sublime, sublime_plugin
+ - hgtk_annotate
+ - hgtk_log
+ - thg_annotate
+ - thg_log
+
+"""
+
+# import os
+# import sys
+# import sublime
+import sublime_plugin
 import subprocess
 
 __version__ = "0.2"
     "HgMeldViewCommand",
 ]
 
+def check_command(command):
+    """Check if the command present in the OS."""
+    try:
+        subprocess.check_call(command)
+        return command
+    except subprocess.CalledProcessError:
+        pass
+    return None
+
+def get_tortoise_command():
+    """Get current tortoise command hgtk/thg."""
+    return check_command("hgtk") or check_command("thg")
+
 class BaseCommandMixin(object):
-
-    def check_command(self, command):
-        try:
-            subprocess.check_call(command)
-            return command
-        except subprocess.CalledProcessError, e:
-            pass
-        return None
-
-    def get_tortoise_command(self):
-        return self.check_command("hgtk") or self.check_command("thg")
+    """Base class for the plugin commands."""
 
     def get_view_root_folder(self):
+        """Get root folder for currently active view in Sublime editor."""
         file_name = self.view.file_name()
         if not file_name:
             return None
         return None
 
     def get_view_relative_file_name(self):
+        """Get relative file name of currently active view in Sublime editor."""
         root_folder = self.get_view_root_folder()
         file_name = self.view.file_name()
         if root_folder and file_name and file_name.startswith(root_folder):
         return file_name
 
     def do_tortoise_command_on_view(self, command):
-        hgtk_command = "%(main_command)s %(command)s -R %(root_folder)s \"%(file_name)s\"" % dict(
-            main_command=self.get_tortoise_command(),
+        """Perform given tortoise command on currently active view in Sublime 
+        editor."""
+        hgtk_command = (
+            "%(main_command)s %(command)s -R %(root_folder)s \"%(file_name)s\""
+        ) % dict(
+            main_command=get_tortoise_command(),
             command=command,
             root_folder=self.get_view_root_folder(),
             file_name=self.get_view_relative_file_name(),
 
 
 class HgtkAnnotateCommand(sublime_plugin.TextCommand, BaseCommandMixin):
+    """hgtk_annotate command class."""
 
     def run(self, edit):
+        """Run the command by Sublime editor."""
         #self.view.insert(edit, 0, sublime.__file__)
         self.do_tortoise_command_on_view("annotate")
 
 
 class HgtkLogCommand(sublime_plugin.TextCommand, BaseCommandMixin):
+    """hgtk_log command class."""
 
     def run(self, edit):
+        """Run the command by Sublime editor."""
         self.do_tortoise_command_on_view("log")
 
 
 class HgMeldViewCommand(sublime_plugin.TextCommand, BaseCommandMixin):
+    """hg_meld_view command class."""
 
     def run(self, edit):
+        """Run the command by Sublime editor."""
         hg_command = "hg extdiff -p meld %(file_name)s" % dict(
             file_name=self.view.file_name(),
         )
         do_system_command(hg_command)
 
 class HgMeldCommand(sublime_plugin.TextCommand, BaseCommandMixin):
+    """hg_meld command class."""
 
     def run(self, edit):
+        """Run the command by Sublime editor."""
         hg_command = "hg extdiff -p meld -R %(root_folder)s" % dict(
             root_folder=self.get_view_root_folder(),
         )
         do_system_command(hg_command)
 
-# Runs a system command from the command line
-# Captures and returns both stdout and stderr as an array, in that respective order
 def do_system_command(command_text):
+    """Runs a system command from the command line. Captures and returns both 
+    stdout and stderr as an array, in that respective order."""
     print command_text
-    p = subprocess.Popen(
+    subprocess.Popen(
         command_text, shell=True, bufsize=1024, stdout=subprocess.PIPE, 
         stderr=subprocess.PIPE,
     )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.