Example #1
0
def addLayerTwo(path, recreate=True):

    # Don't do anything if this file is not located in dCache (/pnfs/...)
    # or has nonzero size.

    if larbatch_posix.exists(path) and path[
            0:6] == '/pnfs/' and larbatch_posix.stat(path).st_size == 0:

        if recreate:
            print('Adding layer two for path %s.' % path)
        else:
            print('Deleting empty file %s.' % path)

        # Now we got a zero size file in dCache, which kind of files may be
        # missing layer two.
        # Delete the file and recreate it using ifdh.

        larbatch_posix.remove(path)
        if not recreate:
            return
        test_proxy()

        # Make sure environment variables X509_USER_CERT and X509_USER_KEY
        # are not defined (they confuse ifdh).

        save_vars = {}
        for var in ('X509_USER_CERT', 'X509_USER_KEY'):
            if var in os.environ:
                save_vars[var] = os.environ[var]
                del os.environ[var]

        # Do ifdh cp.

        command = ['ifdh', 'cp', '/dev/null', path]
        jobinfo = subprocess.Popen(command,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        q = queue.Queue()
        thread = threading.Thread(target=wait_for_subprocess,
                                  args=[jobinfo, q])
        thread.start()
        thread.join(timeout=60)
        if thread.is_alive():
            print('Terminating subprocess.')
            jobinfo.terminate()
            thread.join()
        rc = q.get()
        jobout = convert_str(q.get())
        joberr = convert_str(q.get())
        if rc != 0:
            for var in list(save_vars.keys()):
                os.environ[var] = save_vars[var]
            raise IFDHError(command, rc, jobout, joberr)

        # Restore environment variables.

        for var in list(save_vars.keys()):
            os.environ[var] = save_vars[var]
def root_stream(path):

    stream = path
    if path.startswith('/pnfs/') and (prefer_grid or not pnfs_is_mounted):
        if debug:
            print('*** Larbatch_posix: Stream path %s using xrootd.' % path)
        larbatch_utilities.test_proxy()
        stream = larbatch_utilities.xrootd_uri(path)
    else:
        if debug:
            print('*** Larbatch_posix: Stream path %s as normal file.' % path)
    return stream