Exemple #1
0
    def dumpd(self):
        from dvc.remote.local import RemoteLOCAL

        return {
            key: value
            for key, value in {
                Stage.PARAM_MD5: self.md5,
                Stage.PARAM_CMD: self.cmd,
                Stage.PARAM_WDIR: RemoteLOCAL.unixpath(
                    os.path.relpath(self.wdir, os.path.dirname(self.path))
                ),
                Stage.PARAM_LOCKED: self.locked,
                Stage.PARAM_DEPS: [d.dumpd() for d in self.deps],
                Stage.PARAM_OUTS: [o.dumpd() for o in self.outs],
            }.items()
            if value
        }
Exemple #2
0
class DependencyLOCAL(DependencyBase):
    REGEX = r'^(?P<path>(/+|.:\\+)?[^:]*)$'

    DoesNotExistError = DependencyDoesNotExistError
    IsNotFileOrDirError = DependencyIsNotFileOrDirError

    def __init__(self, stage, path, info=None, remote=None):
        self.stage = stage
        self.project = stage.project
        self.info = info
        if remote is not None:
            self.remote = remote
        else:
            self.remote = RemoteLOCAL(stage.project, {})

        if remote:
            path = os.path.join(remote.prefix, urlparse(path).path.lstrip('/'))

        if not os.path.isabs(path):
            path = self.remote.ospath(path)
            path = os.path.join(stage.cwd, path)
        self.path = os.path.abspath(os.path.normpath(path))

        self.path_info = {'scheme': 'local',
                          'path': self.path}

    @property
    def sep(self):
        return os.sep

    @property
    def rel_path(self):
        return os.path.relpath(self.path)

    def changed(self):
        if not self.exists:
            return True

        info = self.remote.save_info(self.path_info)

        return self.info != info

    def save(self):
        if not self.exists:
            raise self.DoesNotExistError(self.rel_path)

        if not os.path.isfile(self.path) and not os.path.isdir(self.path):
            raise self.IsNotFileOrDirError(self.rel_path)

        if (os.path.isfile(self.path) and os.path.getsize(self.path) == 0) or \
           (os.path.isdir(self.path) and len(os.listdir(self.path)) == 0):
            Logger.warn("File/directory '{}' is empty.".format(self.rel_path))

        self.info = self.remote.save_info(self.path_info)

    def dumpd(self):
        if self.path.startswith(self.stage.project.root_dir):
            path = self.remote.unixpath(os.path.relpath(self.path,
                                                        self.stage.cwd))
        else:
            path = self.path

        info = self.info.copy()
        info[self.PARAM_PATH] = path
        return info
Exemple #3
0
class DependencyLOCAL(DependencyBase):
    REGEX = r'^(?P<path>.*)$'

    DoesNotExistError = DependencyDoesNotExistError
    IsNotFileOrDirError = DependencyIsNotFileOrDirError

    def __init__(self, stage, path, info=None, remote=None):
        super(DependencyLOCAL, self).__init__(stage, path, info)
        if remote is not None:
            self.remote = remote
        else:
            self.remote = RemoteLOCAL(stage.project, {})

        if remote:
            p = os.path.join(remote.prefix,
                             urlparse(self.url).path.lstrip('/'))
        else:
            p = path

        if not os.path.isabs(p):
            p = self.remote.to_ospath(p)
            p = os.path.join(stage.cwd, p)
        p = os.path.abspath(os.path.normpath(p))

        self.path_info = {'scheme': 'local',
                          'path': p}

    def __str__(self):
        return self.rel_path

    @property
    def is_local(self):
        return (urlparse(self.url).scheme != 'remote'
                and not os.path.isabs(self.url))

    @property
    def sep(self):
        return os.sep

    @property
    def rel_path(self):
        return os.path.relpath(self.path)

    def changed(self):
        if not self.exists:
            return True

        info = self.remote.save_info(self.path_info)

        return self.info != info

    def save(self):
        if not self.exists:
            raise self.DoesNotExistError(self.rel_path)

        if not os.path.isfile(self.path) \
           and not os.path.isdir(self.path):  # pragma: no cover
            raise self.IsNotFileOrDirError(self.rel_path)

        if (os.path.isfile(self.path) and os.path.getsize(self.path) == 0) or \
           (os.path.isdir(self.path) and len(os.listdir(self.path)) == 0):
            msg = "file/directory '{}' is empty.".format(self.rel_path)
            logger.warning(msg)

        self.info = self.remote.save_info(self.path_info)

    def dumpd(self):
        if self.is_local:
            path = self.remote.unixpath(os.path.relpath(self.path,
                                                        self.stage.cwd))
        else:
            path = self.url

        info = self.info.copy()
        info[self.PARAM_PATH] = path
        return info