Ejemplo n.º 1
0
def symlink(src, dest):

    # Make sure we have a kerberos ticket.

    if src.startswith('/pnfs/') and not pnfs_is_mounted:
        if debug:
            print('*** Larbatch_posix: Make symbolic link from %s to %s using nfs server.' % (src, dest))
        larbatch_utilities.test_ticket()
        cmd = ['ssh', larbatch_utilities.nfs_server(), 'ln', '-s', src, dest]
        jobinfo = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        q = queue.Queue()
        thread = threading.Thread(target=larbatch_utilities.wait_for_subprocess, args=[jobinfo, q])
        thread.start()
        thread.join(timeout=60)
        if thread.is_alive():
            if debug:
                print('*** Larbatch_posix: Terminating subprocess.')
            jobinfo.terminate()
            thread.join()
        rc = q.get()
        jobout = convert_str(q.get())
        joberr = convert_str(q.get())
        if rc != 0:
            raise IFDHError(cmd, rc, jobout, joberr)

    else:
        if debug:
            print('*** Larbatch_posix: Make symbolic link from %s to %s using posix.' % (src, dest))
        os.symlink(src, dest)
Ejemplo n.º 2
0
def readlink(path):

    result = ''

    # Make sure we have a kerberos ticket.

    if path.startswith('/pnfs/') and not_pnfs_is_mounted:
        if debug:
            print(
                '*** Larbatch_posix: Read symbolic link %s using nfs server.' %
                path)
        larbatch_utilities.test_ticket()
        cmd = ['ssh', larbatch_utilities.nfs_server(), 'readlink', path]
        jobinfo = subprocess.Popen(cmd,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)

        q = queue.Queue()
        thread = threading.Thread(
            target=larbatch_utilities.wait_for_subprocess, args=[jobinfo, q])
        thread.start()
        thread.join(timeout=60)
        if thread.is_alive():
            if debug:
                print('*** Larbatch_posix: Terminating subprocess.')
            jobinfo.terminate()
            thread.join()
        rc = q.get()
        jobout = convert_str(q.get())
        joberr = convert_str(q.get())
        if rc != 0:
            raise IFDHError(cmd, rc, jobout, joberr)
        result = jobout.strip()

    else:
        if debug:
            print('*** Larbatch_posix: Read symbolic link %s using posix.' %
                  path)
        result = os.readlink(path)

    # Done.

    return result