Beispiel #1
0
    def handleStatus(self, pab, devname):
        logger.info("Opcode 9 Status - %s", devname)
        logPab(pab)
        statbyte = 0
        localPath = tinames.devnameToLocal(devname)
        if not os.path.exists(localPath):
            # TODO? Should we pass to other controllers here?
            if devname.startswith(("TIPI.", "DSK0.")):
                statbyte |= STNOFILE
            else:
                self.sendErrorCode(EDEVERR)
                return
        else:
            open_file = self.openFiles[localPath]
            if open_file != None:
                statbyte = open_file.getStatusByte()
            else:
                if ti_files.isTiFile(localPath):
                    fh = open(localPath, "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(localPath)

        self.tipi_io.send([SUCCESS])
        self.tipi_io.send([statbyte])
Beispiel #2
0
    def handleLoad(self, pab, devname):
        logger.info("Opcode 5 LOAD - %s", devname)
        logPab(pab)
        maxsize = recordNumber(pab)
        unix_name = tinames.devnameToLocal(devname)
        if not os.path.exists(unix_name):
            logger.info("Passing to other controllers")
            self.sendErrorCode(EDVNAME)
            return
        try:
            if (not ti_files.isTiFile(unix_name)
                ) and unix_name.lower().endswith(basicSuffixes):
                prog_file = BasicFile.load(unix_name)
            else:
                prog_file = ProgramImageFile.load(unix_name)

            filesize = prog_file.getImageSize()
            bytes = prog_file.getImage()
            if filesize > maxsize:
                logger.debug(
                    "TI buffer too small, only loading %d of %d bytes",
                    maxsize, filesize)
                bytes = bytes[:maxsize]

            self.sendSuccess()
            logger.info("LOAD image size %d", filesize)
            self.tipi_io.send(bytes)

        except Exception as e:
            # I don't think this will work. we need to check for as
            #   many errors as possible up front.
            self.sendErrorCode(EFILERR)
            logger.exception("failed to load file - %s", devname)
Beispiel #3
0
    def load(self, pab, devname):
        logger.info("load devname - %s", devname)
        try:
            tmpname = '/tmp/CF'
            url = self.parseDev(devname)
            cmd = "wget -O {} {}".format(tmpname, url)
            logger.info("cmd: %s", cmd)
            code = os.system(cmd)
            if code != 0:
                raise Exception("error downloading resource")
            if (not ti_files.isTiFile(tmpname)
                ) and devname.lower().endswith(basicSuffixes):
                prog_file = BasicFile.load(tmpname)
            else:
                prog_file = ProgramImageFile.load(tmpname)

            filesize = prog_file.getImageSize()
            bytes = prog_file.getImage()
            maxsize = recordNumber(pab)
            if filesize > maxsize:
                logger.debug(
                    "TI buffer too small, only loading %d of %d bytes",
                    maxsize, filesize)
                bytes = bytes[:maxsize]

            self.tipi_io.send([SUCCESS])
            logger.info("LOAD image size %d", filesize)
            self.tipi_io.send(bytes)

        except Exception:
            # I don't think this will work. we need to check for as
            #   many errors as possible up front.
            self.tipi_io.send([EFILERR])
            logger.exception("failed to load file - %s", devname)
Beispiel #4
0
 def fetch(self, url, pab):
     tmpname = '/tmp/CF'
     cmd = "wget -O {} {}".format(tmpname, url)
     logger.info("cmd: %s", cmd)
     code = os.system(cmd)
     if code != 0:
         raise Exception("error downloading resource")
     if ti_files.isTiFile(tmpname):
         if recordType(pab) == FIXED:
             return FixedRecordFile.load(tmpname, pab)
         else:
             return VariableRecordFile.load(tmpname, pab)
     else:
         return NativeFile.load(tmpname, pab, url)
Beispiel #5
0
    def handleLoad(self, pab, devname):
        logger.info("Opcode 5 LOAD - %s", devname)
        logPab(pab)
        maxsize = recordNumber(pab)
        unix_name = tinames.devnameToLocal(devname)

        if unix_name is None or not os.path.exists(unix_name):
            logger.info("Passing to other controllers")
            self.sendErrorCode(EDVNAME)
            return
        try:
            oled.info("LOAD:/%s", devname)
            if (not ti_files.isTiFile(unix_name)) and unix_name.lower().endswith(basicSuffixes):
                prog_file = BasicFile.load(unix_name)
            else:
                prog_file = ProgramImageFile.load(unix_name)

            filesize = prog_file.getImageSize()
            bytes = prog_file.getImage()
            if filesize > maxsize:
                logger.debug("TI buffer too small, only loading %d of %d bytes", maxsize, filesize)
                bytes = bytes[:maxsize]

            dirname = os.path.dirname(unix_name)
            if tipi_config.get("AUTO") == "on":
                tipidirname = tinames.local2tipi(dirname)
                logger.debug("tmp mapping DSK1 to %s", tipidirname)
                tipi_config.settmp("DSK1_DIR", tipidirname)
            else:
                logger.debug("AUTO mapping not enabled")

            tipifile = os.path.join(dirname, "TIPI")
            if os.path.isfile(tipifile):
                config_records = load_internal(tipifile)
                tipi_config.applyrecords(config_records)

            self.sendSuccess()
            logger.info("LOAD image size %d", filesize)
            self.tipi_io.send(bytes)

        except Exception as e:
            # I don't think this will work. we need to check for as
            #   many errors as possible up front.
            self.sendErrorCode(EFILERR)
            logger.exception("failed to load file - %s", devname)
Beispiel #6
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)

        oled.info("STATUS %d:/%s", statbyte, devname)

        self.tipi_io.send([SUCCESS])
        self.tipi_io.send([statbyte])
Beispiel #7
0
    def handleOpen(self, pab, devname):
        logger.debug("Opcode 0 Open - %s", devname)
        logPab(pab)
        localPath = tinames.devnameToLocal(devname)
        logger.debug("  local file: " + localPath)
        if mode(pab) == INPUT and not os.path.exists(localPath):
            logger.info("Passing to other controllers")
            self.sendErrorCode(EDVNAME)
            return

        if os.path.isdir(localPath):
            try:
                self.sendSuccess()
                cat_file = CatalogFile.load(localPath, pab)
                self.tipi_io.send([cat_file.getRecordLength()])
                self.openFiles[localPath] = cat_file
                return
            except Exception as e:
                self.sendErrorCode(EOPATTR)
                logger.exception("failed to open dir - %s", devname)
                return

        if os.path.exists(localPath):
            try:
                open_file = None
                if ti_files.isTiFile(localPath):
                    if recordType(pab) == FIXED:
                        open_file = FixedRecordFile.load(localPath, pab)
                    else:
                        open_file = VariableRecordFile.load(localPath, pab)
                else:
                    open_file = NativeFile.load(localPath, pab)

                fillInRecordLen = open_file.getRecordLength()

                self.sendSuccess()
                self.tipi_io.send([fillInRecordLen])
                self.openFiles[localPath] = open_file
                return

            except Exception as e:
                self.sendErrorCode(EOPATTR)
                logger.exception("failed to open file - %s", devname)
                return

        else:
            if self.parentExists(localPath):
                if recordType(pab) == VARIABLE:
                    open_file = VariableRecordFile.create(
                        devname, localPath, pab)
                else:
                    open_file = FixedRecordFile.create(devname, localPath, pab)
                self.openFiles[localPath] = open_file
                self.sendSuccess()
                self.tipi_io.send([open_file.getRecordLength()])
                return
            else:
                # EDEVERR triggers passing on the pab request to other controllers.
                self.sendErrorCode(EDEVERR)
                return

        self.sendErrorCode(EFILERR)