diff --git a/tdf b/tdf index ddd7e5d8bf335befa5df3ae316ec0fc9eff5fe10..73117e3f135cf7f495773c3345727a8f90fa9bcf 100755 --- a/tdf +++ b/tdf @@ -8,97 +8,82 @@ import pprint CSV_HEADER='Taiga Mount,Allocation(TB),Used(KB),BlockSoft(KB),BlockHard(KB),BlockGrace,Files,FilesSoft,FilesHard,FilesGrace' -HOST='141.142.224.24' -HOST='taiga-exp01' +HOST='taiga-exp01.ncsa.illinois.edu' PORT=5555 +options = {} +options = { 'human' : False, + 'csv' : False, + 'header' : True, + } + TERABYTE = 1024 ** 4 GIGABYTE = 1024 ** 3 +MEGABYTE = 1024 ** 2 -print_header = True -PRINTED_HEADER = False - -def parse_options( argv ): - """ - This function handles the parsing of the command line arguments. - - Args: - argv: A list of command line arguments, passed in from sys.argv - - Returns - options: A dictionary of the command line option settings - args : A list of files - - """ - - import argparse - import textwrap - parser = argparse.ArgumentParser( - formatter_class = argparse.RawTextHelpFormatter, - prog = 'tdf', - description = textwrap.dedent('''\ - tdf - Taiga DF - - This utility will display your Taiga disk usage in df like format. +#/taiga/ncsa/cavl,164926744166400,106442209432,161061273600,161061273600,-,20488513,90000000,90000000,- - '''), +def print_the_header(): + print("%-30s %8s %8s %7s %8s %4s %12s" % ( 'Taiga Export', 'Alloc(T)', 'Quota(T)', 'Used(T)', 'Avail(T)', 'Use%', 'Files' )) - epilog = textwrap.dedent('''\ +def print_raw_header(): + print("%-30s %16s %13s %13s %13s %4s %12s" % ( 'Taiga Export', 'Alloc(kbytes)', 'Quota(kbytes)', 'Used(kbytes)', 'Avail(kbytes)', 'Use%', 'Files' )) - Usage Examples: +def print_raw( ara ): + if options['header']: + print_raw_header() + options['header'] = False - > tdf + alloc = int(ara[1]) * GIGABYTE + avail = int(ara[3]) - int(ara[2]) + upct = 100 - ( ( int(ara[3]) - int(ara[2]) ) * 100 ) / int(ara[3]) + print("%-30s %16s %13s %13s %13s %3.0f%1s %12s" % ( ara[0], str(alloc), ara[3], ara[2], avail, upct, '%', str(ara[6]) )) - Chad Kerner - ckerner@illinois.edu - Senior Storage Engineer, Storage Enabling Technologies - National Center for Supercomputing Applications - University of Illinois, Urbana-Champaign''') - ) +def print_human_readable( ara ): + if options['header']: + print_the_header() + options['header'] = False - parser.add_argument( "-H", "--human", - dest = "human", - default = False, - action = 'store_true', - help = "Display the output in human readable form. Default: %(default)s") + bused = int(ara[2]) / GIGABYTE + bquota = int(ara[3]) / GIGABYTE + avail = bquota - bused + upct = 100 - ( ( bquota - bused ) * 100 ) / bquota - parser.add_argument( "--csv", - dest = "csv", - default = False, - action = 'store_true', - help = "Display the output in CSV format with no headers. Default: %(default)s") + print("%-30s %8s %9.1f %7.1f %8.1f %3.0f%1s %12s" % ( ara[0], ara[1], bquota, bused, avail, upct, '%', str(ara[6]) )) - parser.add_argument( "--debug", - dest = "debug", - default = False, - action = 'store_true', - help = "Execute in debug mode. This is pretty verbose. Default: %(default)s") - options, args = parser.parse_known_args( argv ) +def print_help(): + my_help = """ - if options.csv: - print_header = False + Usage: tdf [ --human | --csv ] --debug --help - return ( options, args ) + This utility will print out the usage information for your mapped Taiga exports: -#/taiga/ncsa/cavl,164926744166400,106442209432,161061273600,161061273600,-,20488513,90000000,90000000,- + > ./tdf -h + Taiga Export Alloc(T) Quota(T) Used(T) Avail(T) Use% Files + /taiga/ncsa/cavl 150 150.0 103.5 46.5 69% 22931759 -def print_the_header(): - print("%-30s %8s %8s %7s %8s %4s" % ( 'Taiga Export', 'Alloc(T)', 'Quota(T)', 'Used(T)', 'Avail(T)', 'Use%' )) + > ./tdf --csv + /taiga/ncsa/cavl,150,111116403012,161061273600,161061273600,-,22931759,90000000,90000000,- -def print_human_readable( ara ): - if print_header: - print_the_header() - bused = int(ara[2]) / GIGABYTE - bquota = int(ara[3]) / GIGABYTE - avail = bquota - bused - upct = 100 - ( ( bquota - bused ) * 100 ) / bquota + """ + print("%s" % ( my_help ) ) - print("%-30s %8s %9.1f %7.1f %8.1f %3.0f%1s" % ( ara[0], ara[1], bquota, bused, avail, upct, '%' )) if __name__ == '__main__': - ( options, args ) = parse_options( sys.argv[1:] ) - + for opt in sys.argv[1:]: + if opt == '-h': + options['human'] = True + elif opt == '--csv': + options['csv'] = True + elif opt == '--debug': + options['debug'] = True + elif opt == '--help': + print_help() + sys.exit(1) + + # Establish the connection and receive the data with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((HOST, PORT)) data = s.recv(4096) @@ -107,12 +92,9 @@ if __name__ == '__main__': lined = line.decode() array = lined.split(',') - if options.human: + if options['human']: print_human_readable( array ) - elif options.csv: + elif options['csv']: print(lined) else: - print('raw') - - - + print_raw( array )