Example #1
0
    def __init__(self, uri=None):
        self.uri = None
        # Temp. directory, a unicode string
        self._tempdir = None
        self.file_ = None

        if uri:
            if not is_uri(uri):
                # It is a real filename
                self.uri = uri
                self.file_ = uri2path(uri)
            else:
                u = urllib.request.urlopen(uri)

                # Use the same extension
                self.uri = uri
                (n, e) = os.path.splitext(uri)
                logger.info("Making a local copy of %s", uri)
                f, self.file_ = tempfile.mkstemp(e, 'adv')
                os.write(f, u.read())
                os.close(f)
                u.close()

        if self.file_ is not None:
            self.open(self.file_)
Example #2
0
    def save(self, name=None):
        """Save the Package in the specified file.

        We expect that the name is a unicode string.
        """
        if name is None:
            name=self.__uri

        name = uri2path(name)
        # handle .azp files.
        if name.lower().endswith('.azp') or name.endswith('/'):
            # AZP format
            if self.__zip is None:
                # Conversion necessary: we are saving to the new format.
                z=ZipPackage()
                z.new()
                self.__zip = z

            # Save the content.xml (using binary mode since serialize is handling encoding)
            stream = open (self.__zip.getContentsFile(), "wb")
            self.serialize(stream)
            stream.close ()

            # Generate the statistics
            self.__zip.update_statistics(self)

            # Save the whole .azp
            self.__zip.save(name)
        else:
            # Assuming plain XML format
            stream = open (name, "wb")
            self.serialize(stream)
            stream.close ()
Example #3
0
    def save(self, name=None):
        """Save the Package in the specified file.

        We expect that the name is a unicode string.
        """
        if name is None:
            name=self.__uri

        name = uri2path(name)
        # handle .azp files.
        if name.lower().endswith('.azp') or name.endswith('/'):
            # AZP format
            if self.__zip is None:
                # Conversion necessary: we are saving to the new format.
                z=ZipPackage()
                z.new()
                self.__zip = z

            # Save the content.xml (using binary mode since serialize is handling encoding)
            stream = open (self.__zip.getContentsFile(), "wb")
            self.serialize(stream)
            stream.close ()

            # Generate the statistics
            self.__zip.update_statistics(self)

            # Save the whole .azp
            self.__zip.save(name)
        else:
            # Assuming plain XML format
            stream = open (name, "wb")
            self.serialize(stream)
            stream.close ()
Example #4
0
    def getUri(self, absolute=True, context=None):
        """Return the URI of the package.

        Parameter if _absolute_ is _True_, the URI will be forced absolute.
        If not, and if _context_ is _None_, the URI will be resolved with
        respect to the root package URI, whatever its stored form (absolute or
        relative).
        If context is given and is a (direct or indirect) importer package,
        the URI will be resolved with respect to the context URI, whatever its
        stored form (absolute or relative).

        You would probably rather use the uri read-only property, unless you
        want to set the parameter _absolute_.
        """
        uri = self.__uri or ""

        if not absolute and context is self:
            return ''

        if is_uri(uri):
            # This is a file. Keep only the local path.
            path = uri2path(uri)
            if absolute:
                uri = Path(path).absolute().as_uri()
            else:
                uri = Path(path).as_uri()
        importer = self.__importer
        if importer is not None:
            uri = urljoin (importer.getUri (absolute, context), uri)

        return uri
Example #5
0
    def getUri(self, absolute=True, context=None):
        """Return the URI of the package.

        Parameter if _absolute_ is _True_, the URI will be forced absolute.
        If not, and if _context_ is _None_, the URI will be resolved with
        respect to the root package URI, whatever its stored form (absolute or
        relative).
        If context is given and is a (direct or indirect) importer package,
        the URI will be resolved with respect to the context URI, whatever its
        stored form (absolute or relative).

        You would probably rather use the uri read-only property, unless you
        want to set the parameter _absolute_.
        """
        uri = self.__uri or ""

        if not absolute and context is self:
            return ''

        if is_uri(uri):
            # This is a file. Keep only the local path.
            path = uri2path(uri)
            if absolute:
                uri = Path(path).absolute().as_uri()
            else:
                uri = Path(path).as_uri()
        importer = self.__importer
        if importer is not None:
            uri = urljoin (importer.getUri (absolute, context), uri)

        return uri