Changeset 104

Show
Ignore:
Timestamp:
11/20/07 20:35:52 (1 year ago)
Author:
edsuom
Message:

Fixes to jobs client

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/AsynCluster/trunk/asyncluster/master/jobs.py

    r94 r104  
    2323""" 
    2424 
    25 import os.path 
     25import os.path, textwrap 
    2626 
    2727from zope.interface import implements 
     
    4242    root = None 
    4343     
    44     def __init__(self, socket, codeFilePath): 
    45         for name, msgPart in ( 
    46             ('socket', 'UNIX socket'), ('codeFilePath', 'code file')): 
    47             #------------------------------------------------------- 
    48             path = locals()[name] 
    49             if not os.path.exists(path): 
    50                 raise RuntimeError( 
    51                     "No %s available at '%s'" % (msgPart, socket)) 
    52             setattr(self, name, path) 
     44    def __init__(self, socket, codePath=None, codeString=None): 
     45        if not os.path.exists(socket): 
     46            raise RuntimeError("No UNIX socket available at '%s'" % socket) 
     47        self.socket = socket 
     48        if codeString is None and codePath is None: 
     49            raise RuntimeError( 
     50                "You must specify either a file or a string containing "+\ 
     51                "Python source for the job.") 
     52        if codeString is None: 
     53            if not os.path.exists(codePath): 
     54                raise RuntimeError("No code file available at '%s'" % codePath) 
     55            fh = open(codePath) 
     56            codeString = fh.read() 
     57            fh.close() 
     58        self.jobCode = textwrap.dedent(codeString) 
    5359     
    5460    def startup(self): 
     
    6268            if pb.IUnjellyable.providedBy(answer): 
    6369                self.root = answer 
    64                 return gotRoot() 
     70                d = self.root.callRemote('newJob', self.jobCode) 
     71                d.addCallback(gotID) 
     72                return d 
    6573            return False 
    66  
    67         def gotRoot(): 
    68             fh = open(self.codeFilePath) 
    69             jobCode = fh.read() 
    70             fh.close() 
    71             return self.root.callRemote('newJob', jobCode).addCallback(gotID) 
    7274 
    7375        def gotID(jobID):