Exemplo n.º 1
0
    def load(unix_file_name, pab):
        fh = None
        try:
            fh = open(unix_file_name, "rb")
            fdata = bytearray(fh.read())
            # Check that request matches DISPLAY or INTERNAL of file
            ti_files.validateDataType(fdata, dataType(pab))

            # Check that target file is valid
            if not ti_files.isValid(fdata):
                raise Exception("invalid TIFILE")
            # Check that we are a VARIABLE record file
            logger.debug("flags %d", ti_files.flags(fdata))
            if not ti_files.isVariable(fdata):
                raise Exception("file is FIXED, must be VARIABLE")
            if fileType(pab) == RELATIVE:
                raise Exception(
                    "variable length records are restricted to SEQUENTIAL access"
                )
            return VariableRecordFile(fdata, pab)
        except Exception as e:
            logger.exception("not a valid Variable Record TIFILE %s",
                             unix_file_name)
            return None
        finally:
            if fh != None:
                fh.close()
Exemplo n.º 2
0
def _getFileInfo(name):
    dv80suffixes = (".txt", ".a99", ".b99", ".bas", ".xb", ".tb")
    basicSuffixes = (".b99", ".bas", ".xb", ".tb")
        
    header = None
    
    with open(name,"rb") as fdata:
        header = bytearray(fdata.read())[:128]

    valid = ti_files.isValid(header)

    isprotected = 0
    icon = "native"
    type = "DIS/FIX 128"
    tiname = tinames.asTiShortName(name)
    size = os.stat(name).st_size

    if valid:
        type = ti_files.flagsToString(header) 
        if type != 'PROGRAM':
            type = type + " " + str(ti_files.recordLength(header))
        isprotected = ti_files.isProtected(header)
        icon = 'tifile'
    elif name.lower().endswith(dv80suffixes):
        type = "DIS/VAR 80"
        if name.lower().endswith(basicSuffixes):
            icon = 'basic'

    if type == 'PROGRAM' and ti_files.isTiBasicPrg(name):
        icon = 'basic'
    if type == 'INT/VAR 254' and ti_files.isTiBasicPrg(name):
        icon = 'basic'

    return (name, icon, type, tiname, size, isprotected)
Exemplo n.º 3
0
    def load(unix_file_name, pab):
        fh = None
        try:
            fh = open(unix_file_name, "rb")
            fdata = bytearray(fh.read())
            # Check that request matches DISPLAY or INTERNAL of file
            ti_files.validateDataType(fdata, dataType(pab))

            # Check that target file is valid
            if not ti_files.isValid(fdata):
                raise Exception("invaid TIFILE")
            # Check that we are a FIXED record file
            if ti_files.isVariable(fdata):
                raise Exception("file is variable")
            return FixedRecordFile(fdata, pab)
        except Exception as e:
            logger.error("File does not match PAB type: %s", unix_file_name)
            return None
        finally:
            if fh != None:
                fh.close()
Exemplo n.º 4
0
 def load(self, pab, devname):
     logger.info("load devname - %s", devname)
     try:
         url = self.parseDev(devname)
         buffer = BytesIO()
         c = pycurl.Curl()
         c.setopt(c.URL, url)
         c.setopt(c.WRITEDATA, buffer)
         c.perform()
         c.close()
         body = bytearray(buffer.getvalue())
         if not ti_files.isValid(body) or not ti_files.isProgram(body):
             self.tipi_io.send([EFILERR])
             return
         filesize = ti_files.byteLength(body)
         logger.info("sending program - %d", filesize)
         self.tipi_io.send([SUCCESS])
         self.tipi_io.send((body[128:])[:filesize])
         return
     except BaseException:
         traceback.print_exc()
     self.tipi_io.send([EFILERR])
     return
Exemplo n.º 5
0
 def isValid(self):
     return ti_files.isValid(self.header) and ti_files.isProgram(
         self.header)
Exemplo n.º 6
0
 def getFileBytes(self,localname):
     with open(localname, 'rb') as fh:
         bytes = bytearray(fh.read())
         if ti_files.isValid(bytes):
             return bytes
     return None