Пример #1
0
 def setClipboardData(data):
     my_logger.debug('  %s: setClipboardData data = "%s"' % (sys.platform, data))
     p = Popen(['/usr/bin/xsel', '-t', '200', '-i'], stdin=PIPE)
     result = p.communicate(input=data.encode('utf-8'))
     p.wait(2)
     my_logger.debug('  %s: setClipboardData done' % sys.platform)
     return result
Пример #2
0
 def getClipboardData():  # xclip needs iso-8859-1 for ver < 0.11 #failed
     my_logger.debug('  %s: getClipboardData' % sys.platform)
     p = Popen(['/usr/bin/xsel', '-t', '200', '-o'], stdout=PIPE)
     p.wait(2)
     result = p.communicate()[0].decode('utf-8')
     my_logger.debug('  %s: gotClipboardData "%s"' % (sys.platform, result))
     return result
Пример #3
0
 def getClipboardData(): # xclip needs iso-8859-1 for ver < 0.11 #failed
     my_logger.debug('  %s: getClipboardData' % sys.platform)
     p = Popen(['/usr/bin/xsel', '-t', '200', '-o'], stdout=PIPE)
     p.wait(2)
     result = p.communicate()[0].decode('utf-8')
     my_logger.debug('  %s: gotClipboardData "%s"' % (sys.platform, result))
     return result
Пример #4
0
 def setClipboardData(data):
     my_logger.debug('  %s: setClipboardData data = "%s"' %
                     (sys.platform, data))
     p = Popen(['/usr/bin/xsel', '-t', '200', '-i'], stdin=PIPE)
     result = p.communicate(input=data.encode('utf-8'))
     p.wait(2)
     my_logger.debug('  %s: setClipboardData done' % sys.platform)
     return result
Пример #5
0
 def test_timeExceeded(self):
     start = time()
     p = Popen(['python', 'dummy.py', '-t', '1', '-l', '2'],
               stdout=PIPE,
               stderr=PIPE)
     retcode = p.wait(1)
     self.assertEquals(retcode, -9)
Пример #6
0
 def run_pipe(self, cmd):
     if self.debug:
         print('cmd: %s' % cmd)
     try:
         p = Popen((cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         output = p.stdout.readlines()
         err = p.stderr.readlines()
         starttime=time()
         exitCode = p.wait(self.testTimeOut) #abort if it takes longer than 60 seconds
         if exitCode < 0 and self.testTimeOut>-1 and time()-starttime>self.testTimeOut:  # process timed out
             return 'timedOut'
         return (output,err,exitCode)
     except KeyboardInterrupt:
         print '\n\nKeyboardInterrupt detected ... killing process'
         p.kill()
         self.killmyself()
    def _run(self):
        '''
        Runs the command in self.cmdlist from self.workingdir with a timer
        bounded by self.runtimeout
        '''
        logger.debug('Running: %s %s', self.cmdlist, self.workingdir)
        process_info = {}
        id = None
        done = False
        started = False
        wmiInterface = None
        # set timeout(s)
        # run program
        if self.hideoutput:
            p = Popen(self.cmdlist, stdout=open(
                os.devnull), stderr=open(os.devnull))
        else:
            p = Popen(self.cmdlist)

        if self.watchcpu == True:
            # Initialize things used for CPU monitoring
            logger.debug('Initializing WMI...')
            wmiInterface = wmi.WMI()
            id = p.pid

        logger.debug('...Timer: %f', self.runtimeout)
        t = Timer(self.runtimeout, kill, args=[p])
        self.t = t
        logger.debug('...timer start')
        t.start()
        if self.watchcpu == True:
            # This is a race.  In some cases, a GUI app could be done before we can even measure it
            # TODO: Do something about it
            while p.poll() is None and not done and id:
                for proc in wmiInterface.Win32_PerfRawData_PerfProc_Process(IDProcess=id):
                    n1, d1 = long(proc.PercentProcessorTime), long(
                        proc.Timestamp_Sys100NS)
                    n0, d0 = process_info.get(id, (0, 0))
                    try:
                        percent_processor_time = (
                            float(n1 - n0) / float(d1 - d0)) * 100.0
                    except ZeroDivisionError:
                        percent_processor_time = 0.0
                    process_info[id] = (n1, d1)
                    logger.debug(
                        'Process %s CPU usage: %s', id, percent_processor_time)
                    if percent_processor_time < 0.0000000001:
                        if started:
                            logger.debug(
                                'killing %s due to CPU inactivity', id)
                            done = True
                            kill(p)
                    else:
                        # Detected CPU usage. Now look for it to drop near zero
                        started = True

                if not done:
                    time.sleep(0.2)
        else:
            p.wait()
        # probably racy
        logger.debug('...timer stop')
        t.cancel()

        self.returncode = ctypes.c_uint(p.returncode).value
        logger.debug(
            '...Returncode: raw=%s cast=%s', p.returncode, self.returncode)
        logger.debug('...Exceptions: %s', self.exceptions)
        if self.returncode in self.exceptions:
            self.saw_crash = True
        logger.debug('...Saw_crash: %s', self.saw_crash)
Пример #8
0
 def test_timeExceeded(self):
     start = time()
     p = Popen(['python', 'dummy.py', '-t', '1', '-l', '2'], stdout=PIPE, stderr=PIPE)
     retcode = p.wait(1)
     self.assertEquals(retcode, -9)
Пример #9
0
    def _run(self):
        '''
        Runs the command in self.cmdlist from self.workingdir with a timer
        bounded by self.runtimeout
        '''
        logger.debug('Running: %s %s', self.cmdlist, self.workingdir)
        process_info = {}
        id = None
        done = False
        started = False
        wmiInterface = None
        # set timeout(s)
        # run program
        if self.hideoutput:
            p = Popen(self.cmdlist,
                      stdout=open(os.devnull),
                      stderr=open(os.devnull))
        else:
            p = Popen(self.cmdlist)

        if self.watchcpu == True:
            # Initialize things used for CPU monitoring
            logger.debug('Initializing WMI...')
            wmiInterface = wmi.WMI()
            id = p.pid

        logger.debug('...Timer: %f', self.runtimeout)
        t = Timer(self.runtimeout, kill, args=[p])
        self.t = t
        logger.debug('...timer start')
        t.start()
        if self.watchcpu == True:
            # This is a race.  In some cases, a GUI app could be done before we can even measure it
            # TODO: Do something about it
            while p.poll() is None and not done and id:
                for proc in wmiInterface.Win32_PerfRawData_PerfProc_Process(
                        IDProcess=id):
                    n1, d1 = long(proc.PercentProcessorTime), long(
                        proc.Timestamp_Sys100NS)
                    n0, d0 = process_info.get(id, (0, 0))
                    try:
                        percent_processor_time = (float(n1 - n0) /
                                                  float(d1 - d0)) * 100.0
                    except ZeroDivisionError:
                        percent_processor_time = 0.0
                    process_info[id] = (n1, d1)
                    logger.debug('Process %s CPU usage: %s', id,
                                 percent_processor_time)
                    if percent_processor_time < 0.0000000001:
                        if started:
                            logger.debug('killing %s due to CPU inactivity',
                                         id)
                            done = True
                            kill(p)
                    else:
                        # Detected CPU usage. Now look for it to drop near zero
                        started = True

                if not done:
                    time.sleep(0.2)
        else:
            p.wait()
        # probably racy
        logger.debug('...timer stop')
        t.cancel()

        self.returncode = ctypes.c_uint(p.returncode).value
        logger.debug('...Returncode: raw=%s cast=%s', p.returncode,
                     self.returncode)
        logger.debug('...Exceptions: %s', self.exceptions)
        if self.returncode in self.exceptions:
            self.saw_crash = True
        logger.debug('...Saw_crash: %s', self.saw_crash)