diff options
author | nfnty <git@nfnty.se> | 2016-02-08 16:32:46 +0100 |
---|---|---|
committer | nfnty <git@nfnty.se> | 2016-02-08 16:32:46 +0100 |
commit | 6edb035a4d176c4df852b7e7ad9be89a3de24a72 (patch) | |
tree | ba33a90ed10fe968e7e035f75e28e2a799f5eced | |
parent | 878f0f574ca96c6e19c86765159d6ce40084f741 (diff) | |
download | ranger-6edb035a4d176c4df852b7e7ad9be89a3de24a72.tar.gz |
VCS: Split Vcs root into VcsRoot
-rw-r--r-- | ranger/ext/vcs/vcs.py | 145 |
1 files changed, 84 insertions, 61 deletions
diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py index a0f4b5d7..5c456120 100644 --- a/ranger/ext/vcs/vcs.py +++ b/ranger/ext/vcs/vcs.py @@ -78,21 +78,14 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes self.root, self.repodir, self.repotype, self.links = self._find_root(self.path) self.is_root = True if self.obj.path == self.root else False - + self.in_repodir = False self.rootvcs = None - self.rootinit = False - self.head = None - self.branch = None - self.updatetime = None self.track = False - self.in_repodir = False - self.status_subpaths = None if self.root: if self.is_root: self.rootvcs = self - self.__class__ = getattr(getattr(ranger.ext.vcs, self.repotype), - self.REPOTYPES[self.repotype]['class']) + self.__class__ = globals()[self.REPOTYPES[self.repotype]['class'] + 'Root'] if not os.access(self.repodir, os.R_OK): self.obj.vcsremotestatus = 'unknown' @@ -106,7 +99,7 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes if self.rootvcs.root is None: return self.rootvcs.links |= self.links - self.__class__ = self.rootvcs.__class__ + self.__class__ = globals()[self.REPOTYPES[self.repotype]['class']] self.track = self.rootvcs.track if self.path == self.repodir or self.path.startswith(self.repodir + '/'): @@ -160,6 +153,62 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes return (None, None, None, None) + def check(self): + """Check health""" + if not self.in_repodir \ + and (not self.track or (not self.is_root and self._get_repotype(self.path)[0])): + self.__init__(self.obj) + return False + elif self.track and not os.path.exists(self.repodir): + self.rootvcs.update_tree(purge=True) # pylint: disable=no-member + return False + return True + + # Action interface + + def action_add(self, filelist): + """Adds files to the index""" + raise NotImplementedError + + def action_reset(self, filelist): + """Removes files from the index""" + raise NotImplementedError + + # Data interface + + def data_status_root(self): + """Returns status of self.root cheaply""" + raise NotImplementedError + + def data_status_subpaths(self): + """Returns a dict indexed by subpaths not in sync with their status as values. + Paths are given relative to self.root""" + raise NotImplementedError + + def data_status_remote(self): + """ + Returns remote status of repository + One of ('sync', 'ahead', 'behind', 'diverged', 'none') + """ + raise NotImplementedError + + def data_branch(self): + """Returns the current named branch, if this makes sense for the backend. None otherwise""" + raise NotImplementedError + + def data_info(self, rev=None): + """Returns info string about revision rev. None in special cases""" + raise NotImplementedError + + +class VcsRoot(Vcs): # pylint: disable=abstract-method + """Vcs root""" + rootinit = False + head = None + branch = None + updatetime = None + status_subpaths = None + def _status_root(self): """Returns root status""" if self.status_subpaths is None: @@ -264,17 +313,6 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes self.updatetime = time.time() return True - def check(self): - """Check health""" - if not self.in_repodir \ - and (not self.track or (not self.is_root and self._get_repotype(self.path)[0])): - self.__init__(self.obj) - return False - elif self.track and not os.path.exists(self.repodir): - self.rootvcs.update_tree(purge=True) - return False - return True - def check_outdated(self): """Check if root is outdated""" if self.updatetime is None: @@ -322,42 +360,6 @@ class Vcs(object): # pylint: disable=too-many-instance-attributes return status return 'sync' - # Action interface - - def action_add(self, filelist): - """Adds files to the index""" - raise NotImplementedError - - def action_reset(self, filelist): - """Removes files from the index""" - raise NotImplementedError - - # Data interface - - def data_status_root(self): - """Returns status of self.root cheaply""" - raise NotImplementedError - - def data_status_subpaths(self): - """Returns a dict indexed by subpaths not in sync with their status as values. - Paths are given relative to self.root""" - raise NotImplementedError - - def data_status_remote(self): - """ - Returns remote status of repository - One of ('sync', 'ahead', 'behind', 'diverged', 'none') - """ - raise NotImplementedError - - def data_branch(self): - """Returns the current named branch, if this makes sense for the backend. None otherwise""" - raise NotImplementedError - - def data_info(self, rev=None): - """Returns info string about revision rev. None in special cases""" - raise NotImplementedError - class VcsThread(threading.Thread): # pylint: disable=too-many-instance-attributes """VCS thread""" @@ -444,8 +446,29 @@ class VcsThread(threading.Thread): # pylint: disable=too-many-instance-attribut self.queue.put(dirobj) self.awoken.set() + # Backend imports -import ranger.ext.vcs.bzr # NOQA pylint: disable=wrong-import-position -import ranger.ext.vcs.git # NOQA pylint: disable=wrong-import-position -import ranger.ext.vcs.hg # NOQA pylint: disable=wrong-import-position -import ranger.ext.vcs.svn # NOQA pylint: disable=wrong-import-position +from .bzr import Bzr # NOQA pylint: disable=wrong-import-position +from .git import Git # NOQA pylint: disable=wrong-import-position +from .hg import Hg # NOQA pylint: disable=wrong-import-position +from .svn import SVN # NOQA pylint: disable=wrong-import-position + + +class BzrRoot(VcsRoot, Bzr): + ''' Bzr root ''' + pass + + +class GitRoot(VcsRoot, Git): + ''' Git root ''' + pass + + +class HgRoot(VcsRoot, Hg): + ''' Hg root ''' + pass + + +class SVNRoot(VcsRoot, SVN): + ''' SVN root ''' + pass |