def test_killprocess(self):
     
     import os
     import signal
     
     # some process that runs until killed
     if sys.platform == "win32":
         cmd = ['cmd','/k','imdisplay','foobar.gif']
     
         process_start(cmd)
         
         pids=process_instances_get('imdisplay.exe')
         self.assertEquals(len(pids),1)
         sleep(0.5)
         for _pid in pids:
             process_kill(_pid)
             
         pids=process_instances_get('imdisplay.exe')
         self.assertEquals(len(pids),0)
     else:
         cmd = ['display','foobar.gif']
         process_start(cmd)
         
         pids=process_instances_get('display')
         self.assertEquals(len(pids),1)
         
         process_kill(pids[0][0])
         pids=process_instances_get('display')
         self.assertEquals(len(pids),0)
 def test_killprocess(self):
     
     import os
     import signal
     
     # some process that runs until killed
     cmd = ['display','-geometry','750x750+7500+740','/tmp/foobar.gif']
     
     process_start(cmd)
     pids=process_instances_get('display')
     self.assertEquals(len(pids),1)
     
     process_kill(pids[0][0])
     pids=process_instances_get('display')
     self.assertEquals(len(pids),0)
 def test_failure(self):
     # known external command --verbose is a bad switch
     cmd = [IMDIR+'convert','--verbose','label:'+self.label,'-pointsize','22','foobar.gif']
     
     p = process_start(cmd)
     status = parse_convert_stdout(p,self.label)
     self.assertTrue(status[0],1)
 def test_failure(self):
     # known external command --verbose is a bad switch
     cmd = ['convert','--verbose','label:'+self.label,'-pointsize','22','/tmp/foobar.gif']
     
     p = process_start(cmd)
     status = parse_convert_stdout(p,self.label)
     self.assertTrue(status[0],1)
示例#5
0
def bindiff(file1,file2,returnfulldiff=False):
    """ binary compare 2 files
    :param file1 :string
    :param file2 :string
    :param returnfulldiff : boolean, if False func returns True/False otherwise full diff
    rtype:boolean or list of string
    """
    import sys
    from types import BooleanType
    from misc_utils_process import process_start,process_get_stdout
    from misc_utils import os_file_exists
    
    assert os_file_exists(file1),file1
    assert os_file_exists(file2),file2
    assert isinstance(returnfulldiff,BooleanType)
    
    if sys.platform == "win32":
        cmd = ['fc.exe','/B',file1,file2]
        p = process_start(cmd)
        diff_result = process_get_stdout(p)
        
        if diff_result.split("\n")[1].startswith("FC: no differences encountered"):
            return True
    
        if returnfulldiff:
            return diff_result.split("\n")
        return False
示例#6
0
    def log_cat(self,grepargs=[]):

        self.logfile.close()        

        cmd = ["cat",self.logpath]
        p = process_start(cmd)
        logfile = process_get_stdout(p) 
        
        print        
        if grepargs <> []:
            cmd = ['grep'] + grepargs      
            p = process_start(cmd,stdin=True)
            
            for line in process_stdin(p,logfile):
                print line
        else:
            print logfile
    def setUp(self):
        self.findpids=[]
        
        # some process that runs until killed
        cmd = ['find','/','-name','foobar','-print']

        for i in range(5):
            self.findpids.append(process_start(cmd))
 def test_failure_grabstderr(self):
     # known external command --verbose is a bad switch
     cmd = ['convert','--verbose','label:'+self.label,'-pointsize','22','/tmp/foobar.gif']
     
     p = process_start(cmd)
     
     stderr =  parse_convert_stdout(p,self.label)[1]
     self.assertTrue(stderr.startswith('convert.im6'))
    def setUp(self):
        self.findpids=[]
        
        # some process that runs until killed
        cmd = ['cmd','/k','imdisplay','foobar.gif']

        for i in range(5):
            self.findpids.append(process_start(cmd))
示例#10
0
    def create_image_file(self, labels, **kw):
        if not kw.has_key('convert_exec'):
            convert_exec = "convert"
        else:
            convert_exec = kw['convert_exec']
            log.log(PRIORITY.INFO,
                    msg="convert command being set to [" + convert_exec + "]")

        if not kw.has_key('overwrite'):
            kw['overwrite'] = False
            log.log(PRIORITY.INFO, msg="overwrite not set")

        if not isinstance(labels, list):
            labels = [labels]

        self.outputfiles = []
        self.labels = labels
        self.outputdirname = ImageCreate._getoutputdirname()

        for lbl in self.labels:
            cmd = [convert_exec, '-verbose']
            outputfilename = get_gif_filename(self.outputdirname, lbl, kw)

            if os_file_exists(
                    outputfilename) == False or kw['overwrite'] == True:

                # settings go before the input label/file
                for s in settings:
                    if kw.has_key(s):
                        cmd = cmd + ["-" + s, str(kw[s])]

                cmd.append(labelstr_get(lbl))

                # image operators come afterwards
                for im in image_operator:
                    if kw.has_key(im):
                        cmd = cmd + ["-" + im, str(kw[im])]

                cmd.append(outputfilename)
                p = process_start(cmd)
                status = parse_convert_stdout(p, lbl)

                if status[0] == 0:
                    log.log(PRIORITY.INFO,
                            msg="create_image=" + outputfilename)
                else:
                    log.log(PRIORITY.FAILURE,
                            msg="status=" + ",".join(map(str, status)))
                    raise Exception("ImageCreate failure", status)

            else:
                log.log(PRIORITY.INFO, msg="reused_image=" + outputfilename)

            self.outputfiles.append(outputfilename)

        return (self.outputfiles)
示例#11
0
 def log_null(self):
     try:
         self.logfile = open(self.logpath,"a")
     except IOError:
         pass
     
     cmd = ["nullfile.sh",self.logpath]
     p = process_start(cmd)  
     
     self.logfile.close()
    def test_success(self):

        # some external command to test with whose outputs are known
        cmd = [IMDIR+'convert','-verbose','label:'+self.label,'-pointsize','22','foobar.gif']
        p = process_start(cmd)
        status = parse_convert_stdout(p,self.label)
        
        self.assertEquals(status[0],0)
        self.assertTrue(status[1],'37x13')
        self.assertTrue(status[2],'foobar.txt')
    def test_success(self):

        # some external command to test with whose outputs are known
        cmd = ['convert','-verbose','label:'+self.label,'-pointsize','22','/tmp/foobar.gif']
        
        p = process_start(cmd)
        status = parse_convert_stdout(p,self.label)
        
        self.assertEquals(status[0],0)
        self.assertTrue(status[1],'37x13')
        self.assertTrue(status[2],'/tmp/foobar.txt')
 def test_failure_grabstderr(self):
     # known external command --verbose is a bad switch
     cmd = [IMDIR+'convert','--verbose','label:'+self.label,'-pointsize','22','foobar.gif']
     
     p = process_start(cmd)
     stderr = parse_convert_stdout(p,self.label)[1]
     
     if sys.platform == "win32":
         self.assertTrue(stderr.startswith('convert.exe: no decode delegate for this image format'))
     else:     
         self.assertTrue(stderr.startswith('convert: unrecognized option'))
 def test_killprocess_popen(self):
     ''' passing in a Popen object not a pid '''
     import os
     import signal
     
     # some process that runs until killed
     cmd = ['display','-geometry','750x750+7500+740','/tmp/foobar.gif']
     
     p = process_start(cmd)
     pids=process_instances_get('display')
     self.assertEquals(len(pids),1)
     
     process_kill(p)
     pids=process_instances_get('display')
     self.assertEquals(len(pids),0)
 def test_killprocess_popen(self):
     # passing in a Popen object not a pid
     import os
     import signal
     
     # some process that runs until killed
     if sys.platform == "win32":
         cmd = ['cmd','/k','imdisplay','foobar.gif']
                 
         p = process_start(cmd)
         pids=process_instances_get('imdisplay.exe')
         self.assertEquals(len(pids),1)
     
         process_kill(p)
         sleep(1)
         pids=process_instances_get('imdisplay.exe')
         self.assertEquals(len(pids),0)
 def test_(self):
     cmd = ["dir",__file__] 
     p = process_start(cmd)
     self.assertEqual(path.basename(process_get_stdout(p).rstrip()),
                      path.basename(__file__))