Beispiel #1
0
    def open(self, path, flags, attr):
        """
        Open a file on the server and create a handle for future operations
        on that file.  On success, a new object subclassed from L{SFTPHandle}
        should be returned.  This handle will be used for future operations
        on the file (read, write, etc).  On failure, an error code such as
        L{SFTP_PERMISSION_DENIED} should be returned.

        C{flags} contains the requested mode for opening (read-only,
        write-append, etc) as a bitset of flags from the C{os} module:

            - C{os.O_RDONLY}
            - C{os.O_WRONLY}
            - C{os.O_RDWR}
            - C{os.O_APPEND}
            - C{os.O_CREAT}
            - C{os.O_TRUNC}
            - C{os.O_EXCL}

        (One of C{os.O_RDONLY}, C{os.O_WRONLY}, or C{os.O_RDWR} will always
        be set.)

        The C{attr} object contains requested attributes of the file if it
        has to be created.  Some or all attribute fields may be missing if
        the client didn't specify them.

        @note: The SFTP protocol defines all files to be in "binary" mode. \
            There is no equivalent to python's "text" mode.

        :param basestring path: the requested datafile path
        :param int flags: flags or'd together from the C{os} module indicating \
            the requested mode for opening the file.
        :param SFTPAttributes attr: requested attributes of the file if it is \
            newly created.
        :returns: a new L{SFTPHandle} I{or error code}.
        :rtype: SFTPHandle
        """
        leaf = self.tree.get_leaf(path)
        tracker.track_download('sftp',
                               session_id=self.uuid,
                               ip=self.client_ip,
                               user=self.user,
                               total_size=leaf.obj.size,
                               num_files=1)
        return MyTSFTPHandle(leaf.obj, flags, attr)
Beispiel #2
0
    def open(self, path, flags, attr):
        """
        Open a file on the server and create a handle for future operations
        on that file.  On success, a new object subclassed from L{SFTPHandle}
        should be returned.  This handle will be used for future operations
        on the file (read, write, etc).  On failure, an error code such as
        L{SFTP_PERMISSION_DENIED} should be returned.

        C{flags} contains the requested mode for opening (read-only,
        write-append, etc) as a bitset of flags from the C{os} module:

            - C{os.O_RDONLY}
            - C{os.O_WRONLY}
            - C{os.O_RDWR}
            - C{os.O_APPEND}
            - C{os.O_CREAT}
            - C{os.O_TRUNC}
            - C{os.O_EXCL}

        (One of C{os.O_RDONLY}, C{os.O_WRONLY}, or C{os.O_RDWR} will always
        be set.)

        The C{attr} object contains requested attributes of the file if it
        has to be created.  Some or all attribute fields may be missing if
        the client didn't specify them.

        @note: The SFTP protocol defines all files to be in "binary" mode. \
            There is no equivalent to python's "text" mode.

        :param basestring path: the requested datafile path
        :param int flags: flags or'd together from the C{os} module indicating \
            the requested mode for opening the file.
        :param SFTPAttributes attr: requested attributes of the file if it is \
            newly created.
        :returns: a new L{SFTPHandle} I{or error code}.
        :rtype: SFTPHandle
        """
        leaf = self.tree.get_leaf(path)
        tracker.track_download(
            'sftp', session_id=self.uuid, ip=self.client_ip, user=self.user,
            total_size=leaf.obj.size, num_files=1)
        return MyTSFTPHandle(leaf.obj, flags, attr)
Beispiel #3
0
def _streaming_downloader(request,
                          datafiles,
                          rootdir,
                          filename,
                          comptype='tgz',
                          organization=DEFAULT_ORGANIZATION):
    '''
    private function to be called by wrappers
    creates download response with given files and names
    '''
    mapper = _make_mapper(organization, rootdir)
    if not mapper:
        return render_error_message(request,
                                    'Unknown download organization: %s' %
                                    organization,
                                    status=400)
    try:
        files = _get_datafile_details_for_archive(mapper, datafiles)
        tfs = UncachedTarStream(files,
                                filename=filename,
                                do_gzip=comptype != 'tar')
        tracker.track_download('tar',
                               session_id=request.COOKIES.get('_ga'),
                               ip=request.META.get('REMOTE_ADDR', ''),
                               user=request.user,
                               total_size=tfs.tar_size,
                               num_files=len(datafiles),
                               ua=request.META.get('HTTP_USER_AGENT', None))
        return tfs.get_response()
    except ValueError:  # raised when replica not verified TODO: custom excptn
        redirect = request.META.get(
            'HTTP_REFERER', 'http://%s/' % request.META.get('HTTP_HOST'))
        message = """The experiment you are trying to access has not yet been
                     verified completely.
                     Verification is an automated background process.
                     Please try again later or contact the system
                     administrator if the issue persists."""
        message = ' '.join(message.split())  # removes spaces
        redirect = redirect + '#error:' + message
        return HttpResponseRedirect(redirect)