def main(): """Entry point.""" # arguments parsing first for quicker feedback on invalid arguments args = docopt(__doc__, version=__version__) # set up logging logger = lg.getLogger('hdfs') logger.setLevel(lg.DEBUG) handler = Config().get_file_handler('hdfs') if handler: logger.addHandler(handler) # set up client and fix arguments client = Client.from_alias(args['--alias']) rpath = args['RPATH'] or '.' for option in ('--depth', '--threads'): try: args[option] = int(args[option]) except ValueError: raise HdfsError('Invalid `%s` option: %r.', option, args[option]) # run command if args['--log']: if handler: sys.stdout.write('%s\n' % (handler.baseFilename, )) else: raise HdfsError('No log file active.') elif args['--write']: reader = (line for line in sys.stdin) # doesn't work with stdin, why? client.write(rpath, reader, overwrite=args['--overwrite']) elif args['--read']: size = client.status(rpath)['length'] read(client.read(rpath), size, '%s\t' % (rpath, )) elif args['--download']: client.download( rpath, args['LPATH'], overwrite=args['--overwrite'], n_threads=args['--threads'] ) elif args['--upload']: client.upload( rpath, args['LPATH'], overwrite=args['--overwrite'], n_threads=args['--threads'] ) elif args['--list']: list_infos(client, rpath, args['--depth'], args['--json'], args['--path']) else: banner = ( 'Interactive HDFS python shell.\n' 'Client for %r is available as `CLIENT`.' % (client.url, ) ) namespace = {'CLIENT': client} try: from IPython import embed except ImportError: from code import interact interact(banner=banner, local=namespace) else: embed(banner1=banner, user_ns=namespace)
def main(): """Entry point.""" # arguments parsing first for quicker feedback on invalid arguments args = docopt(__doc__, version=__version__) # set up logging logger = lg.getLogger('hdfs') logger.setLevel(lg.DEBUG) handler = Config().get_file_handler('hdfs') if handler: logger.addHandler(handler) # set up client and fix arguments client = Client.from_alias(args['--alias']) rpath = args['RPATH'] or '.' for option in ('--depth', '--threads'): try: args[option] = int(args[option]) except ValueError: raise HdfsError('Invalid `%s` option: %r.', option, args[option]) # run command if args['--log']: if handler: sys.stdout.write('%s\n' % (handler.baseFilename, )) else: raise HdfsError('No log file active.') elif args['--write']: reader = (line for line in sys.stdin) # doesn't work with stdin, why? client.write(rpath, reader, overwrite=args['--overwrite']) elif args['--read']: size = client.status(rpath)['length'] read(client.read(rpath), size, '%s\t' % (rpath, )) elif args['--download']: client.download(rpath, args['LPATH'], overwrite=args['--overwrite'], n_threads=args['--threads']) elif args['--upload']: client.upload(rpath, args['LPATH'], overwrite=args['--overwrite'], n_threads=args['--threads']) elif args['--list']: list_infos(client, rpath, args['--depth'], args['--json'], args['--path']) else: banner = ('Interactive HDFS python shell.\n' 'Client for %r is available as `CLIENT`.' % (client.url, )) namespace = {'CLIENT': client} try: from IPython import embed except ImportError: from code import interact interact(banner=banner, local=namespace) else: embed(banner1=banner, user_ns=namespace)
def main(): """Entry point.""" # arguments parsing first for quicker feedback on invalid arguments args = docopt(__doc__, version=__version__) # set up logging logger = lg.getLogger('hdfs') logger.setLevel(lg.DEBUG) handler = Config().get_file_handler('hdfs') if handler: logger.addHandler(handler) # set up client and fix arguments client = Client.from_alias(args['--alias']) rpath = args['RPATH'] or '' for option in ('--depth', '--threads'): try: args[option] = int(args[option]) except ValueError: raise HdfsError('Invalid `%s` option: %r.', option, args[option]) # run command if args['--log']: if handler: sys.stdout.write('%s\n' % (handler.baseFilename, )) else: raise HdfsError('No log file active.') elif args['--write']: reader = (line for line in sys.stdin) # doesn't work with stdin, why? client.write(rpath, reader, overwrite=args['--overwrite']) elif args['--read']: size = client.status(rpath)['length'] read(client.read(rpath), size, '%s\t' % (rpath, )) elif args['--download']: client.download( rpath, args['LPATH'], overwrite=args['--overwrite'], n_threads=args['--threads'] ) else: infos(client, rpath, args['--depth'], args['--json'], args['--path'])