summary refs log tree commit diff stats
diff options
context:
space:
mode:
authornfnty <git@nfnty.se>2016-02-08 03:15:02 +0100
committernfnty <git@nfnty.se>2016-02-08 04:43:05 +0100
commitf68763ad11774290279763b30fed37bcf5e0da1a (patch)
tree2005922049074efa3397a7a5addd78c96851e442
parentcd703e2b5f75af497edbc630539c6cce93070eff (diff)
downloadranger-f68763ad11774290279763b30fed37bcf5e0da1a.tar.gz
VCS: Rename _vcs to _run
-rw-r--r--ranger/ext/vcs/bzr.py26
-rw-r--r--ranger/ext/vcs/git.py24
-rw-r--r--ranger/ext/vcs/hg.py22
-rw-r--r--ranger/ext/vcs/vcs.py8
4 files changed, 36 insertions, 44 deletions
diff --git a/ranger/ext/vcs/bzr.py b/ranger/ext/vcs/bzr.py
index ab4b8b06..5decc8b1 100644
--- a/ranger/ext/vcs/bzr.py
+++ b/ranger/ext/vcs/bzr.py
@@ -22,14 +22,10 @@ class Bzr(Vcs):
 
     # Generic
 
-    def _bzr(self, args, path=None, catchout=True, retbytes=False):
-        """Run a bzr command"""
-        return self._vcs(['bzr'] + args, path or self.path, catchout=catchout, retbytes=retbytes)
-
     def _remote_url(self):
         """Remote url"""
         try:
-            return self._bzr(['config', 'parent_location']).rstrip('\n') or None
+            return self._run(['config', 'parent_location']).rstrip('\n') or None
         except VcsError:
             return None
 
@@ -42,7 +38,7 @@ class Bzr(Vcs):
             args += ['--'] + filelist
 
         try:
-            output = self._bzr(args)
+            output = self._run(args)
         except VcsError:
             return None
         entries = re.findall(r'-+\n(.+?)\n(?:-|\Z)', output, re.MULTILINE | re.DOTALL)
@@ -64,7 +60,7 @@ class Bzr(Vcs):
             log.append(new)
         return log
 
-    def _bzr_status_translate(self, code):
+    def _status_translate(self, code):
         """Translate status code"""
         for code_x, code_y, status in self._status_translations:
             if code[0] in code_x and code[1] in code_y:
@@ -77,13 +73,13 @@ class Bzr(Vcs):
         args = ['add']
         if filelist:
             args += ['--'] + filelist
-        self._bzr(args, catchout=False)
+        self._run(args, catchout=False)
 
     def action_reset(self, filelist=None):
         args = ['remove', '--keep', '--new']
         if filelist:
             args += ['--'] + filelist
-        self._bzr(args, catchout=False)
+        self._run(args, catchout=False)
 
     # Data Interface
 
@@ -91,11 +87,11 @@ class Bzr(Vcs):
         statuses = set()
 
         # Paths with status
-        output = self._bzr(['status', '--short', '--no-classify']).rstrip('\n')
+        output = self._run(['status', '--short', '--no-classify']).rstrip('\n')
         if not output:
             return 'sync'
         for line in output.split('\n'):
-            statuses.add(self._bzr_status_translate(line[:2]))
+            statuses.add(self._status_translate(line[:2]))
 
         for status in self.DIRSTATUSES:
             if status in statuses:
@@ -106,15 +102,15 @@ class Bzr(Vcs):
         statuses = {}
 
         # Ignored
-        output = self._bzr(['ls', '--null', '--ignored']).rstrip('\x00')
+        output = self._run(['ls', '--null', '--ignored']).rstrip('\x00')
         if output:
             for path in output.split('\x00'):
                 statuses[path] = 'ignored'
 
         # Paths with status
-        output = self._bzr(['status', '--short', '--no-classify']).rstrip('\n')
+        output = self._run(['status', '--short', '--no-classify']).rstrip('\n')
         for line in output.split('\n'):
-            statuses[os.path.normpath(line[4:])] = self._bzr_status_translate(line[:2])
+            statuses[os.path.normpath(line[4:])] = self._status_translate(line[:2])
 
         return statuses
 
@@ -125,7 +121,7 @@ class Bzr(Vcs):
 
     def data_branch(self):
         try:
-            return self._bzr(['nick']).rstrip('\n') or None
+            return self._run(['nick']).rstrip('\n') or None
         except VcsError:
             return None
 
diff --git a/ranger/ext/vcs/git.py b/ranger/ext/vcs/git.py
index ca49998e..8f4d9ff8 100644
--- a/ranger/ext/vcs/git.py
+++ b/ranger/ext/vcs/git.py
@@ -28,19 +28,15 @@ class Git(Vcs):
 
     # Generic
 
-    def _git(self, args, path=None, catchout=True, retbytes=False):
-        """Run a git command"""
-        return self._vcs(['git'] + args, path or self.path, catchout=catchout, retbytes=retbytes)
-
     def _head_ref(self):
         """Returns HEAD reference"""
-        return self._git(['symbolic-ref', self.HEAD]).rstrip('\n') or None
+        return self._run(['symbolic-ref', self.HEAD]).rstrip('\n') or None
 
     def _remote_ref(self, ref):
         """Returns remote reference associated to given ref"""
         if ref is None:
             return None
-        return self._git(['for-each-ref', '--format=%(upstream)', ref]).rstrip('\n') or None
+        return self._run(['for-each-ref', '--format=%(upstream)', ref]).rstrip('\n') or None
 
     def _log(self, refspec=None, maxres=None, filelist=None):
         """Returns an array of dicts containing revision info for refspec"""
@@ -62,7 +58,7 @@ class Git(Vcs):
             args += ['--'] + filelist
 
         try:
-            output = self._git(args).rstrip('\n')
+            output = self._run(args).rstrip('\n')
         except VcsError:
             return None
         if not output:
@@ -89,13 +85,13 @@ class Git(Vcs):
         args = ['add', '--all']
         if filelist:
             args += ['--'] + filelist
-        self._git(args, catchout=False)
+        self._run(args, catchout=False)
 
     def action_reset(self, filelist=None):
         args = ['reset']
         if filelist:
             args += ['--'] + filelist
-        self._git(args, catchout=False)
+        self._run(args, catchout=False)
 
     # Data Interface
 
@@ -104,7 +100,7 @@ class Git(Vcs):
 
         # Paths with status
         skip = False
-        output = self._git(['status', '--porcelain', '-z']).rstrip('\x00')
+        output = self._run(['status', '--porcelain', '-z']).rstrip('\x00')
         if not output:
             return 'sync'
         for line in output.split('\x00'):
@@ -124,7 +120,7 @@ class Git(Vcs):
         statuses = {}
 
         # Ignored directories
-        output = self._git([
+        output = self._run([
             'ls-files', '-z', '--others', '--directory', '--ignored', '--exclude-standard'
         ]).rstrip('\x00')
         if output:
@@ -133,7 +129,7 @@ class Git(Vcs):
                     statuses[os.path.normpath(path)] = 'ignored'
 
         # Empty directories
-        output = self._git(
+        output = self._run(
             ['ls-files', '-z', '--others', '--directory', '--exclude-standard']).rstrip('\x00')
         if output:
             for path in output.split('\x00'):
@@ -141,7 +137,7 @@ class Git(Vcs):
                     statuses[os.path.normpath(path)] = 'none'
 
         # Paths with status
-        output = self._git(['status', '--porcelain', '-z', '--ignored']).rstrip('\x00')
+        output = self._run(['status', '--porcelain', '-z', '--ignored']).rstrip('\x00')
         if output:
             skip = False
             for line in output.split('\x00'):
@@ -163,7 +159,7 @@ class Git(Vcs):
         if not head or not remote:
             return 'none'
 
-        output = self._git(['rev-list', '--left-right', '{0:s}...{1:s}'.format(remote, head)])
+        output = self._run(['rev-list', '--left-right', '{0:s}...{1:s}'.format(remote, head)])
         ahead = re.search(r'^>', output, flags=re.MULTILINE)
         behind = re.search(r'^<', output, flags=re.MULTILINE)
         if ahead:
diff --git a/ranger/ext/vcs/hg.py b/ranger/ext/vcs/hg.py
index f1e9dbdb..2d047de3 100644
--- a/ranger/ext/vcs/hg.py
+++ b/ranger/ext/vcs/hg.py
@@ -25,10 +25,6 @@ class Hg(Vcs):
 
     # Generic
 
-    def _hg(self, args, path=None, catchout=True, retbytes=False):
-        """Run a hg command"""
-        return self._vcs(['hg'] + args, path or self.path, catchout=catchout, retbytes=retbytes)
-
     def _log(self, refspec=None, maxres=None, filelist=None):
 
         args = [
@@ -49,7 +45,7 @@ class Hg(Vcs):
             args += ['--'] + filelist
 
         try:
-            output = self._hg(args).rstrip('\n')
+            output = self._run(args).rstrip('\n')
         except VcsError:
             return None
         if not output:
@@ -66,7 +62,7 @@ class Hg(Vcs):
     def _remote_url(self):
         """Remote url"""
         try:
-            return self._hg(['showconfig', 'paths.default']).rstrip('\n') or None
+            return self._run(['showconfig', 'paths.default']).rstrip('\n') or None
         except VcsError:
             return None
 
@@ -83,7 +79,7 @@ class Hg(Vcs):
         args = ['add']
         if filelist:
             args += ['--'] + filelist
-        self._hg(args, catchout=False)
+        self._run(args, catchout=False)
 
     def action_reset(self, filelist=None):
         args = ['forget', '--']
@@ -91,7 +87,7 @@ class Hg(Vcs):
             args += filelist
         else:
             args += self.rootvcs.status_subpaths.keys()
-        self._hg(args, catchout=False)
+        self._run(args, catchout=False)
 
     # Data interface
 
@@ -99,7 +95,7 @@ class Hg(Vcs):
         statuses = set()
 
         # Paths with status
-        output = self._hg(['status', '--all', '--print0']).rstrip('\x00')
+        output = self._run(['status', '--all', '--print0']).rstrip('\x00')
         if not output:
             return 'sync'
         for line in output.split('\x00'):
@@ -117,7 +113,7 @@ class Hg(Vcs):
         statuses = {}
 
         # Paths with status
-        output = self._hg(['status', '--all', '--print0']).rstrip('\x00')
+        output = self._run(['status', '--all', '--print0']).rstrip('\x00')
         if output:
             for line in output.split('\x00'):
                 code, path = line[0], line[2:]
@@ -133,12 +129,12 @@ class Hg(Vcs):
 
         ahead = behind = True
         try:
-            self._hg(['outgoing'], catchout=False)
+            self._run(['outgoing'], catchout=False)
         except VcsError:
             ahead = False
 
         try:
-            self._hg(['incoming'], catchout=False)
+            self._run(['incoming'], catchout=False)
         except VcsError:
             behind = False
 
@@ -148,7 +144,7 @@ class Hg(Vcs):
             return 'behind' if behind else 'sync'
 
     def data_branch(self):
-        return self._hg(['branch'], catchout=True).rstrip('\n') or None
+        return self._run(['branch'], catchout=True).rstrip('\n') or None
 
     def data_info(self, rev=None):
         if rev is None:
diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py
index a99f9aa9..4cf38a97 100644
--- a/ranger/ext/vcs/vcs.py
+++ b/ranger/ext/vcs/vcs.py
@@ -115,8 +115,12 @@ class Vcs(object):  # pylint: disable=too-many-instance-attributes
 
     # Generic
 
-    def _vcs(self, cmd, path, catchout=True, retbytes=False):  # pylint: disable=no-self-use
-        """Run a VCS command"""
+    def _run(self, args, path=None, catchout=True, retbytes=False):
+        """Run a command"""
+        cmd = [self.repotype] + args
+        if path is None:
+            path = self.path
+
         with open(os.devnull, 'w') as devnull:
             try:
                 if catchout: