Exemplo n.º 1
0
    def downloadRawFile ( self , remote , local=None ) :
        """Downloads a remote file to the local system.

        remote - path relative to repository base
        local - Optional local name for the file

        Returns the local file name or False if errors"""

        remote = repolib.urljoin( self.base_url() , remote ) 

        if not local :
            (handle, fname) = tempfile.mkstemp()
        else :
            fname = local
            handle = os.open( fname , os.O_WRONLY | os.O_TRUNC | os.O_CREAT )
        if not repolib.download( remote , handle ) :
            os.unlink(fname)
            return False
        return fname
Exemplo n.º 2
0
    def downloadRawFile(self, remote, local=None):
        """Downloads a remote file to the local system.

        remote - path relative to repository base
        local - Optional local name for the file

        Returns the local file name or False if errors"""

        remote = repolib.urljoin(self.base_url(), remote)

        if not local:
            (handle, fname) = tempfile.mkstemp()
        else:
            fname = local
            handle = os.open(fname, os.O_WRONLY | os.O_TRUNC | os.O_CREAT)
        if not repolib.download(remote, handle):
            os.unlink(fname)
            return False
        return fname
Exemplo n.º 3
0
    if not os.path.isdir(os.path.dirname(local_path)):
        try:
            os.makedirs(os.path.dirname(local_path))
        except OSError, ex:
            req.log_error("Cannot create destination hierarchy %s" % os.path.dirname(local_path))
            req.status = apache.HTTP_INTERNAL_SERVER_ERROR
            return apache.DONE

    if not os.path.exists(local_path):
        try:
            local = os.open(local_path, os.O_CREAT | os.O_WRONLY)
        except Exception, ex:
            req.log_error("Cannot write local copy %s : %s" % (local_path, ex))
            return apache.HTTP_NOT_FOUND
        req.log_error("Downloading %s" % remote_url, apache.APLOG_INFO)
        remote = repolib.download(remote_url, local, req)
        if not remote:
            req.log_error("Cannot download remote %s" % remote_url)
            return apache.HTTP_NOT_FOUND

        file_size = int(remote.info().getheaders("Content-Length")[0])
        if "content-type" in remote.info().keys():
            req.content_type = remote.info().getheader("Content-Type")

    else:
        req.sendfile(local_path)

    return apache.OK


def handler(req):
Exemplo n.º 4
0
        try:
            os.makedirs(os.path.dirname(local_path))
        except OSError, ex:
            req.log_error("Cannot create destination hierarchy %s" %
                          os.path.dirname(local_path))
            req.status = apache.HTTP_INTERNAL_SERVER_ERROR
            return apache.DONE

    if not os.path.exists(local_path):
        try:
            local = os.open(local_path, os.O_CREAT | os.O_WRONLY)
        except Exception, ex:
            req.log_error("Cannot write local copy %s : %s" % (local_path, ex))
            return apache.HTTP_NOT_FOUND
        req.log_error("Downloading %s" % remote_url, apache.APLOG_INFO)
        remote = repolib.download(remote_url, local, req)
        if not remote:
            req.log_error("Cannot download remote %s" % remote_url)
            return apache.HTTP_NOT_FOUND

        file_size = int(remote.info().getheaders("Content-Length")[0])
        if 'content-type' in remote.info().keys():
            req.content_type = remote.info().getheader('Content-Type')

    else:
        req.sendfile(local_path)

    return apache.OK


def handler(req):