Example #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])
Example #2
0
 def fetch(self, url, pab):
     tmpname = self.http_get(url, pab)
     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)
Example #3
0
    def status(self, pab, devname):
        logger.info("status devname - %s", devname)
        statbyte = 0

        try:
            open_file = self.files[devname]
            statbyte = open_file.getStatusByte()
        except KeyError:
            statbyte = NativeFile.status("", devname)

# not really implemented yet
        self.tipi_io.send([SUCCESS])
        self.tipi_io.send([statbyte])
Example #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)
Example #5
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])
Example #6
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)
Example #7
0
    def handleOpen(self, pab, devname):
        logger.info("Opcode 0 Open - %s", devname)
        logPab(pab)
        unix_name = tinames.devnameToLocal(devname)
        if unix_name is None:
            logger.info("(1) Passing to other controllers")
            self.sendErrorCode(EDVNAME)
            return

        logger.debug("  local file: " + unix_name)
        if mode(pab) == INPUT and not os.path.exists(unix_name):
            logger.info("(2) Passing to other controllers")
            self.sendErrorCode(EDVNAME)
            return

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

        if os.path.exists(unix_name):
            try:
                if ti_files.isTiFile(unix_name):
                    # check protect flag
                    if mode(pab) != INPUT:
                        fh = open(unix_name, "rb")
                        header = bytearray(fh.read())[:128]
                        if ti_files.isProtected(header):
                            self.sendErrorCode(EWPROT)
                            return

                    if recordType(pab) == FIXED:
                        open_file = FixedRecordFile.load(unix_name, pab)
                    else:
                        open_file = VariableRecordFile.load(unix_name, pab)
                else:
                    open_file = NativeFile.load(unix_name, pab)

                if open_file is None:
                    self.sendErrorCode(EOPATTR)
                    return

                fillInRecordLen = open_file.getRecordLength()

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

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

        else:
            if self.parentExists(unix_name):
                if recordType(pab) == VARIABLE:
                    open_file = VariableRecordFile.create(
                        devname, unix_name, pab)
                else:
                    open_file = FixedRecordFile.create(devname, unix_name, pab)
                self.openFiles[unix_name] = 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(EDVNAME)
                return

        self.sendErrorCode(EFILERR)