Exemple #1
0
def main(argv):
    p = argparse.ArgumentParser()
    p.add_argument('distroname',
                   help='Name of distro this package is intended for')
    args = p.parse_args()
    print(util.get_git_version(from_file=False),
          args.distroname.replace(' ', ''),
          sep='-')
Exemple #2
0
def main(argv):
    p = argparse.ArgumentParser()
    p.add_argument(
        'distroname',
        help='Name of distro this package is intended for'
    )
    args = p.parse_args()
    print(util.get_git_version(from_file=False),
          args.distroname.replace(' ', ''), sep='-')
Exemple #3
0
def main():
    usage = "%prog [options] <config file>"
    opts = optparse.OptionParser(usage)
    opts.add_option("-i",
                    "--debuginput",
                    dest="debuginput",
                    help="read commands from file instead of from tty port")
    opts.add_option("-I",
                    "--input-tty",
                    dest="inputtty",
                    default='/tmp/printer',
                    help="input tty name (default is /tmp/printer)")
    opts.add_option("-l",
                    "--logfile",
                    dest="logfile",
                    help="write log to file instead of stderr")
    opts.add_option("-v",
                    action="store_true",
                    dest="verbose",
                    help="enable debug messages")
    opts.add_option("-o",
                    "--debugoutput",
                    dest="debugoutput",
                    help="write output to file instead of to serial port")
    opts.add_option("-d",
                    "--dictionary",
                    dest="dictionary",
                    type="string",
                    action="callback",
                    callback=arg_dictionary,
                    help="file to read for mcu protocol dictionary")
    options, args = opts.parse_args()
    if len(args) != 1:
        opts.error("Incorrect number of arguments")
    start_args = {'config_file': args[0], 'start_reason': 'startup'}

    input_fd = bglogger = None

    debuglevel = logging.INFO
    if options.verbose:
        debuglevel = logging.DEBUG
    if options.debuginput:
        start_args['debuginput'] = options.debuginput
        debuginput = open(options.debuginput, 'rb')
        input_fd = debuginput.fileno()
    else:
        input_fd = util.create_pty(options.inputtty)
    if options.debugoutput:
        start_args['debugoutput'] = options.debugoutput
        start_args.update(options.dictionary)
    if options.logfile:
        bglogger = queuelogger.setup_bg_logging(options.logfile, debuglevel)
    else:
        logging.basicConfig(level=debuglevel)
    logging.info("Starting Klippy...")
    start_args['software_version'] = util.get_git_version()
    if bglogger is not None:
        versions = "\n".join([
            "Args: %s" % (sys.argv, ),
            "Git version: %s" % (repr(start_args['software_version']), ),
            "CPU: %s" % (util.get_cpu_info(), ),
            "Python: %s" % (repr(sys.version), )
        ])
        logging.info(versions)
    elif not options.debugoutput:
        logging.warning("No log file specified!"
                        " Severe timing issues may result!")

    # Start Printer() class
    while 1:
        if bglogger is not None:
            bglogger.clear_rollover_info()
            bglogger.set_rollover_info('versions', versions)
        printer = Printer(input_fd, bglogger, start_args)
        res = printer.run()
        if res in ['exit', 'error_exit']:
            break
        time.sleep(1.)
        logging.info("Restarting printer")
        start_args['start_reason'] = res

    if bglogger is not None:
        bglogger.stop()

    if res == 'error_exit':
        sys.exit(-1)
Exemple #4
0
def main():
    usage = "%prog [options] <config file>"
    opts = optparse.OptionParser(usage)
    opts.add_option("-o", "--debugoutput", dest="outputfile",
                    help="write output to file instead of to serial port")
    opts.add_option("-i", "--debuginput", dest="inputfile",
                    help="read commands from file instead of from tty port")
    opts.add_option("-I", "--input-tty", dest="inputtty", default='/tmp/printer',
                    help="input tty name (default is /tmp/printer)")
    opts.add_option("-l", "--logfile", dest="logfile",
                    help="write log to file instead of stderr")
    opts.add_option("-v", action="store_true", dest="verbose",
                    help="enable debug messages")
    opts.add_option("-d", dest="read_dictionary",
                    help="file to read for mcu protocol dictionary")
    options, args = opts.parse_args()
    if len(args) != 1:
        opts.error("Incorrect number of arguments")
    conffile = args[0]

    input_fd = debuginput = debugoutput = bglogger = None

    debuglevel = logging.INFO
    if options.verbose:
        debuglevel = logging.DEBUG
    if options.inputfile:
        debuginput = open(options.inputfile, 'rb')
        input_fd = debuginput.fileno()
    else:
        input_fd = util.create_pty(options.inputtty)
    if options.outputfile:
        debugoutput = open(options.outputfile, 'wb')
    if options.logfile:
        bglogger = queuelogger.setup_bg_logging(options.logfile, debuglevel)
    else:
        logging.basicConfig(level=debuglevel)
    logging.info("Starting Klippy...")
    software_version = util.get_git_version()
    if bglogger is not None:
        lines = ["Args: %s" % (sys.argv,),
                 "Git version: %s" % (repr(software_version),),
                 "CPU: %s" % (util.get_cpu_info(),),
                 "Python: %s" % (repr(sys.version),)]
        lines = "\n".join(lines)
        logging.info(lines)
        bglogger.set_rollover_info('versions', lines)

    # Start firmware
    res = 'startup'
    while 1:
        is_fileinput = debuginput is not None
        printer = Printer(
            conffile, input_fd, res, is_fileinput, software_version, bglogger)
        if debugoutput:
            proto_dict = read_dictionary(options.read_dictionary)
            printer.set_fileoutput(debugoutput, proto_dict)
        res = printer.run()
        if res == 'restart':
            printer.disconnect()
            time.sleep(1.)
            logging.info("Restarting printer")
            continue
        elif res == 'firmware_restart':
            printer.firmware_restart()
            time.sleep(1.)
            logging.info("Restarting printer")
            continue
        elif res == 'exit_eof':
            printer.disconnect()
        break

    if bglogger is not None:
        bglogger.stop()
Exemple #5
0
def main():
    usage = "%prog [options] <config file>"
    opts = optparse.OptionParser(usage)
    opts.add_option("-i", "--debuginput", dest="debuginput",
                    help="read commands from file instead of from tty port")
    opts.add_option("-I", "--input-tty", dest="inputtty",
                    default='/tmp/printer',
                    help="input tty name (default is /tmp/printer)")
    opts.add_option("-l", "--logfile", dest="logfile",
                    help="write log to file instead of stderr")
    opts.add_option("-v", action="store_true", dest="verbose",
                    help="enable debug messages")
    opts.add_option("-o", "--debugoutput", dest="debugoutput",
                    help="write output to file instead of to serial port")
    opts.add_option("-d", "--dictionary", dest="dictionary", type="string",
                    action="callback", callback=arg_dictionary,
                    help="file to read for mcu protocol dictionary")
    options, args = opts.parse_args()
    if len(args) != 1:
        opts.error("Incorrect number of arguments")
    start_args = {'config_file': args[0], 'start_reason': 'startup'}

    input_fd = bglogger = None

    debuglevel = logging.INFO
    if options.verbose:
        debuglevel = logging.DEBUG
    if options.debuginput:
        start_args['debuginput'] = options.debuginput
        debuginput = open(options.debuginput, 'rb')
        input_fd = debuginput.fileno()
    else:
        input_fd = util.create_pty(options.inputtty)
    if options.debugoutput:
        start_args['debugoutput'] = options.debugoutput
        start_args.update(options.dictionary)
    if options.logfile:
        bglogger = queuelogger.setup_bg_logging(options.logfile, debuglevel)
    else:
        logging.basicConfig(level=debuglevel)
    logging.info("Starting Klippy...")
    start_args['software_version'] = util.get_git_version()
    if bglogger is not None:
        versions = "\n".join([
            "Args: %s" % (sys.argv,),
            "Git version: %s" % (repr(start_args['software_version']),),
            "CPU: %s" % (util.get_cpu_info(),),
            "Python: %s" % (repr(sys.version),)])
        logging.info(versions)

    # Start Printer() class
    while 1:
        if bglogger is not None:
            bglogger.clear_rollover_info()
            bglogger.set_rollover_info('versions', versions)
        printer = Printer(input_fd, bglogger, start_args)
        res = printer.run()
        if res in ['exit', 'error_exit']:
            break
        time.sleep(1.)
        logging.info("Restarting printer")
        start_args['start_reason'] = res

    if bglogger is not None:
        bglogger.stop()

    if res == 'error_exit':
        sys.exit(-1)
Exemple #6
0
def main():
    "Klippy app main()."
    input_fd = None
    # parse command line options
    parser = argparse.ArgumentParser()
    # verbose
    parser.add_argument("-v",
                        "--verbose",
                        dest="verbose",
                        action='store_true',
                        default=False,
                        help="enable debug messages")
    # config_file
    parser.add_argument(
        "-c",
        "--config-file",
        dest="config_file",
        default='printer.cfg',
        help="configuration file name (default is printer.cfg)")
    # input_tty
    parser.add_argument("-i",
                        "--input-tty",
                        dest="input_tty",
                        default='/tmp/printer',
                        help="input tty name (default is /tmp/printer)")
    # log_dir
    parser.add_argument("-l",
                        "--log-dir",
                        dest="log_dir",
                        default='log',
                        help="log directory (default is 'log')")
    # dictionary
    parser.add_argument("-d",
                        "--dictionary",
                        dest="dict_file",
                        default=None,
                        help="file to read for mcu protocol dictionary")
    # input_debug
    parser.add_argument("-I",
                        "--input-debug",
                        dest="input_debug",
                        default=None,
                        help="read commands from file instead of tty port")
    # output_debug
    parser.add_argument("-O",
                        "--output-debug",
                        dest="output_debug",
                        default=None,
                        help="write output to file instead of tty port")
    # log_stderr
    parser.add_argument("-L",
                        "--log-stderr",
                        dest="log_stderr",
                        action='store_true',
                        default=False,
                        help="write log to stderr instead of log file")
    # console
    parser.add_argument(
        "-C",
        "--console",
        dest="console",
        action='store_true',
        default=False,
        help="spawn a printer interactive console, implies '-l'")
    # single core -> single process (ie: use old reactor)
    parser.add_argument(
        "-S",
        "--single",
        dest="single",
        action='store_true',
        default=False,
        help="force single process, ie: use old greenlet-based reactor")
    args = parser.parse_args()
    args.start_reason = 'startup'
    args.software_version = util.get_git_version()
    # setup log
    console_level = None
    file_level = 'info'
    if args.verbose:
        file_level = 'debug'
    if args.log_stderr:
        console_level = file_level
        file_level = None
    ps_log = processlog.Writer("log")
    ps_log.setup(log_queue, console_level, file_level, args.log_dir)
    # setup host I/O process (files and printer tty)
    ps_fd = processfd.FdProcess("fd")
    if args.dict_file:
        args.dictionary = None
        # TODO read dict_file and fill args.dictionary
        #def arg_dictionary(option, opt_str, value, parser):
        #    key, fname = "dictionary", value
        #    if '=' in value:
        #        mcu_name, fname = value.split('=', 1)
        #        key = "dictionary_" + mcu_name
        #    if args.dictionary is None:
        #        args.dictionary = {}
        #    args.dictionary[key] = fname
    if args.input_debug and args.output_debug:
        args.input_fd = args.output_fd = ps_fd.open(args.input_debug)
    elif args.input_debug:
        args.input_fd = ps_fd.open(args.input_debug)
        args.output_fd = ps_fd.open(args.input_tty, mode="w", tty=True)
    elif args.output_debug:
        args.input_fd = ps_fd.open(args.input_tty, mode="r", tty=True)
        args.output_fd = ps_fd.open(args.input_debug)
    else:
        args.input_fd = args.output_fd = ps_fd.open(args.input_tty,
                                                    mode="r+",
                                                    tty=True)
    # setup reactor (timers and callbacks)
    ps_reactor = reactor.make("reactor", args.single, args.verbose)
    # setup console
    if args.console:
        args.console = multiprocessing.Lock()
    # services ready, let's start...
    logger.info("--------------------")
    logger.info("* Starting Klippy...")
    if ps_log is not None:
        versions = "\n".join([
            "Args: %s" % (sys.argv, ),
            "Git version: %s" % (repr(args.software_version), ),
            "CPU: %s" % (util.get_cpu_info(), ),
            "Python: %s" % (repr(sys.version), )
        ])
        ps_log.rollover_clear_info()
        ps_log.rollover_set_info('versions', versions)
        for l in [line for line in versions.split('\n')]:
            logger.info(l)
    elif not args.output_debug:
        logger.warning(
            "No log file specified! Severe timing issues may result!")
    # start printer.Master() class,
    myprinter = printer.Master("printer", args, ecodes)
    # open, read, parse, validate cfg file, build printer tree
    need_config = myprinter.setup()
    # printer restart/reload/exit loop
    while 1:
        # config reload: new hal, new reactor, new tree, new ... printer
        if need_config:
            need_config = myprinter.setup()
        # reactor go!
        exit_reason = myprinter.run()
        # evaluate exit reason (result)
        if exit_reason in ['exit', 'error']:
            # exit from klippy
            if exit_reason == 'exit':
                logger.info("* Klippy clean exit.")
            elif exit_reason == 'error':
                logger.info("* Klippy exited with error.")
            break
        elif exit_reason == 'restart':
            # restart without changing configuration
            logger.info("Klippy restarting using the same conf.")
        elif exit_reason == 'reload':
            # reload configuration and restart
            need_config = True
            logger.info("Klippy restarting using a fresh conf.")
        else:
            # unknown result
            logger.warning("Unknown exit code (%s). Given reason: '%s'",
                           exit_code, exit_reason)
            break
        #
        args.start_reason = myprinter.cleanup(exit_reason)
        time.sleep(1.)
        # log rollover
        if ps_log is not None:
            #ps_log.rollover_do()
            pass
    # graceful stop
    for w in reversed(workers.keys()):
        worker_stop(w)
    # open all the loops
    process.running.clear()
    # try again, stronger
    for w in reversed(workers.values()):
        if w.is_alive():
            w.terminate()
            w.join()
            # python > 3.7
            #w.close()
    # return exit_code to os shell
    sys.exit(ecodes.index(exit_reason))