Esempio n. 1
0
    def get_sources(self, pkg):
        """
        Returns the sources of a DataPackage. Sources are the raw, unmodified
        files (if they exist) that contains the package's data.
        """
        pkg_id = self._get_id(pkg)
        resp = self._get(self._uri('/{id}/sources', id=pkg_id))
        for r in resp:
            r['content'].update(dict(pkg_id=pkg_id))

        return [File.from_dict(r, api=self.session) for r in resp]
Esempio n. 2
0
    def create(self, file, destination=None):
        """
        Creates a file under the given destination or its current parent
        """
        container = file.parent if destination is None else destination

        body = file.as_dict()
        body["container"] = container

        response = self._post('', json=body)

        return File.from_dict(response, api=self.session)
Esempio n. 3
0
    def get_view(self, pkg):
        """
        Returns the object(s) used to view the package. This is typically a set of
        file objects, that may be the DataPackage's sources or files, but could also be
        a unique object specific for the viewer.
        """
        pkg_id = self._get_id(pkg)
        resp = self._get(self._uri('/{id}/view', id=pkg_id))
        for r in resp:
            r['content'].update(dict(pkg_id=pkg_id))

        return [File.from_dict(r, api=self.session) for r in resp]
Esempio n. 4
0
    def get_files(self, pkg):
        """
        Returns the files of a DataPackage. Files are the possibly modified
        source files (e.g. converted to a different format), but they could also
        be the source files themselves.
        """
        pkg_id = self._get_id(pkg)
        resp = self._get(self._uri('/{id}/files', id=pkg_id))
        for r in resp:
            r['content'].update(dict(pkg_id=pkg_id))

        return [File.from_dict(r, api=self.session) for r in resp]
Esempio n. 5
0
    def set_view(self, pkg, *files, **kwargs):
        """
        Set the object(s) used to view the package, if not the file(s) or source(s).
        """
        pkg_id = self._get_id(pkg)
        data = [x.as_dict() for x in files]
        path = self._uri('/{id}/view', id=pkg_id)
        resp = self._put(path, json=data, params=kwargs)

        return [
            File.from_dict(r, api=self.session) for r in resp
            if not isinstance(r, basestring)
        ]
Esempio n. 6
0
    def set_files(self, pkg, *files, **kwargs):
        """
        Sets the files of a DataPackage. Files are typically modified
        source files (e.g. converted to a different format).
        """
        pkg_id = self._get_id(pkg)
        data = [x.as_dict() for x in files]
        path = self._uri('/{id}/files', id=pkg_id)
        resp = self._put(path, json=data, params=kwargs)

        return [
            File.from_dict(r, api=self.session) for r in resp
            if not isinstance(r, basestring)
        ]
Esempio n. 7
0
    def set_sources(self, pkg, *files, **kwargs):
        """
        Sets the sources of a DataPackage. Sources are the raw, unmodified
        files (if they exist) that contains the package's data.
        """
        pkg_id = self._get_id(pkg)
        data = [x.as_dict() for x in files]
        path = self._uri('/{id}/sources', id=pkg_id)
        # Note: PUT returns list of IDs
        resp = self._put(path, json=data, params=kwargs)

        return [
            File.from_dict(r, api=self.session) for r in resp
            if not isinstance(r, basestring)
        ]