Beispiel #1
0
    def OnInit(self):
        """Override `wx.App.OnInit()`."""
        # Read or create the model (table)
        # TODO: Read columns from config file
        logging.config.fileConfig('logging.cfg')

        # Backup the old data file if it exists
        outfile = 'data.csv'
        if os.path.isfile(outfile):
            backup = outfile[:-4] + '.bak'
            if os.path.isfile(backup):
                os.remove(backup)
            os.rename(outfile, backup)

        # Get column headings
        columns = core.get_columns()
        if columns:
            core.write_to_file(outfile, (columns,))
 
        # Set up the serial port reader
        controller = core.DataManager(outfile)
        self.table = Table(columns)
        controller.datacallbacks.append(self.table.data_received)

        self.frame = Frame(None, 'pylibra', self.table, controller)
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True # No errors during init
Beispiel #2
0
def main():
    """Main program entry function.
    
    Parse the command line, process the options and start the parser.
    
    """
    # Make stdout write almost immediately
    sys.stdout = utils.FlushFile(sys.stdout)

    # Parse the command line options
    argsParser = optparse.OptionParser(version=core.__version__)
    argsParser.add_option(
        "-o", "--outfile", dest="outfile", help="output data to outfile (%default)", default="data.csv"
    )
    options = argsParser.parse_args()[0]

    _LOGGER.info("Starting pylibra" + "-" * 30)
    _LOGGER.debug("Options: " + str(options))

    # Backup the old data file if it exists
    if os.path.isfile(options.outfile):
        backup = options.outfile[:-4] + ".bak"
        if os.path.isfile(backup):
            os.remove(backup)
        os.rename(options.outfile, backup)

    # Read the settings file
    app = core.DataManager(options.outfile)
    app.datacallbacks.append(echo)

    columns = core.get_columns()
    if columns:
        core.write_to_file(options.outfile, (columns,))

    # Start the parser
    app.start_parser()

    # Block until quit command is received
    while True:
        command = raw_input("Type q to quit:")
        if command[0] == "q":
            break

    # Stop the parser
    app.stop_parser()
    print "Quitting."
    _LOGGER.info("Exit OK." + "-" * 30)