From 918bb53b75e39070554fff8e08af393bda5201b8 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 15 Jul 2018 07:44:25 +0300 Subject: [PATCH] dvc: implement `dvc destroy` Fixes #621 Signed-off-by: Ruslan Kuprieiev --- dvc/cli.py | 10 ++++++++++ dvc/command/destroy.py | 11 +++++++++++ dvc/project.py | 7 +++++++ 3 files changed, 28 insertions(+) create mode 100644 dvc/command/destroy.py diff --git a/dvc/cli.py b/dvc/cli.py index 9bbef90f1..3be482007 100644 --- a/dvc/cli.py +++ b/dvc/cli.py @@ -7,6 +7,7 @@ from multiprocessing import cpu_count from dvc.logger import Logger from dvc.command.init import CmdInit +from dvc.command.destroy import CmdDestroy from dvc.command.remove import CmdRemove from dvc.command.move import CmdMove from dvc.command.run import CmdRun @@ -87,6 +88,15 @@ def parse_args(argv=None): help="Initiate dvc in directory that is not tracked by any scm tool(e.g. git)") init_parser.set_defaults(func=CmdInit) + + # Destroy + destroy_parser = subparsers.add_parser( + 'destroy', + parents=[parent_parser], + help='Destroy dvc') + destroy_parser.set_defaults(func=CmdDestroy) + + # Add add_parser = subparsers.add_parser( 'add', diff --git a/dvc/command/destroy.py b/dvc/command/destroy.py new file mode 100644 index 000000000..8d2a719db --- /dev/null +++ b/dvc/command/destroy.py @@ -0,0 +1,11 @@ +from dvc.command.common.base import CmdBase + + +class CmdDestroy(CmdBase): + def run(self): + try: + self.project.destroy() + except Exception as exc: + self.project.logger.error('Failed to destroy DVC', exc) + return 1 + return 0 diff --git a/dvc/project.py b/dvc/project.py index 122405620..105d11ee7 100644 --- a/dvc/project.py +++ b/dvc/project.py @@ -2,6 +2,7 @@ import os import csv import stat import json +import shutil import networkx as nx from jsonpath_rw import parse @@ -96,6 +97,12 @@ class Project(object): return proj + def destroy(self): + for stage in self.stages(): + stage.remove() + + shutil.rmtree(self.dvc_dir) + def _ignore(self): l = [self.state.state_file, self.state._lock_file.lock_file,