Ejemplo n.º 1
0
    def call(self, meth, args=None, query=None):
        url = self.get_url(meth, args, query)
        try:
            return network.get_file(url)
        except ResourceNotFound:
            # check if it is one of the broken URLs as reported in
            # https://groups.google.com/group/pgxn-users/browse_thread/thread/e41fbc202680c92c
            version = args and args.get('version')
            if not (version and version.trail):
                raise

            args = args.copy()
            args['version'] = str(version).replace('-', '', 1)
            url = self.get_url(meth, args, query)
            return network.get_file(url)
Ejemplo n.º 2
0
    def call(self, meth, args=None, query=None):
        url = self.get_url(meth, args, query)
        try:
            return network.get_file(url)
        except ResourceNotFound:
            # check if it is one of the broken URLs as reported in
            # https://groups.google.com/group/pgxn-users/browse_thread/thread/e41fbc202680c92c
            version = args and args.get('version')
            if not (version and version.trail):
                raise

            args = args.copy()
            args['version'] = str(version).replace('-', '', 1)
            url = self.get_url(meth, args, query)
            return network.get_file(url)
Ejemplo n.º 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
Ejemplo n.º 4
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
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
    def _run_url(self, spec):
        with network.get_file(spec.url) as fin:
            fn = network.download(fin, self.opts.target)

        return fn
Ejemplo n.º 8
0
 def call(self, meth, args=None, query=None):
     url = self.get_url(meth, args, query)
     return network.get_file(url)
Ejemplo n.º 9
0
    def _run_url(self, spec):
        with network.get_file(spec.url) as fin:
            fn = network.download(fin, self.opts.target)

        return fn
Ejemplo n.º 10
0
 def call(self, meth, args=None, query=None):
     url = self.get_url(meth, args, query)
     return get_file(url)