Example #1
0
def test_open(tmppath):
    """Test fs.open()"""
    # Create a file to open.
    file_name = 'data/testa.txt'
    contents = 'testa.txt\n'
    xrd_rooturl = mkurl(tmppath)

    # Open file w/ xrootd
    xrdfs = XRootDPyFS(xrd_rooturl)
    xfile = xrdfs.open(file_name, mode='r')
    assert xfile
    assert xfile.path.endswith("data/testa.txt")
    assert type(xfile) == XRootDPyFile
    assert xfile.read() == contents
    xfile.close()

    # Test passing of querystring.
    xrdfs = XRootDPyFS(xrd_rooturl + "?xrd.wantprot=krb5")
    xfile = xrdfs.open(file_name, mode='r')
    assert xfile
    assert xfile.path.endswith("data/testa.txt?xrd.wantprot=krb5")
    assert type(xfile) == XRootDPyFile
    assert xfile.read() == contents
    xfile.close()
Example #2
0
def test_open(tmppath):
    """Test fs.open()"""
    # Create a file to open.
    file_name = 'data/testa.txt'
    contents = 'testa.txt\n'
    xrd_rooturl = mkurl(tmppath)

    # Open file w/ xrootd
    xrdfs = XRootDPyFS(xrd_rooturl)
    xfile = xrdfs.open(file_name, mode='r')
    assert xfile
    assert xfile.path.endswith("data/testa.txt")
    assert type(xfile) == XRootDPyFile
    assert xfile.read() == contents
    xfile.close()

    # Test passing of querystring.
    xrdfs = XRootDPyFS(xrd_rooturl + "?xrd.wantprot=krb5")
    xfile = xrdfs.open(file_name, mode='r')
    assert xfile
    assert xfile.path.endswith("data/testa.txt?xrd.wantprot=krb5")
    assert type(xfile) == XRootDPyFile
    assert xfile.read() == contents
    xfile.close()
 def file_downloader(self):
     """Download single file with XrootDPyFS."""
     try:
         fs = XRootDPyFS("root://eospublic.cern.ch//")
         with open(self.file_dest,
                   self.mode) as dest, fs.open(self.file_src, "rb") as src:
             display_message(
                 msg_type="note",
                 msg="File: ./{}/{}".format(
                     self.path,
                     self.file_name,
                 ),
             )
             src_data = src.read()
             dest.write(src_data)
     except Exception:
         display_message(msg_type="error",
                         msg="Download error occured. Please try again.")
Example #4
0
def file_opener_xrootd(path, *args, **kwargs):
    """File opener from XRootD path.

    :param path: The file path for the opener.
    :returns: an open file

    .. note::

        This will return an open file via ``XRootDPyFS`` if XRootD is
        enabled.
    """
    if current_app.config['XROOTD_ENABLED'] and \
            current_app.config['VIDEOS_XROOTD_ENDPOINT'] in path:
        from xrootdpyfs import XRootDPyFS
        # Get the filename
        _filename = path.split('/')[-1]
        # Remove filename from the path
        path = path.replace(_filename, '')
        fs = XRootDPyFS(path)
        return fs.open('data', *args, **kwargs)
    # No XrootD return a normal file
    return open(path, *args, **kwargs)