def help_paragraphs(self): print_help(help_text.PARAGRAPHS)
def help_generators(self): print_help(help_text.GENERATORS)
def help_tokens(self): print_help(help_text.TOKENS)
def help_dump(self): print_help(help_text.DUMP)
def help_exit(self): print_help(help_text.EXIT)
def help_load(self): print_help(help_text.LOAD)
def help_train(self): print_help(help_text.TRAIN)
def help_continue(self): print_help(help_text.CONTINUE)
def help_sentences(self): print_help(help_text.SENTENCES)
def main(argv): """Print a book! Arguments: -h --help -- show usage -l --list -- list all jobs -c --calibrate -- calibrate the plotter -n --new -- start a new job -r --resume {job} -- resume a job""" job = None try: opts, args = getopt.getopt( argv[1:], "hlcn:r:", ["help", "list", "calibrate", "new=", "resume="]) if not opts: raise getopt.GetoptError('No arguments given') except getopt.GetoptError: helpers.print_help() sys.exit(2) for opt, arg in opts: if opt in ('-h', '--help'): helpers.print_help() sys.exit() elif opt in ('-l', '--list'): print('todo') sys.exit() elif opt in ('-c', '--calibrate'): if (os.path.isfile(config.CALIBRATION_PATH)): os.rename( config.CALIBRATION_PATH, config.CALIBRATION_PATH[:-4] + '_' + time.strftime('%Y%m%d_%H%M%S') + '.txt') printer = Printer() printer.init() sys.exit() elif opt in ("-n", "--new"): name = arg if (os.path.isfile('jobs/' + name + '.conf')): i = raw_input("Job already exists. Overwrite [Y/N]? ") if i.lower() != 'y': sys.exit() helpers.print_modes() mode = raw_input("Job mode: ") lang = raw_input("Job language (nld/eng): ") printer = Printer() printer.safe = True printer.init() job = Job(name, Job.get_processor(mode), lang) page = Page(printer.capture(), printer.getOcr(), job.get_language()) properties = job.init(page) with open('jobs/' + name + '.conf', 'wb') as f: pickle.dump(properties, f, pickle.HIGHEST_PROTOCOL) break elif opt in ("-r", "--resume"): if (os.path.isfile('jobs/' + arg + '.conf')): with open('jobs/' + arg + '.conf', 'rb') as f: p = pickle.load(f) printer = Printer() printer.safe = True printer.init() job = Job(p['name'], Job.get_processor(p['processor']), p['lang']) job.processor.set_properties(p['processor_properties']) else: helpers.print_fail("Job does not exist.") sys.exit() break if config.DEBUGGING: gui = Gui() while True: page = Page(printer.capture(), printer.getOcr(), job.get_language()) instructions = job.process(page) if config.DEBUGGING: gui.setOriginal(page.getImageOriginal()) gui.setProcessed(page.getImageProcessed()) gui.plotList(instructions) else: printer.go((0, 250)) printer.plotList(instructions) printer.home() i = raw_input( "Please turn the page and press ENTER to continue or Q to quit... " ) if i == 'q': break sys.exit()