Beispiel #1
0
 def dist(self, dist, version=''):
     try:
         return load_json(self.call(
             version and 'meta' or 'dist',
             {'dist': dist, 'version': version}))
     except ResourceNotFound:
         raise NotFound("distribution '%s' not found" % dist)
Beispiel #2
0
    def get_meta(self, spec):
        """
        Return the content of the ``META.json`` file for *spec*.

        Return the object obtained parsing the JSON.
        """
        if not spec.is_local():
            # Get the metadata from the API
            try:
                data = self.api.dist(spec.name)
            except NotFound:
                # Distro not found: maybe it's an extension?
                ext = self.api.ext(spec.name)
                name, ver = self.get_best_version_from_ext(ext, spec)
                return self.api.meta(name, ver)
            else:
                ver = self.get_best_version(data, spec)
                return self.api.meta(spec.name, ver)

        elif spec.is_dir():
            # Get the metadata from a directory
            fn = os.path.join(spec.dirname, 'META.json')
            logger.debug("reading %s", fn)
            if not os.path.exists(fn):
                raise PgxnClientException(
                    _("file 'META.json' not found in '%s'") % dir)

            return load_json(open(fn))

        elif spec.is_file():
            # Get the metadata from a zip file
            return get_meta_from_zip(spec.filename)
Beispiel #3
0
    def get_index(self):
        if self._api_index is None:
            url = self.mirror.rstrip('/') + '/index.json'
            try:
                self._api_index = load_json(get_file(url))
            except ResourceNotFound:
                raise NetworkError("API index not found at '%s'" % url)

        return self._api_index
Beispiel #4
0
 def dist(self, dist, version=''):
     try:
         with self.call(version and 'meta' or 'dist', {
                 'dist': dist,
                 'version': version
         }) as f:
             return load_json(f)
     except ResourceNotFound:
         raise NotFound("distribution '%s' not found" % dist)
Beispiel #5
0
    def get_index(self):
        if self._api_index is None:
            url = self.mirror.rstrip('/') + '/index.json'
            try:
                with network.get_file(url) as f:
                    self._api_index = load_json(f)
            except ResourceNotFound:
                raise NetworkError("API index not found at '%s'" % url)

        return self._api_index
Beispiel #6
0
    def search(self, where, query):
        """Search into PGXN.

        :param where: where to search. The server currently supports "docs",
            "dists", "extensions"
        :param query: list of strings to search
        """
        # convert the query list into a string
        q = ' '.join([' ' in s and ('"%s"' % s) or s for s in query])

        with self.call('search', {'in': where}, query={'q': q}) as f:
            return load_json(f)
Beispiel #7
0
    def search(self, where, query):
        """Search into PGXN.

        :param where: where to search. The server currently supports "docs",
            "dists", "extensions"
        :param query: list of strings to search
        """
        # convert the query list into a string
        q = ' '.join([' ' in s and ('"%s"' % s) or s for s in query])

        with self.call('search', {'in': where}, query={'q': q}) as f:
            return load_json(f)
Beispiel #8
0
    def get_meta(self, spec):
        """
        Return the content of the ``META.json`` file for *spec*.

        Return the object obtained parsing the JSON.
        """
        if spec.is_name():
            # Get the metadata from the API
            try:
                data = self.api.dist(spec.name)
            except NotFound:
                # Distro not found: maybe it's an extension?
                ext = self.api.ext(spec.name)
                name, ver = self.get_best_version_from_ext(ext, spec)
                return self.api.meta(name, ver)
            else:
                ver = self.get_best_version(data, spec)
                return self.api.meta(spec.name, ver)

        elif spec.is_dir():
            # Get the metadata from a directory
            fn = os.path.join(spec.dirname, 'META.json')
            logger.debug("reading %s", fn)
            if not os.path.exists(fn):
                raise PgxnClientException(
                    _("file 'META.json' not found in '%s'") % spec.dirname
                )

            with open(fn) as f:
                return load_json(f)

        elif spec.is_file():
            arc = archive.from_spec(spec)
            return arc.get_meta()

        elif spec.is_url():
            with network.get_file(spec.url) as fin:
                with temp_dir() as dir:
                    fn = network.download(fin, dir)
                    arc = archive.from_file(fn)
                    return arc.get_meta()

        else:
            assert False
Beispiel #9
0
    def get_meta(self, spec):
        """
        Return the content of the ``META.json`` file for *spec*.

        Return the object obtained parsing the JSON.
        """
        if spec.is_name():
            # Get the metadata from the API
            try:
                data = self.api.dist(spec.name)
            except NotFound:
                # Distro not found: maybe it's an extension?
                ext = self.api.ext(spec.name)
                name, ver = self.get_best_version_from_ext(ext, spec)
                return self.api.meta(name, ver)
            else:
                ver = self.get_best_version(data, spec)
                return self.api.meta(spec.name, ver)

        elif spec.is_dir():
            # Get the metadata from a directory
            fn = os.path.join(spec.dirname, 'META.json')
            logger.debug("reading %s", fn)
            if not os.path.exists(fn):
                raise PgxnClientException(
                    _("file 'META.json' not found in '%s'") % spec.dirname)

            with open(fn) as f:
                return load_json(f)

        elif spec.is_file():
            arc = archive.from_spec(spec)
            return arc.get_meta()

        elif spec.is_url():
            with network.get_file(spec.url) as fin:
                with temp_dir() as dir:
                    fn = network.download(fin, dir)
                    arc = archive.from_file(fn)
                    return arc.get_meta()

        else:
            assert False
Beispiel #10
0
 def mirrors(self):
     return load_json(self.call('mirrors'))
Beispiel #11
0
 def user(self, username):
     with self.call('user', {'user': username}) as f:
         return load_json(f)
Beispiel #12
0
 def stats(self, arg):
     with self.call('stats', {'stats': arg}) as f:
         return load_json(f)
Beispiel #13
0
 def user(self, username):
     with self.call('user', {'user': username}) as f:
         return load_json(f)
Beispiel #14
0
 def mirrors(self):
     with self.call('mirrors') as f:
         return load_json(f)
Beispiel #15
0
 def stats(self, arg):
     return load_json(self.call('stats', {'stats': arg}))
Beispiel #16
0
 def ext(self, ext):
     try:
         with self.call('extension', {'extension': ext}) as f:
             return load_json(f)
     except ResourceNotFound:
         raise NotFound("extension '%s' not found" % ext)
Beispiel #17
0
 def meta(self, dist, version, as_json=True):
     with self.call('meta', {'dist': dist, 'version': version}) as f:
         if as_json:
             return load_json(f)
         else:
             return f.read().decode('utf-8')
Beispiel #18
0
 def user(self, username):
     return load_json(self.call('user', {'user': username}))
Beispiel #19
0
 def ext(self, ext):
     try:
         with self.call('extension', {'extension': ext}) as f:
             return load_json(f)
     except ResourceNotFound:
         raise NotFound("extension '%s' not found" % ext)
Beispiel #20
0
 def meta(self, dist, version, as_json=True):
     with self.call('meta', {'dist': dist, 'version': version}) as f:
         if as_json:
             return load_json(f)
         else:
             return f.read().decode('utf-8')
Beispiel #21
0
 def stats(self, arg):
     with self.call('stats', {'stats': arg}) as f:
         return load_json(f)
Beispiel #22
0
 def mirrors(self):
     with self.call('mirrors') as f:
         return load_json(f)