def main_to_ascii(): setup_cli_logger(logging.INFO) parser = create_ascii_arg_parser() args = parser.parse_args() if not args.deployments_path: L.error("Please provide a --deployments_path agrument or set the " "GUTILS_DEPLOYMENTS_DIRECTORY environmental variable") sys.exit(parser.print_usage()) wm = WatchManager() mask = IN_MOVED_TO | IN_CLOSE_WRITE wm.add_watch(args.deployments_path, mask, rec=True, auto_add=True) # Convert binary data to ASCII if args.type == 'slocum': processor = Slocum2AsciiProcessor( deployments_path=args.deployments_path) notifier = Notifier(wm, processor, read_freq=10) # Read every 10 seconds # Enable coalescing of events. This merges event types of the same type on the same file # together over the `read_freq` specified in the Notifier. notifier.coalesce_events() try: L.info(f"Watching {args.deployments_path} for new binary files") notifier.loop(daemonize=args.daemonize) except NotifierError: L.exception('Unable to start notifier loop') return 1 L.info("GUTILS binary_to_ascii Exited Successfully") return 0
def main_create(): setup_cli_logger(logging.INFO) parser = create_arg_parser() args = parser.parse_args() filter_args = vars(args) # Remove non-filter args into positional arguments file = filter_args.pop('file') config_path = filter_args.pop('config_path') output_path = filter_args.pop('output_path') subset = filter_args.pop('subset') template = filter_args.pop('template') # Move reader_class to a class reader_class = filter_args.pop('reader_class') if reader_class == 'slocum': reader_class = SlocumReader return create_dataset( file=file, reader_class=reader_class, config_path=config_path, output_path=output_path, subset=subset, template=template, **filter_args )
def main_to_netcdf(): setup_cli_logger(logging.INFO) parser = create_netcdf_arg_parser() args = parser.parse_args() filter_args = vars(args) # Remove non-filter args into positional arguments deployments_path = filter_args.pop('deployments_path') subset = filter_args.pop('subset') daemonize = filter_args.pop('daemonize') template = filter_args.pop('template') profile_id_type = int(filter_args.pop('profile_id_type')) # Move reader_class to a class reader_class = filter_args.pop('reader_class') if reader_class == 'slocum': reader_class = SlocumReader if not deployments_path: L.error("Please provide a --deployments_path argument or set the " "GUTILS_DEPLOYMENTS_DIRECTORY environmental variable") sys.exit(parser.print_usage()) # Add inotify watch wm = WatchManager() mask = IN_MOVED_TO | IN_CLOSE_WRITE wm.add_watch( deployments_path, mask, rec=True, auto_add=True ) # Convert ASCII data to NetCDF using a specific reader class if reader_class == SlocumReader: processor = Slocum2NetcdfProcessor( deployments_path=deployments_path, subset=subset, template=template, profile_id_type=profile_id_type, prefer_file_filters=True, **filter_args ) notifier = Notifier(wm, processor, read_freq=10) # Enable coalescing of events. This merges event types of the same type on the same file # together over the `read_freq` specified in the Notifier. notifier.coalesce_events() try: L.info(f"Watching {deployments_path} for new ascii files") notifier.loop(daemonize=daemonize) except NotifierError: L.exception('Unable to start notifier loop') return 1 L.info("GUTILS ascii_to_netcdf Exited Successfully") return 0
def main_check(): setup_cli_logger(logging.INFO) parser = check_arg_parser() args = parser.parse_args() # Check filenames if args.file is None: raise ValueError('Must specify path to NetCDF file') return check_dataset(args)
def main_to_erddap(): setup_cli_logger(logging.WARNING) parser = create_erddap_arg_parser() args = parser.parse_args() if not args.data_path: L.error("Please provide an --data_path agrument or set the " "GUTILS_NETCDF_DIRECTORY environmental variable") sys.exit(parser.print_usage()) if not args.erddap_content_path: L.error("Please provide an --erddap_content_path agrument or set the " "GUTILS_ERDDAP_CONTENT_PATH environmental variable") sys.exit(parser.print_usage()) wm = WatchManager() mask = IN_MOVED_TO | IN_CLOSE_WRITE wm.add_watch( args.data_path, mask, rec=True, auto_add=True ) processor = Netcdf2ErddapProcessor( outputs_path=args.data_path, erddap_content_path=args.erddap_content_path, erddap_flag_path=args.erddap_flag_path ) notifier = Notifier(wm, processor, read_freq=30) # Read every 30 seconds # Enable coalescing of events. This merges event types of the same type on the same file # together over the `read_freq` specified in the Notifier. notifier.coalesce_events() try: L.info("Watching {}, updating content at {} and flags at {}".format( args.data_path, args.erddap_content_path, args.erddap_flag_path )) notifier.loop(daemonize=args.daemonize) except NotifierError: L.exception('Unable to start notifier loop') return 1 except BaseException as e: L.exception(e) return 1 L.info("GUTILS netcdf_to_erddap Exited Successfully") return 0
def main_to_ftp(): setup_cli_logger(logging.INFO) parser = create_ftp_arg_parser() args = parser.parse_args() if not args.data_path: L.error("Please provide an --data_path agrument or set the " "GUTILS_NETCDF_DIRECTORY environmental variable") sys.exit(parser.print_usage()) if not args.ftp_url: L.error("Please provide an --ftp_url agrument or set the " "GUTILS_FTP_URL environmental variable") sys.exit(parser.print_usage()) wm = WatchManager() mask = IN_MOVED_TO | IN_CLOSE_WRITE wm.add_watch( args.data_path, mask, rec=True, auto_add=True ) processor = Netcdf2FtpProcessor( ftp_url=args.ftp_url, ftp_user=args.ftp_user, ftp_pass=args.ftp_pass, ) notifier = Notifier(wm, processor, read_freq=10) # Read every 10 seconds # Enable coalescing of events. This merges event types of the same type on the same file # together over the `read_freq` specified in the Notifier. notifier.coalesce_events() try: L.info("Watching {} and Uploading to {}".format( args.data_path, args.ftp_url) ) notifier.loop(daemonize=args.daemonize) except NotifierError: L.exception('Unable to start notifier loop') return 1 except BaseException as e: L.exception(e) return 1 L.info("GUTILS netcdf_to_ftp Exited Successfully") return 0