qdo (5147:a7b91336a3fc) | qdo (11320:42ecb523c64a) |
---|---|
1#! /usr/bin/env python 2 3# Copyright (c) 2004-2005, 2007 The Regents of The University of Michigan 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28# 29# Authors: Steve Reinhardt 30# Ali Saidi 31 32# Important! | 1#! /usr/bin/env python 2 3# Copyright (c) 2004-2005, 2007 The Regents of The University of Michigan 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28# 29# Authors: Steve Reinhardt 30# Ali Saidi 31 32# Important! |
33# This script expects a simple $ prompt, if you are using a shell other than | 33# This script expects a simple $ prompt, if you are using a shell other than |
34# sh which defaults to this you'll need to add something like the following 35# to your bashrc/bash_profile script: 36#if [ "$OAR_USER" = "xxxx" ]; then 37# PS1='$ ' 38 39 40import sys 41import os --- 50 unchanged lines hidden (view full) --- 92class Shell(pexpect.spawn): 93 # Regexp to match the shell prompt. We change the prompt to 94 # something fixed and distinctive to make it easier to match 95 # reliably. 96 prompt_re = re.compile('qdo\$ ') 97 98 def __init__(self, cmd): 99 # initialize base pexpect.spawn object | 34# sh which defaults to this you'll need to add something like the following 35# to your bashrc/bash_profile script: 36#if [ "$OAR_USER" = "xxxx" ]; then 37# PS1='$ ' 38 39 40import sys 41import os --- 50 unchanged lines hidden (view full) --- 92class Shell(pexpect.spawn): 93 # Regexp to match the shell prompt. We change the prompt to 94 # something fixed and distinctive to make it easier to match 95 # reliably. 96 prompt_re = re.compile('qdo\$ ') 97 98 def __init__(self, cmd): 99 # initialize base pexpect.spawn object |
100 try: | 100 try: |
101 pexpect.spawn.__init__(self, cmd) | 101 pexpect.spawn.__init__(self, cmd) |
102 except pexpect.ExceptionPexpect, exc: 103 print "%s:" % progname, exc 104 sys.exit(1) | 102 except pexpect.ExceptionPexpect, exc: 103 print "%s:" % progname, exc 104 sys.exit(1) |
105 # full_output accumulates the full output of the session 106 self.full_output = "" 107 self.quick_timeout = 15 108 # wait for a prompt, then change it 109 try: 110 self.expect('\$ ', options.oarsub_timeout) 111 except pexpect.TIMEOUT: 112 print >>sys.stderr, "%s: oarsub timed out." % progname --- 28 unchanged lines hidden (view full) --- 141 status = int(self.do_bare_command("echo $?", self.quick_timeout)) 142 return (output, status) 143 144 # Check to see if the given directory exists. 145 def dir_exists(self, dirname): 146 (output, status) = shell.do_command('[ -d %s ]' % dirname, 147 self.quick_timeout) 148 return status == 0 | 105 # full_output accumulates the full output of the session 106 self.full_output = "" 107 self.quick_timeout = 15 108 # wait for a prompt, then change it 109 try: 110 self.expect('\$ ', options.oarsub_timeout) 111 except pexpect.TIMEOUT: 112 print >>sys.stderr, "%s: oarsub timed out." % progname --- 28 unchanged lines hidden (view full) --- 141 status = int(self.do_bare_command("echo $?", self.quick_timeout)) 142 return (output, status) 143 144 # Check to see if the given directory exists. 145 def dir_exists(self, dirname): 146 (output, status) = shell.do_command('[ -d %s ]' % dirname, 147 self.quick_timeout) 148 return status == 0 |
149 | 149 |
150 # Don't actually try to close it.. just wait until it closes by itself | 150 # Don't actually try to close it.. just wait until it closes by itself |
151 # We can't actually kill the pid which is what it's trying to do, and if 152 # we call wait we could be in an unfortunate situation of it printing input | 151 # We can't actually kill the pid which is what it's trying to do, and if 152 # we call wait we could be in an unfortunate situation of it printing input |
153 # right as we call wait, so the input is never read and the process never ends 154 def safe_close(self): 155 count = 0 156 while self.isalive() and count < 10: 157 time.sleep(1) 158 self.close(force=False) | 153 # right as we call wait, so the input is never read and the process never ends 154 def safe_close(self): 155 count = 0 156 while self.isalive() and count < 10: 157 time.sleep(1) 158 self.close(force=False) |
159 | 159 |
160# Spawn the interactive pool job. 161 162# Hack to do link on poolfs... disabled for now since 163# compiler/linker/library versioning problems between poolfs and 164# nodes. May never work since poolfs is x86-64 and nodes are 32-bit. 165if False and len(cmd) > 50: 166 shell_cmd = 'ssh -t poolfs /bin/sh -l' 167 print "%s: running %s on poolfs" % (progname, cmd[0]) --- 71 unchanged lines hidden --- | 160# Spawn the interactive pool job. 161 162# Hack to do link on poolfs... disabled for now since 163# compiler/linker/library versioning problems between poolfs and 164# nodes. May never work since poolfs is x86-64 and nodes are 32-bit. 165if False and len(cmd) > 50: 166 shell_cmd = 'ssh -t poolfs /bin/sh -l' 167 print "%s: running %s on poolfs" % (progname, cmd[0]) --- 71 unchanged lines hidden --- |