mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-13 07:18:25 +01:00
Refactoring: extract CommandFile class
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ import os
|
||||
from dvc.command.common.base import CmdBase
|
||||
from dvc.logger import Logger
|
||||
from dvc.state_file import StateFile
|
||||
from dvc.command.run import CommandFile
|
||||
from dvc.command.common.command_file import CommandFile
|
||||
|
||||
|
||||
class CmdAdd(CmdBase):
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import yaml
|
||||
|
||||
from dvc.state_file import StateFileBase
|
||||
|
||||
|
||||
class CommandFile(StateFileBase):
|
||||
MAGIC = 'DVC-Command-State'
|
||||
VERSION = '0.1'
|
||||
|
||||
PARAM_CMD = 'cmd'
|
||||
PARAM_OUT = 'out'
|
||||
PARAM_REG = 'reg'
|
||||
PARAM_DEPS = 'deps'
|
||||
PARAM_LOCK = 'locked'
|
||||
|
||||
def __init__(self, cmd, out, reg, deps, locked, fname):
|
||||
self.cmd = cmd
|
||||
self.out = out
|
||||
self.reg = reg
|
||||
self.deps = deps
|
||||
self.locked = locked
|
||||
self.fname = fname
|
||||
|
||||
@property
|
||||
def dict(self):
|
||||
data = {
|
||||
self.PARAM_CMD: self.cmd,
|
||||
self.PARAM_OUT: self.out,
|
||||
self.PARAM_REG: self.reg,
|
||||
self.PARAM_DEPS: self.deps,
|
||||
self.PARAM_LOCK: self.locked
|
||||
}
|
||||
|
||||
return data
|
||||
|
||||
def dumps(self):
|
||||
return yaml.dump(self.dict)
|
||||
|
||||
def dump(self, fname):
|
||||
with open(fname, 'w+') as fd:
|
||||
fd.write(self.dumps())
|
||||
|
||||
@staticmethod
|
||||
def loadd(data, fname=None):
|
||||
return CommandFile(data.get(CommandFile.PARAM_CMD, None),
|
||||
data.get(CommandFile.PARAM_OUT, None),
|
||||
data.get(CommandFile.PARAM_REG, None),
|
||||
data.get(CommandFile.PARAM_DEPS, None),
|
||||
data.get(CommandFile.PARAM_LOCK, None),
|
||||
fname)
|
||||
|
||||
@staticmethod
|
||||
def load(fname):
|
||||
return CommandFile._load(fname, CommandFile, fname)
|
||||
+1
-54
@@ -1,11 +1,9 @@
|
||||
import yaml
|
||||
|
||||
from dvc.command.common.base import CmdBase
|
||||
from dvc.command.common.command_file import CommandFile
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.logger import Logger
|
||||
from dvc.state_file import StateFile
|
||||
from dvc.executor import Executor
|
||||
from dvc.state_file import StateFileBase
|
||||
|
||||
|
||||
class RunError(DvcException):
|
||||
@@ -13,57 +11,6 @@ class RunError(DvcException):
|
||||
DvcException.__init__(self, 'Run error: {}'.format(msg))
|
||||
|
||||
|
||||
class CommandFile(StateFileBase):
|
||||
MAGIC = 'DVC-Command-State'
|
||||
VERSION = '0.1'
|
||||
|
||||
PARAM_CMD = 'cmd'
|
||||
PARAM_OUT = 'out'
|
||||
PARAM_REG = 'reg'
|
||||
PARAM_DEPS = 'deps'
|
||||
PARAM_LOCK = 'locked'
|
||||
|
||||
def __init__(self, cmd, out, reg, deps, locked, fname):
|
||||
self.cmd = cmd
|
||||
self.out = out
|
||||
self.reg = reg
|
||||
self.deps = deps
|
||||
self.locked = locked
|
||||
self.fname = fname
|
||||
|
||||
@property
|
||||
def dict(self):
|
||||
data = {
|
||||
self.PARAM_CMD: self.cmd,
|
||||
self.PARAM_OUT: self.out,
|
||||
self.PARAM_REG: self.reg,
|
||||
self.PARAM_DEPS: self.deps,
|
||||
self.PARAM_LOCK: self.locked
|
||||
}
|
||||
|
||||
return data
|
||||
|
||||
def dumps(self):
|
||||
return yaml.dump(self.dict)
|
||||
|
||||
def dump(self, fname):
|
||||
with open(fname, 'w+') as fd:
|
||||
fd.write(self.dumps())
|
||||
|
||||
@staticmethod
|
||||
def loadd(data, fname=None):
|
||||
return CommandFile(data.get(CommandFile.PARAM_CMD, None),
|
||||
data.get(CommandFile.PARAM_OUT, None),
|
||||
data.get(CommandFile.PARAM_REG, None),
|
||||
data.get(CommandFile.PARAM_DEPS, None),
|
||||
data.get(CommandFile.PARAM_LOCK, None),
|
||||
fname)
|
||||
|
||||
@staticmethod
|
||||
def load(fname):
|
||||
return CommandFile._load(fname, CommandFile, fname)
|
||||
|
||||
|
||||
class CmdRun(CmdBase):
|
||||
def __init__(self, settings):
|
||||
super(CmdRun, self).__init__(settings)
|
||||
|
||||
Reference in New Issue
Block a user