def currentJob(job=None): import os if not job: if os.environ.has_key('PIPE_JOB'): job = os.environ['PIPE_JOB'] if not job: return '' return "%s/%s" % (roots.jobs(), job)
def __init__(self, projectID=None, projectName=None, adminUser="******"): if not projectID: if os.environ.has_key('PIPE_JOB'): tmp = os.environ['PIPE_JOB'].split('.') projectID = int(tmp[0]) projectName = '.'.join(tmp[1:]) else: raise Exception("ERROR: No Job Set!!") sudo.__init__(self) self.root = roots.jobs() self.proj = "%04d.%s" % (int(projectID), projectName.lower()) self.__user = adminUser self.projPath = "%s/%s" % (self.root, self.proj)
def __go(args): import sys, os from glob import glob from job import current as currentJob from job import currentShot args = map( lambda x: x.lower(), args ) if 'reset' in args or '-r' in args: return "\n".join([ 'unset PIPE_JOB', 'unset PIPE_SHOT', '''PROMPT_COMMAND='echo -ne "\033]0;No Job/Shot set!!\007"' ''', ]) reserved = ['asset', 'shot', 'shot'] job = None # if os.environ.has_key('PIPE_JOB'): # job = os.environ['PIPE_JOB'] shot = None # if os.environ.has_key('PIPE_SHOT'): # shot = os.environ['PIPE_SHOT'] env = [] # passed arguments if len(args)>1: if args[1].lower() not in reserved: jobs = filter( lambda x: args[1] in x, glob( "%s/*" % roots.jobs() ) ) if not jobs: ret = ["echo 'ERROR: job %s doesnt exist! \n\nOptions are:'\n" % args[1].lower()] for each in glob( '%s/*' % (roots.jobs()) ): beach = os.path.basename(each) if beach[:4] != '0000': ret.append( "echo '\t %s'" % beach ) ret.append( "echo ' '") return "\n".join(ret) elif len(jobs)>1: ret = ["echo 'WARNING: There is more than one job with `%s` in it! \n\nOptions are:'\n" % args[1].lower()] for each in jobs: beach = os.path.basename(each) if beach[:4] != '0000': ret.append( "echo '\t %s'" % beach ) ret.append( "echo ' '") return "\n".join(ret) job = os.path.basename(jobs[0]) env.append( 'export PIPE_JOB="%s"' % job ) env.append( 'unset PIPE_SHOT' ) for each in reserved: if each in args: value = "" try: value = args[args.index(each)+1] if not os.path.exists('%s/%s/%ss/%s' % (roots.jobs(), job, each, value) ): raise shot = "%s@%s" % (each, value) env.append( 'export PIPE_SHOT="%s"' % shot ) except: ret = ["echo 'ERROR: %s %s doesnt exist!\n\nOptions are:'" % (each, value)] for l in glob( '%s/%s/%ss/*' % (roots.jobs(), job, each) ): ret.append( "echo '\t%s %s'" % (each, os.path.basename(l)) ) ret.append( "echo ' '") return "\n".join(ret) if not job: return "\n".join([ "echo 'ERROR: No current job set.'", '''PROMPT_COMMAND='echo -ne "\033]0;No Job/Shot set!!\007"' ''', ]) # cd to job env.append( 'cd "%s"' % currentJob(job) ) # add job tools/python to pythonpath path = '%s/tools/scripts' % currentJob(job) env.append( 'export PATH=%s:$__PATH' % path ) pythonpath = '%s/tools/python' % currentJob(job) env.append( 'export PYTHONPATH=%s:$__PYTHONPATH' % pythonpath ) # deal with shot values = ['Shot',''] if shot: if os.path.exists( "%s/users/%s" % (currentShot(job, shot), admin.username()) ): env.append( 'cd "%s/users/%s"' % (currentShot(job, shot), admin.username()) ) else: env.append( 'cd "%s/users"' % currentShot(job, shot) ) values = shot.split('@') values[0] = "%s%s" % (values[0][0].upper(), values[0][1:]) # add shot/user/tools/python to pythonpath path += ':%s/tools/scripts' % currentShot(job, shot) path += ':%s/users/%s/tools/scripts' % (currentShot(job, shot), admin.username()) pythonpath += ':%s/tools/python' % currentShot(job, shot) pythonpath += ':%s/users/%s/tools/python' % (currentShot(job, shot), admin.username()) env.append( 'export PATH=%s:$__PATH' % path ) env.append( 'export PYTHONPATH=%s:$__PYTHONPATH' % pythonpath ) env.append( 'echo "Job: %s\n%s: %s\nPath: $(pwd)"' % (job, values[0], values[1] ) ) env.append( '''PROMPT_COMMAND='echo -ne "\033]0;Job: %s | %s: %s\007"' ''' % (job, values[0], values[1]) ) # if running in Qube, set PIPE_FARM_USER if os.environ.has_key('QBJOBID'): user = '' for line in os.popen('/atomo/apps/linux/x86_64/qube/current/qube-core/local/pfx/qube/bin/qbjobs --expression "id==%s" --user "" ' % os.environ['QBJOBID']).readlines(): if os.environ['QBJOBID'] in line: user = line[38:48].strip() env.append( 'export PIPE_FARM_USER=%s' % user ) env.append( 'export PIPE_FARM_JOBID=%s' % os.environ['QBJOBID'] ) return '%s \n %s' % (init(), '\n'.join(env))