Exemplo n.º 1
0
 def addFile(pOut):
     '''Used to make a file that will be shown in output tab of website. If
     the file does not exist, it will make a new one that can be written to.'''
     matches = _pComm.__addFile.finditer(pOut)
     for m in matches:
         if m is not None:
             FileChecker.addFile(m.group("name"),
                                 m.group("fileName"),
                                 m.group("desc"))
             
             if not os.path.isfile("output/" + m.group("fileName")):
                 open(os.path.join(DIR_FILEOUTPUT,m.group("fileName")),"w").close()
             
             StatusIO.write("Pipeline added file: <a href='%s' target='_blank'>%s</a> - %s" \
                            % ("output/" + m.group("fileName"),
                               m.group("name"),
                               m.group("desc")))
         pOut = pOut.replace(m.group(),"")
     return pOut
Exemplo n.º 2
0
 def run(self):
     '''Used to install software on the server. Reports to statusIOobj to
         inform user of status. Starts pipeline once install complete'''
     #write software to node.js
     if not os.path.isdir(Installer.NODEJS_DIR):
         os.mkdir(Installer.NODEJS_DIR)
     nodejs = open(Installer.NODEJS_PATH,"w")
     nodejs.write('{ "run_list": [ %s ] }' 
         % ', '.join(['"recipe[%s]"' % s for s in self.__softwareList]))
     nodejs.close()
     
     #execute chef-solo to install
     command = ["chef-solo","-j",Installer.NODEJS_PATH,"-r",Installer.CHEF_REPO_LOCATION]
     process = subprocess.Popen(command,stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
         
     #redirect output to website
     while(process.poll() == None):
         StatusIO.write(process.stdout.read())
         StatusIO.write(process.stderr.read())
         
     Controller().SIG_KEYS[SIG_KEY_INSTALLER] = True
Exemplo n.º 3
0
 def writeToFile(pOut):
     '''Can either use this function to write to an output file, or use the
     pipeline to pipe to a file that was already created with addFile.
     This command should be used with caution, if a pipeline is going to
     produce a lot of output, it would be better for it to directly pipe
     into the file.'''
     matches = _pComm.__writeToFile.finditer(pOut)
     open_dict = {}
     for m in matches:
         if m is not None:
             abs_path = os.path.join(DIR_FILEOUTPUT,m.group("fileName")) 
             
             if not os.path.isfile(abs_path):
                 StatusIO.write("[ERROR] File being written to with pComm.writeToFile cannot be found, did you forget to use addFile first?")
                 continue
             
             if abs_path not in open_dict.keys():
                 open_dict[abs_path] = open(abs_path,"a")
             
             open_dict[abs_path].write(m.group("text").decode("string_escape"))
         pOut = pOut.replace(m.group(),"")
     for k in open_dict.keys():
         open_dict[k].close()
     return pOut
Exemplo n.º 4
0
    def run(self):
        '''Start a pipeline downloaded from pipelineUrl.'''
        
        StatusIO.write("Pipeline located at '%s', downloading..." \
                       % self.__pipelineUrl)
        
        #copy pipeline into current directory
        try:
            purl = urllib.urlopen(self.__pipelineUrl)
        except IOError:
            StatusIO.write("[ERROR] Pipeline not found at url.")
            return
            
        f = open(PIPELINE_FILE_PATH,"w")
        f.write(purl.read())
        f.close()
        purl.close()
        
        if os.path.getsize(PIPELINE_FILE_PATH) < 1:
            StatusIO.write("[ERROR] Pipeline script was not properly downloaded.")
            return
            
        #make pipeline executable
        command = ["chmod","+x",PIPELINE_FILE_PATH]
        process = subprocess.Popen(command)
        while(process.poll() is None): pass
        
        StatusIO.write("Pipeline now executable. Executing...")
        
        #execute pipeline script
        command = ["sudo","%s" % PIPELINE_FILE_PATH]
        process = subprocess.Popen(command,stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        
        #redirect output to website
        while(process.poll() is None):
            pOut = process.stdout.read()
            pErr = process.stderr.read()    
            
            #here, pipeline output is checked for commands from stdout
            pOut = _pComm.checkComm(pOut)

            if(len(pOut) > 0):
                StatusIO.write("[PIPELINE][COUT] {{ %s }}" % pOut)
            if(len(pErr) > 0):
                StatusIO.write("[PIPELINE][CERR] {{ %s }}" % pErr)
        
                
        StatusIO.write("Pipeline complete. Click here to view results: <a href='results'>results</a>")
        Controller().SIG_KEYS[SIG_KEY_PIPELINE] = True
Exemplo n.º 5
0
 def getstatus(self):
     return StatusIO.read(get_response(),get_request().get_field("lastLine"))