コード例 #1
0
ファイル: proctools.py プロジェクト: bharathi26/pycopia
 def waitpid(self, pid, option=0):
     try:
         proc = self._procs[pid]
     except KeyError:
         logging.warning("Wait on unmanaged process (pid: %s)." % pid)
         cmdline = ProcStat(pid).cmdline
         pid, sts = os.waitpid(pid, option)
         return ExitStatus(cmdline, sts)
     return self.waitproc(proc)
コード例 #2
0
 def waitpid(self, pid, option=0):
     try:
         proc = self._procs[pid]
     except KeyError:
         logging.warning("Wait on unmanaged process (pid: %s)." % pid)
         cmdline = ProcStat(pid).cmdline
         pid, sts = os.waitpid(pid, option)
         return ExitStatus(cmdline, sts)
     return self.waitproc(proc)
コード例 #3
0
 def _suboption(self):
     subopt = self.sbdataq
     self.sbdataq = ''
     if len(subopt) != 3:
         logging.error("Bad suboption recieved: {!r}".format(subopt))
         return
     if subopt[0] == COM_PORT_OPTION:
         comopt = subopt[1]
         if comopt == RESP_NOTIFY_LINESTATE:
             value = subopt[2]
             self._linestate = LineState(subopt[2])
         elif comopt == RESP_NOTIFY_MODEMSTATE:
             self._modemstate = ModemState(subopt[2])
         elif comopt == RESP_FLOWCONTROL_SUSPEND:
             self._suspended = True
             logging.warning("Telnet: requested to suspend tx.")
         elif comopt == RESP_FLOWCONTROL_RESUME:
             self._suspended = False
             logging.warning("Telnet: requested to resume tx.")
         else:
             logging.warning("Telnet: unhandled COM opton: {}".format(
                 repr(subopt)))
     else:
         logging.warning("Telnet: unhandled subnegotion: {}".format(
             repr(subopt)))
コード例 #4
0
    def _process_rawq(self):
        buf = ['', '']  # data buffer and SB buffer
        try:
            while self._rawq:
                c = self._rawq_getchar()
                if not self.iacseq:
                    if c == NULL:
                        continue
                    if c == "\021":
                        continue
                    if c != IAC:
                        buf[self.sb] += c
                        continue
                    else:
                        self.iacseq += c
                elif len(self.iacseq) == 1:
                    if c in (DO, DONT, WILL, WONT):
                        self.iacseq += c
                        continue

                    self.iacseq = ''
                    if c == IAC:
                        buf[self.sb] += c
                    else:
                        if c == SB:  # SB ... SE start.
                            self.sb = 1
                            self.sbdataq = ''
                        elif c == SE:
                            self.sb = 0
                            self.sbdataq += buf[1]
                            buf[1] = ''
                            self._suboption()
                        else:
                            logging.warning(
                                'Telnet: IAC {!r} not recognized'.format(c))
                elif len(self.iacseq) == 2:
                    cmd = self.iacseq[1]
                    self.iacseq = ''
                    if cmd in (DO, DONT, WILL, WONT):
                        self._neg_option(cmd, c)
                    else:
                        logging.error("telnet bad command: {!r}".format(cmd))
        except EOFError:
            self.iacseq = ''  # Reset on EOF
            self.sb = 0
        self._q += buf[0]
        self.sbdataq += buf[1]
コード例 #5
0
ファイル: telnet.py プロジェクト: ktosiu/pycopia
    def _process_rawq(self):
        buf = ['', ''] # data buffer and SB buffer
        try:
            while self._rawq:
                c = self._rawq_getchar()
                if not self.iacseq:
                    if c == NULL:
                        continue
                    if c == "\021":
                        continue
                    if c != IAC:
                        buf[self.sb] += c
                        continue
                    else:
                        self.iacseq += c
                elif len(self.iacseq) == 1:
                    if c in (DO, DONT, WILL, WONT):
                        self.iacseq += c
                        continue

                    self.iacseq = ''
                    if c == IAC:
                        buf[self.sb] += c
                    else:
                        if c == SB: # SB ... SE start.
                            self.sb = 1
                            self.sbdataq = ''
                        elif c == SE:
                            self.sb = 0
                            self.sbdataq += buf[1]
                            buf[1] = ''
                            self._suboption()
                        else:
                            logging.warning('Telnet: IAC {!r} not recognized'.format(c))
                elif len(self.iacseq) == 2:
                    cmd = self.iacseq[1]
                    self.iacseq = ''
                    if cmd in (DO, DONT, WILL, WONT):
                        self._neg_option(cmd, c)
                    else:
                        logging.error("telnet bad command: {!r}".format(cmd))
        except EOFError:
            self.iacseq = '' # Reset on EOF
            self.sb = 0
        self._q += buf[0]
        self.sbdataq += buf[1]
コード例 #6
0
ファイル: config.py プロジェクト: bharathi26/pycopia
 def _build_report(self, name):
     from pycopia import reports # XXX pycopia-QA circular dependency.
     if name is None:
         name = self.get("reportname", "default")
     if "," in name:
         params = []
         for n in name.split(","):
             rptparams = self.reports.get(n, None)
             if rptparams is None:
                 logging.warning("Reportname %r not found." % (n,))
                 continue
             params.append(rptparams)
     else:
         params = self.reports.get(name, None)
     if not params:
         raise reports.ReportFindError("Report %r not found." % (name,))
     if type(params) is list:
         params = map(self.expand_params, params)
     else:
         params = self.expand_params(params)
     return reports.get_report(params)
コード例 #7
0
ファイル: config.py プロジェクト: wildone/pycopia
 def _build_report(self, name):
     from pycopia import reports  # XXX pycopia-QA circular dependency.
     if name is None:
         name = self.get("reportname", "default")
     if "," in name:
         params = []
         for n in name.split(","):
             rptparams = self.reports.get(n, None)
             if rptparams is None:
                 logging.warning("Reportname %r not found." % (n, ))
                 continue
             params.append(rptparams)
     else:
         params = self.reports.get(name, None)
     if not params:
         raise reports.ReportFindError("Report %r not found." % (name, ))
     if type(params) is list:
         params = map(self.expand_params, params)
     else:
         params = self.expand_params(params)
     return reports.get_report(params)
コード例 #8
0
ファイル: testloader.py プロジェクト: bharathi26/pycopia
def get_suite(dbsuite, config):
    """Get a Suite object.

    Return the implementation class of a TestSuite, or a generic Suite
    instance if not defined.
    """
    name = dbsuite.name
    if " " in name:
        name = identifier(name)
    impl = dbsuite.suiteimplementation
    if impl:
        try:
            obj = module.get_object(impl)
        except module.ObjectImportError:
            logging.warning("Did not find suite implementation %r." % (impl,))
        else:
            if type(obj) is type and issubclass(obj, core.TestSuite):
                return obj(config, name=name)
            else:
                raise InvalidObjectError("%r is not a TestSuite class object." % (obj,))
    return core.TestSuite(config, name=name)
コード例 #9
0
ファイル: testloader.py プロジェクト: wildone/pycopia
def get_suite(dbsuite, config):
    """Get a Suite object.

    Return the implementation class of a TestSuite, or a generic Suite
    instance if not defined.
    """
    name = dbsuite.name
    if " " in name:
        name = identifier(name)
    impl = dbsuite.suiteimplementation
    if impl:
        try:
            obj = module.get_object(impl)
        except module.ObjectImportError:
            logging.warning("Did not find suite implementation %r." % (impl, ))
        else:
            if type(obj) is type and issubclass(obj, core.TestSuite):
                return obj(config, name=name)
            else:
                raise InvalidObjectError(
                    "%r is not a TestSuite class object." % (obj, ))
    return core.TestSuite(config, name=name)
コード例 #10
0
ファイル: telnet.py プロジェクト: ktosiu/pycopia
 def _suboption(self):
     subopt = self.sbdataq
     self.sbdataq = ''
     if len(subopt) != 3:
         logging.error("Bad suboption recieved: {!r}".format(subopt))
         return
     if subopt[0] == COM_PORT_OPTION:
         comopt = subopt[1]
         if comopt == RESP_NOTIFY_LINESTATE:
             value = subopt[2]
             self._linestate = LineState(subopt[2])
         elif comopt == RESP_NOTIFY_MODEMSTATE:
             self._modemstate = ModemState(subopt[2])
         elif comopt == RESP_FLOWCONTROL_SUSPEND:
             self._suspended = True
             logging.warning("Telnet: requested to suspend tx.")
         elif comopt == RESP_FLOWCONTROL_RESUME:
             self._suspended = False
             logging.warning("Telnet: requested to resume tx.")
         else:
             logging.warning("Telnet: unhandled COM opton: {}".format(repr(subopt)))
     else:
         logging.warning("Telnet: unhandled subnegotion: {}".format(repr(subopt)))
コード例 #11
0
    def send(self, stream, retry=16, timeout=60, quiet=0):
        '''
        Send a stream via the XMODEM protocol.

            >>> stream = file('/etc/issue', 'rb')
            >>> print modem.send(stream)
            True

        Returns ``True`` upon succesful transmission or ``False`` in case of
        failure.
        '''

        # initialize protocol
        error_count = 0
        crc_mode = 0
        cancel = 0
        while True:
            char = self.getc(1)
            if char:
                if char == NAK:
                    crc_mode = 0
                    break
                elif char == CRC:
                    crc_mode = 1
                    break
                elif char == CAN:
                    if not quiet:
                        print >> sys.stderr, 'received CAN'
                    if cancel:
                        return False
                    else:
                        cancel = 1
                else:
                    logging.error('send ERROR expected NAK/CRC, got %s' %
                                  (ord(char), ))

            error_count += 1
            if error_count >= retry:
                self.abort(timeout=timeout)
                return False

        # send data
        error_count = 0
        packet_size = 128
        sequence = 1
        while True:
            data = stream.read(packet_size)
            if not data:
                # end of stream
                break

            data = data.ljust(packet_size, '\xff')
            if crc_mode:
                crc = self.calc_crc(data)
            else:
                crc = self.calc_checksum(data)

            # emit packet
            while True:
                self.putc(SOH)
                self.putc(chr(sequence))
                self.putc(chr(0xff - sequence))
                self.putc(data)
                if crc_mode:
                    self.putc(chr(crc >> 8))
                    self.putc(chr(crc & 0xff))
                else:
                    self.putc(chr(crc))

                char = self.getc(1, timeout)
                if char == ACK:
                    break
                if char == NAK:
                    error_count += 1
                    if error_count >= retry:
                        # excessive amounts of retransmissions requested,
                        # abort transfer
                        self.abort(timeout=timeout)
                        logging.warning('excessive NAKs, transfer aborted')
                        return False

                    # return to loop and resend
                    continue

                # protocol error
                self.abort(timeout=timeout)
                logging.error('xmodem protocol error')
                return False

            # keep track of sequence
            sequence = (sequence + 1) % 0x100

        # end of transmission
        self.putc(EOT)
        return True
コード例 #12
0
 def error_handler(self):
     logging.warning("Telnet: unhandled error")
コード例 #13
0
 def hangup_handler(self):
     logging.warning("Telnet: unhandled hangup event")
コード例 #14
0
 def pri_handler(self):
     logging.warning("Telnet: unhandled pri event")
コード例 #15
0
 def read_handler(self):
     data = self._read(16384)
     logging.warning("unhandled read from process")
コード例 #16
0
ファイル: telnet.py プロジェクト: ktosiu/pycopia
 def error_handler(self):
     logging.warning("Telnet: unhandled error")
コード例 #17
0
ファイル: telnet.py プロジェクト: ktosiu/pycopia
 def hangup_handler(self):
     logging.warning("Telnet: unhandled hangup event")
コード例 #18
0
ファイル: telnet.py プロジェクト: ktosiu/pycopia
 def pri_handler(self):
     logging.warning("Telnet: unhandled pri event")
コード例 #19
0
ファイル: xmodem.py プロジェクト: bharathi26/pycopia
    def send(self, stream, retry=16, timeout=60, quiet=0):
        '''
        Send a stream via the XMODEM protocol.

            >>> stream = file('/etc/issue', 'rb')
            >>> print modem.send(stream)
            True

        Returns ``True`` upon succesful transmission or ``False`` in case of
        failure.
        '''

        # initialize protocol
        error_count = 0
        crc_mode = 0
        cancel = 0
        while True:
            char = self.getc(1)
            if char:
                if char == NAK:
                    crc_mode = 0
                    break
                elif char == CRC:
                    crc_mode = 1
                    break
                elif char == CAN:
                    if not quiet:
                        print >> sys.stderr, 'received CAN'
                    if cancel:
                        return False
                    else:
                        cancel = 1
                else:
                    logging.error('send ERROR expected NAK/CRC, got %s' % (ord(char),))

            error_count += 1
            if error_count >= retry:
                self.abort(timeout=timeout)
                return False

        # send data
        error_count = 0
        packet_size = 128
        sequence = 1
        while True:
            data = stream.read(packet_size)
            if not data:
                # end of stream
                break

            data = data.ljust(packet_size, '\xff')
            if crc_mode:
                crc = self.calc_crc(data)
            else:
                crc = self.calc_checksum(data)

            # emit packet
            while True:
                self.putc(SOH)
                self.putc(chr(sequence))
                self.putc(chr(0xff - sequence))
                self.putc(data)
                if crc_mode:
                    self.putc(chr(crc >> 8))
                    self.putc(chr(crc & 0xff))
                else:
                    self.putc(chr(crc))

                char = self.getc(1, timeout)
                if char == ACK:
                    break
                if char == NAK:
                    error_count += 1
                    if error_count >= retry:
                        # excessive amounts of retransmissions requested,
                        # abort transfer
                        self.abort(timeout=timeout)
                        logging.warning('excessive NAKs, transfer aborted')
                        return False

                    # return to loop and resend
                    continue

                # protocol error
                self.abort(timeout=timeout)
                logging.error('xmodem protocol error')
                return False

            # keep track of sequence
            sequence = (sequence + 1) % 0x100

        # end of transmission
        self.putc(EOT)
        return True
コード例 #20
0
ファイル: proctools.py プロジェクト: kdart/pycopia3
 def read_handler(self):
     data = self._read(16384)
     logging.warning("unhandled read from process")