def main(): usage_string = \ 'Usage: morpho_tagger.py ' \ '--input <input path> ' \ '--output <output path> [options]' parser = configure_option_parser(usage_string) (options, args) = parser.parse_args() config.generate_config(options) if not options.input or not options.output: parser.print_help() exit(0) inpath = os.path.abspath(options.input) outpath = os.path.abspath(options.output) retcode = 0 jobs_number = config.CONFIG['jobs_number'] if os.path.isdir(inpath): fs_walk.process_directory(inpath, outpath, task_list.add_task) else: task_list.add_task(inpath, outpath) if 1 < jobs_number: worker_pool =\ multiprocessing.Pool(processes=jobs_number, initializer=initialize_lemmers, initargs=[options]) return_codes = task_list.execute_tasks(convert, worker_pool) retcode = sum([1 if code is not None else 0 for code in return_codes]) else: initialize_lemmers(options) retcode = True for paths_pair in task_list.TASKS: retcode &= convert(paths_pair) is not None return retcode
def main(): usage_string = 'Usage: tokenizer.py --input <input path> --output <output path>' parser = optparse.OptionParser(usage=usage_string) parser.add_option('--input', dest='input', help='input path - directory or file') parser.add_option('--output', dest='output', help='output path - directory or file') parser.add_option('--output_encoding', dest='out_encoding', help='encoding of the output files', default='cp1251') parser.add_option('--jobs', dest='jobs_number', help='concurrent jobs number', default='1') (options, args) = parser.parse_args() config.generate_config(options) if not options.input or not options.output: parser.print_help() exit(0) inpath = os.path.abspath(options.input) outpath = os.path.abspath(options.output) if os.path.isdir(inpath): print 'Collecting tasks...' fs_walk.process_directory(inpath, outpath, task_list.add_task) print 'Starting processing...' child_retcodes = task_list.execute_tasks(convert_and_log) retcode = sum([1 if code != 0 else 0 for code in child_retcodes]) else: retcode = convert_and_log((inpath, outpath)) return retcode
def main(): usage_string = 'Usage: tokenizer.py --input <input path> --output <output path>' parser = optparse.OptionParser(usage=usage_string) parser.add_option('--input', dest='input', help='input path - directory or file') parser.add_option('--output', dest='output', help='output path - directory or file') parser.add_option('--output_encoding', dest='out_encoding', help='encoding of the output files', default='cp1251') parser.add_option('--jobs', dest='jobs_number', help='concurrent jobs number', default=1, type='int') (options, args) = parser.parse_args() config.generate_config(options) if not options.input or not options.output: parser.print_help() exit(0) inpath = os.path.abspath(options.input) outpath = os.path.abspath(options.output) if os.path.isdir(inpath): print 'Collecting tasks...' fs_walk.process_directory(inpath, outpath, task_list.add_task) else: task_list.TASKS.append(inpath, outpath) jobs_number = config.CONFIG['jobs_number'] print 'Starting processing...' if 1 < jobs_number: child_retcodes = task_list.execute_tasks(convert_and_log) retcode = sum([1 if code != 0 else 0 for code in child_retcodes]) else: retcode = True for paths_pair in task_list.TASKS: retcode &= convert_and_log(paths_pair) return retcode
def main(): usage_string = 'Usage: annotate_texts.py --input <input path> --output <output path> [options]' parser = morpho_tagger.configure_option_parser(usage_string) (options, args) = parser.parse_args() config.generate_config(options) if not options.input or not options.output: parser.print_help() exit(0) inpath = os.path.abspath(options.input) outpath = os.path.abspath(options.output) morpho_tagger.initialize_lemmers(options) retcode = 0 if os.path.isdir(inpath): fs_walk.process_directory(inpath, outpath, task_list.add_task) return_codes = task_list.execute_tasks(convert) retcode = sum([1 if code is not None else 0 for code in return_codes]) else: retcode = convert((inpath, outpath)) is not None return retcode
def main(): """ Main function that has the actual loop. :return: Nothing. """ if not os.path.isfile(os.path.join(SCRIPT_LOCATION, "screens.json")): generate_config() LOGGER.info( "Config not found. New one has been generated. Please look and modify the config before running again." ) exit(0) init_conf = parse_config() # Set the scene to the beginning scene. current_scene = init_conf["start_scene"] current_active = None write_scene_to_file(current_scene) # Notify ready for execution. LOGGER.info("Setup is done. Starting daemon...") while True: # Sleep the delay time to not overuse the CPU. time.sleep(init_conf["delay_time"] / 1000) data = check_new_scene() if not data: # App is unknown. Switch to the "unknown_app" scene. new_scene = init_conf["unknown_app_scene"] if new_scene: current_scene = new_scene write_scene_to_file(current_scene) continue # Don't change the current scene if it's the same. new_scene, active_app = data if new_scene == current_scene: # Log once if the focus changed but the app leads to the same scene. if active_app != current_active: LOGGER.info( "Focused screen changed to known definition: {}. Not changing scene as it is the same." .format(active_app)) current_active = active_app continue # Known app requested a stay of the current scene. elif not new_scene: # Log it ONCE. if active_app != current_active: LOGGER.info( "Focused window changed to known app: {}. Requested stay of scene." .format(active_app)) current_active = active_app continue # Log the change in scene. LOGGER.info( "Focused window changed to known app: {}. Changing scene to {}.". format(active_app, new_scene)) # Write the scene to the scene.txt write_scene_to_file(new_scene) current_scene = new_scene current_active = active_app