diff --git a/dvc/command/base.py b/dvc/command/base.py index c39abb7fa..0a1f88e66 100644 --- a/dvc/command/base.py +++ b/dvc/command/base.py @@ -65,3 +65,11 @@ class CmdBase(object): # Abstract methods that have to be implemented by any inheritance class def run(self): pass + + +class CmdBaseNoRepo(CmdBase): + def __init__(self, args): + self.args = args + + def run_cmd(self): + return self.run() diff --git a/dvc/command/config.py b/dvc/command/config.py index 7cd594803..f62ac5d7d 100644 --- a/dvc/command/config.py +++ b/dvc/command/config.py @@ -4,7 +4,7 @@ import os import argparse import logging -from dvc.command.base import CmdBase, append_doc_link +from dvc.command.base import CmdBaseNoRepo, append_doc_link from dvc.config import Config from dvc.exceptions import DvcException @@ -12,11 +12,11 @@ from dvc.exceptions import DvcException logger = logging.getLogger(__name__) -class CmdConfig(CmdBase): +class CmdConfig(CmdBaseNoRepo): def __init__(self, args): from dvc.repo import Repo, NotDvcRepoError - self.args = args + super(CmdConfig, self).__init__(args) try: dvc_dir = os.path.join(Repo.find_root(), Repo.DVC_DIR) @@ -39,9 +39,6 @@ class CmdConfig(CmdBase): raise saved_exc self.configobj = self.config._repo_config - def run_cmd(self): - return self.run() - def _unset(self, section, opt=None, configobj=None): if configobj is None: configobj = self.configobj diff --git a/dvc/command/daemon.py b/dvc/command/daemon.py index 07b931c72..01fa07532 100644 --- a/dvc/command/daemon.py +++ b/dvc/command/daemon.py @@ -1,15 +1,10 @@ from __future__ import unicode_literals -from dvc.command.base import CmdBase, fix_subparsers +from dvc.command.base import CmdBaseNoRepo, fix_subparsers -class CmdDaemonBase(CmdBase): - def __init__(self, args): - self.args = args - self.config = None - - def run_cmd(self): - return self.run() +class CmdDaemonBase(CmdBaseNoRepo): + pass class CmdDaemonUpdater(CmdDaemonBase): diff --git a/dvc/command/init.py b/dvc/command/init.py index c435a9757..0e9bdf83f 100644 --- a/dvc/command/init.py +++ b/dvc/command/init.py @@ -3,17 +3,14 @@ from __future__ import unicode_literals import argparse import logging -from dvc.command.base import append_doc_link +from dvc.command.base import CmdBaseNoRepo, append_doc_link logger = logging.getLogger(__name__) -class CmdInit(object): - def __init__(self, args): - self.args = args - - def run_cmd(self): +class CmdInit(CmdBaseNoRepo): + def run(self): from dvc.repo import Repo from dvc.exceptions import InitError diff --git a/dvc/command/root.py b/dvc/command/root.py index f51e19da6..b52364cbb 100644 --- a/dvc/command/root.py +++ b/dvc/command/root.py @@ -4,18 +4,16 @@ import argparse import os import logging -from dvc.command.base import CmdBase, append_doc_link +from dvc.repo import Repo +from dvc.command.base import CmdBaseNoRepo, append_doc_link logger = logging.getLogger(__name__) -class CmdRoot(CmdBase): - def run_cmd(self): - return self.run() - +class CmdRoot(CmdBaseNoRepo): def run(self): - logger.info(os.path.relpath(self.repo.root_dir)) + logger.info(os.path.relpath(Repo.find_root())) return 0