Source code for irfpy.vexop.itlfile

''' Module corresponding the command itl file.

Only reading and parsing and processing is supported.
No writing and generating itl file is not supported.
'''
import os
import logging

from . import itlparser

[docs]class ItlFile: def __init__(self, filename, parse=True): ''' ''' self.parsed = False self.filename = filename self.logger = logging.getLogger(self.__class__.__name__) # self.logger.setLevel(logging.DEBUG) if parse: self.parse_file()
[docs] def parse_file(self): with open(self.filename) as fp: self.lines = itlparser.itl_split_line(fp) self.parsed = True
[docs] def get_commandlines(self, commandlist=None): ''' Return the sequence of command. # Load a sample >>> itl = os.path.join(os.path.dirname(__file__), 'sample', 'AS_CP0211___1486_1492__A_VS0PI1.itl') >>> itlf = ItlFile(itl) # You can load all the command line. >>> allcmd = itlf.get_commandlines() >>> print(len(allcmd)) 226 # You can select the command line. >>> partcmd = itlf.get_commandlines(commandlist=['AASF001A', 'AASF003A', 'AASF009A']) >>> print(len(partcmd)) 6 ''' if commandlist is None: return self.lines[0:] else: cmds = [] for cmdline in self.lines: try: cmd = itlparser.get_command(cmdline) except ValueError: continue if cmd in commandlist: cmds.append(cmdline) return cmds
import unittest,doctest
[docs]def doctests(): return unittest.TestSuite(( doctest.DocTestSuite(), ))
if __name__=='__main__': unittest.main(defaultTest='doctests')