Beispiel #1
0
 def getStatusByte(self):
     statByte = STVARIABLE
     if ti_files.isInternal(self.header):
         statByte |= STINTERNAL
     if self.currentRecord >= len(self.records):
         statByte |= STLEOF
     return statByte
Beispiel #2
0
def basicContents(filename):
    logger.debug("fetching BASIC PROGRAM as ascii in %s", filename)
    # We are assuming the test for FIAD isTiFile has already passed.

    prg_tmp_file = '/tmp/' + str(uuid.uuid4()) + '.tmp'
    bas_tmp_file = '/tmp/' + str(uuid.uuid4()) + '.tmp'

    try:
        # strip the FIAD header off to get the raw file xbas99 needs.
        with open(filename, "rb") as tifile:
            with open(prg_tmp_file, "wb") as program:
                bytes = bytearray(tifile.read())
                if ti_files.isProgram(bytes):
                    program.write(bytes[128:])
                elif ti_files.isVariable(bytes) and ti_files.isInternal(
                        bytes) and ti_files.recordLength(bytes) == 254:
                    i = 128
                    limit = len(bytes)
                    while (i < limit):
                        rlen = bytes[i]
                        next = i + rlen + 1
                        program.write(bytes[i:next])
                        i = next
                        if bytes[i] == 0xff:
                            # skip to next 256 byte boundary
                            i = (256 * (((i - 128) / 256) + 1)) + 128
                else:
                    return False

        call([
            '/home/tipi/xdt99/xbas99.py', '-d', prg_tmp_file, '-o',
            bas_tmp_file
        ])

        if ti_files.isTiBasicAscii(bas_tmp_file):
            with open(bas_tmp_file, 'rb') as content_file:
                return content_file.read().decode("latin_1")

    finally:
        if os.path.exists(prg_tmp_file):
            os.unlink(prg_tmp_file)
        if os.path.exists(bas_tmp_file):
            os.unlink(bas_tmp_file)

    return False
Beispiel #3
0
    def handleStatus(self, pab, devname):
        logger.info("Opcode 9 Status - %s", devname)
        logPab(pab)
        statbyte = 0

        unix_name = tinames.devnameToLocal(devname)
        if unix_name is None:
            self.sendErrorCode(EDVNAME)
            return

        if not os.path.exists(unix_name):
            statbyte |= STNOFILE
        else:
            if not os.path.isdir(unix_name):
                open_file = None
                try:
                    open_file = self.openFiles[unix_name]
                except:
                    pass
                if open_file is not None:
                    statbyte = open_file.getStatusByte()
                else:
                    if ti_files.isTiFile(unix_name):
                        fh = open(unix_name, "rb")
                        header = bytearray(fh.read())[:128]
                        if ti_files.isVariable(header):
                            statbyte |= STVARIABLE
                        if ti_files.isProgram(header):
                            statbyte |= STPROGRAM
                        if ti_files.isInternal(header):
                            statbyte |= STINTERNAL
                    else:
                        statbyte = NativeFile.status(unix_name)

        self.tipi_io.send([SUCCESS])
        self.tipi_io.send([statbyte])