Exemplo n.º 1
0
def load_feed(source, local=False, selections_ok=False):
    """Load a feed from a local file.
	@param source: the name of the file to read
	@type source: str
	@param local: this is a local feed
	@type local: bool
	@param selections_ok: if it turns out to be a local selections document, return that instead
	@type selections_ok: bool
	@raise InvalidInterface: if the source's syntax is incorrect
	@return: the new feed
	@since: 0.48
	@see: L{iface_cache.iface_cache}, which uses this to load the feeds"""
    try:
        root = qdom.parse(open(source))
    except IOError as ex:
        if ex.errno == errno.ENOENT and local:
            raise MissingLocalFeed(
                _("Feed not found. Perhaps this is a local feed that no longer exists? You can remove it from the list of feeds in that case."
                  ))
        raise InvalidInterface(_("Can't read file"), ex)
    except Exception as ex:
        raise InvalidInterface(_("Invalid XML"), ex)

    if local:
        if selections_ok and root.uri == XMLNS_IFACE and root.name == 'selections':
            from zeroinstall.injector import selections
            return selections.Selections(root)
        local_path = source
    else:
        local_path = None
    feed = ZeroInstallFeed(root, local_path)
    feed.last_modified = int(os.stat(source).st_mtime)
    return feed
Exemplo n.º 2
0
def load_feed(source, local=False):
    """Load a feed from a local file.
	@param source: the name of the file to read
	@type source: str
	@param local: this is a local feed
	@type local: bool
	@return: the new feed
	@rtype: L{ZeroInstallFeed}
	@raise InvalidInterface: if the source's syntax is incorrect
	@since: 0.48
	@see: L{iface_cache.iface_cache}, which uses this to load the feeds"""
    try:
        with open(source, "rb") as stream:
            root = qdom.parse(stream, filter_for_version=True)
    except IOError as ex:
        if ex.errno == errno.ENOENT and local:
            raise MissingLocalFeed(
                _(
                    "Feed not found. Perhaps this is a local feed that no longer exists? You can remove it from the list of feeds in that case."
                )
            )
        raise InvalidInterface(_("Can't read file"), ex)
    except Exception as ex:
        raise InvalidInterface(_("Invalid XML"), ex)

    if local:
        assert os.path.isabs(source), source
        local_path = source
    else:
        local_path = None
    feed = ZeroInstallFeed(root, local_path)
    feed.last_modified = int(os.stat(source).st_mtime)
    return feed
Exemplo n.º 3
0
def load_feed(source, local = False, selections_ok = False):
	"""Load a feed from a local file.
	@param source: the name of the file to read
	@type source: str
	@param local: this is a local feed
	@type local: bool
	@param selections_ok: if it turns out to be a local selections document, return that instead
	@type selections_ok: bool
	@raise InvalidInterface: if the source's syntax is incorrect
	@return: the new feed
	@since: 0.48
	@see: L{iface_cache.iface_cache}, which uses this to load the feeds"""
	try:
		with open(source, 'rb') as stream:
			root = qdom.parse(stream)
	except IOError as ex:
		if ex.errno == errno.ENOENT and local:
			raise MissingLocalFeed(_("Feed not found. Perhaps this is a local feed that no longer exists? You can remove it from the list of feeds in that case."))
		raise InvalidInterface(_("Can't read file"), ex)
	except Exception as ex:
		raise InvalidInterface(_("Invalid XML"), ex)

	if local:
		if selections_ok and root.uri == XMLNS_IFACE and root.name == 'selections':
			from zeroinstall.injector import selections
			return selections.Selections(root)
		local_path = source
	else:
		local_path = None
	feed = ZeroInstallFeed(root, local_path)
	feed.last_modified = int(os.stat(source).st_mtime)
	return feed
Exemplo n.º 4
0
def load_feed(source, local = False, selections_ok = False, generate_sizes = False, implementation_id_alg=None, config=None):
	"""Load a feed from a local file.
	@param source: the name of the file to read
	@type source: str
	@param local: this is a local feed
	@type local: bool
	@param selections_ok: if it turns out to be a local selections document, return that instead
	@type selections_ok: bool
	@param generate_sizes: if True, sizes of archives with missing size attributes will be generated
	@type generate_sizes: bool
	@param implementation_id_alg: if specified, missing impl ids will be generated with this alg
	@type implementation_id_alg: L{Algorithm}
	@raise InvalidInterface: if the source's syntax is incorrect
	@return: the new feed
	@since: 0.48
	@see: L{iface_cache.iface_cache}, which uses this to load the feeds"""
	try:
		root = qdom.parse(file(source))
	except IOError as ex:
		if ex.errno == 2 and local:
			raise MissingLocalFeed(_("Feed not found. Perhaps this is a local feed that no longer exists? You can remove it from the list of feeds in that case."))
		raise InvalidInterface(_("Can't read file"), ex)
	except Exception as ex:
		raise InvalidInterface(_("Invalid XML"), ex)

	if local:
		if selections_ok and root.uri == XMLNS_IFACE and root.name == 'selections':
			from zeroinstall.injector import selections
			return selections.Selections(root)
		local_path = source
	else:
		local_path = None
	if implementation_id_alg or generate_sizes:
		from zeroinstall.injector.config import load_config
		if config is None:
			config = load_config()
		feed = ZeroInstallFeed(root, local_path, None, generate_sizes, implementation_id_alg, config.fetcher, config.stores)
	else:
		feed = ZeroInstallFeed(root, local_path)
	feed.last_modified = int(os.stat(source).st_mtime)
	
	return feed
Exemplo n.º 5
0
    try:
        root = qdom.parse(file(source))
    except IOError, ex:
        if ex.errno == 2:
            raise InvalidInterface(
                _("Feed not found. Perhaps this is a local feed that no longer exists? You can remove it from the list of feeds in that case."
                  ), ex)
        raise InvalidInterface(_("Can't read file"), ex)
    except Exception, ex:
        raise InvalidInterface(_("Invalid XML"), ex)

    if local:
        local_path = source
    else:
        local_path = None
    feed = ZeroInstallFeed(root, local_path, distro.get_host_distribution())
    feed.last_modified = int(os.stat(source).st_mtime)

    if not local:
        if feed.url != interface.uri:
            raise InvalidInterface(
                _("Incorrect URL used for feed.\n\n"
                  "%(feed_url)s is given in the feed, but\n"
                  "%(interface_uri)s was requested") % {
                      'feed_url': feed.url,
                      'interface_uri': interface.uri
                  })

    interface._main_feed = feed
    return feed
Exemplo n.º 6
0
	"""Load a feed from a local file.
	@param source: the name of the file to read
	@type source: str
	@param local: this is a local feed
	@type local: bool
	@param selections_ok: if it turns out to be a local selections document, return that instead
	@type selections_ok: bool
	@raise InvalidInterface: if the source's syntax is incorrect
	@return: the new feed
	@since: 0.48
	@see: L{iface_cache.iface_cache}, which uses this to load the feeds"""
	try:
		root = qdom.parse(file(source))
	except IOError, ex:
		if ex.errno == 2:
			raise InvalidInterface(_("Feed not found. Perhaps this is a local feed that no longer exists? You can remove it from the list of feeds in that case."), ex)
		raise InvalidInterface(_("Can't read file"), ex)
	except Exception, ex:
		raise InvalidInterface(_("Invalid XML"), ex)

	if local:
		if selections_ok and root.uri == XMLNS_IFACE and root.name == 'selections':
			from zeroinstall.injector import selections
			return selections.Selections(root)
		local_path = source
	else:
		local_path = None
	feed = ZeroInstallFeed(root, local_path)
	feed.last_modified = int(os.stat(source).st_mtime)
	return feed