Refactoring: extract method stage_file_basename()

This commit is contained in:
Dmitry
2017-12-24 22:40:08 -08:00
parent 4a1363de76
commit 1987693f34
+12 -6
View File
@@ -7,7 +7,7 @@ from dvc.stage import Stage
class CmdRun(CmdBase):
def run(self):
fname = self.get_stage_file(self.args.file, self.args.outs, self.args.outs_no_cache)
fname = self.stage_file_name(self.args.file, self.args.outs, self.args.outs_no_cache)
self.project.run(cmd=' '.join(self.args.command),
outs=self.args.outs,
@@ -20,16 +20,22 @@ class CmdRun(CmdBase):
return 0
@staticmethod
def get_stage_file(args_file, args_out, args_outs_no_cache):
def stage_file_name(args_file, args_outs, args_outs_no_cache):
if args_file:
return args_file
if args_out or args_outs_no_cache:
result = args_out[0] if args_out else args_outs_no_cache[0]
result = os.path.basename(result)
result += Stage.STAGE_FILE_SUFFIX
if args_outs:
result = CmdRun._stage_file_basename(args_outs)
elif args_outs_no_cache:
result = CmdRun._stage_file_basename(args_outs_no_cache)
else:
result = Stage.STAGE_FILE
Logger.info(u'Using \'{}\' as a stage file'.format(result))
return result
@staticmethod
def _stage_file_basename(fname):
result = os.path.basename(fname)
result += Stage.STAGE_FILE_SUFFIX
return result