def run_cmd(self): try: self.project.install() except Exception as e: logger.error('Failed to install dvc hooks', e) return 1 return 0
def _show(self, section, opt): try: self.config.show(self.configobj, section, opt) except DvcException as exc: logger.error("Failed to show '{}'".format(self.args.name), exc) return 1 return 0
def _spawn_posix(self, cmd): try: pid = os.fork() if pid > 0: return except OSError as exc: logger.error("Failed at first fork", exc) sys.exit(1) os.setsid() os.umask(0) try: pid = os.fork() if pid > 0: sys.exit(0) except OSError as exc: logger.error("Failed at second fork", exc) sys.exit(1) sys.stdin.close() sys.stdout.close() sys.stderr.close() Popen(cmd, close_fds=True, shell=False)
def run(self): for target in self.args.targets: try: self.project.add(target, recursive=self.args.recursive) except DvcException as ex: logger.error('Failed to add \'{}\''.format(target), ex) return 1 return 0
def run(self): for target in self.args.targets: try: outs_only = self._is_outs_only(target) self.project.remove(target, outs_only=outs_only) except DvcException as ex: logger.error('Failed to remove {}'.format(target), ex) return 1 return 0
def run_cmd(self): from dvc.lock import LockError try: with self.project.lock: return self.run() except LockError as ex: logger.error('Failed to lock before running a command', ex) return 1
def test_stderr(self, mock_stdout, mock_stderr): logger = Logger(force=True) error_message = 'error msg' logger.error(error_message) self.assertEqual('', mock_stdout.getvalue()) self.assertEqual( 'Error: {}\n\nHaving any troubles? ' 'Hit us up at dvc.org/support, we ' 'are always happy to help!\n'.format(error_message), mock_stderr.getvalue())
def _set(self, section, opt, value): try: self.config.set(self.configobj, section, opt, value) self.config.save(self.configobj) except DvcException as exc: logger.error("Failed to set '{}.{}' to '{}'".format(section, opt, value), exc) return 1 return 0
def _unset(self, section, opt=None, configobj=None): if configobj is None: configobj = self.configobj try: self.config.unset(configobj, section, opt) self.config.save(configobj) except DvcException as exc: logger.error("Failed to unset '{}'".format(self.args.name), exc) return 1 return 0
def add(self, paths): # NOTE: GitPython is not currently able to handle index version >= 3. # See https://github.com/iterative/dvc/issues/610 for more details. try: self.repo.index.add(paths) except AssertionError as exc: msg = 'Failed to add \'{}\' to git. You can add those files ' msg += 'manually using \'git add\'. ' msg += 'See \'https://github.com/iterative/dvc/issues/610\' ' msg += 'for more details.' logger.error(msg.format(str(paths)), exc)
def run_cmd(self): from dvc.project import Project, InitError try: self.project = Project.init('.', no_scm=self.args.no_scm, force=self.args.force) self.config = self.project.config except InitError as e: logger.error('Failed to initiate dvc', e) return 1 return 0
def run(self): try: default_out = os.path.basename( urlparse(self.args.url).path ) out = self.args.out or default_out self.project.imp(self.args.url, out) except DvcException as ex: logger.error('Failed to import {}'.format(self.args.url), ex) return 1 return 0
def test_empty_err_msg(self, mock_stdout, mock_stderr): from dvc.exceptions import DvcException logger = Logger(force=True) exc_msg = 'msg' logger.error("", exc=DvcException(exc_msg)) self.assertEqual('', mock_stdout.getvalue()) self.assertEqual( 'Error: {}\n\nHaving any troubles? ' 'Hit us up at dvc.org/support, we ' 'are always happy to help!\n'.format(exc_msg), mock_stderr.getvalue())
def main(argv=None): args = None cmd = None try: args = parse_args(argv) # Init loglevel early in case we'll run # into errors before setting it properly CmdBase._set_loglevel(args) cmd = args.func(args) ret = cmd.run_cmd() except KeyboardInterrupt as ex: logger.error("Interrupted by the user", ex) ret = 252 except NotDvcProjectError as ex: logger.error("", ex) ret = 253 except DvcParserError: ret = 254 except Exception as ex: logger.error('Unexpected error', ex) ret = 255 Analytics().send_cmd(cmd, args, ret) return ret
def load_dir_cache(self, md5): path = self.get(md5) assert self.is_dir_cache(path) try: with open(path, 'r') as fd: d = json.load(fd) except Exception as exc: msg = u'Failed to load dir cache \'{}\'' logger.error(msg.format(os.path.relpath(path)), exc) return [] if not isinstance(d, list): msg = u'Dir cache file format error \'{}\': skipping the file' logger.error(msg.format(os.path.relpath(path))) return [] for info in d: info['relpath'] = self.ospath(info['relpath']) return d