<s> """<STR_LIT>""" <EOL> import functools <EOL> import getopt <EOL> import pipes <EOL> import subprocess <EOL> import sys <EOL> from humanfriendly import ( <EOL> format_length , <EOL> format_number , <EOL> format_size , <EOL> format_table , <EOL> format_timespan , <EOL> parse_length , <EOL> parse_size , <EOL> Spinner , <EOL> Timer , <EOL> ) <EOL> from humanfriendly . terminal import usage <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> options , arguments = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , '<STR_LIT>' , [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> ] ) <EOL> except getopt . GetoptError as e : <EOL> sys . stderr . write ( "<STR_LIT>" % e ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> actions = [ ] <EOL> delimiter = None <EOL> should_format_table = False <EOL> for option , value in options : <EOL> if option in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> delimiter = value <EOL> elif option == '<STR_LIT>' : <EOL> actions . append ( functools . partial ( print_parsed_size , value ) ) <EOL> elif option == '<STR_LIT>' : <EOL> actions . append ( functools . partial ( print_parsed_length , value ) ) <EOL> elif option in ( '<STR_LIT:-c>' , '<STR_LIT>' ) : <EOL> actions . append ( functools . partial ( run_command , arguments ) ) <EOL> elif option in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> actions . append ( functools . partial ( print_formatted_length , value ) ) <EOL> elif option in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> actions . append ( functools . partial ( print_formatted_number , value ) ) <EOL> elif option in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> actions . append ( functools . partial ( print_formatted_size , value ) ) <EOL> elif option == '<STR_LIT>' : <EOL> should_format_table = True <EOL> elif option in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> actions . append ( functools . partial ( print_formatted_timespan , value ) ) <EOL> elif option in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> usage ( __doc__ ) <EOL> return <EOL> if should_format_table : <EOL> actions . append ( functools . partial ( print_formatted_table , delimiter ) ) <EOL> if not actions : <EOL> usage ( __doc__ ) <EOL> return <EOL> for partial in actions : <EOL> partial ( ) <EOL> def run_command ( command_line ) : <EOL> """<STR_LIT>""" <EOL> timer = Timer ( ) <EOL> spinner_label = "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( map ( pipes . quote , command_line ) ) <EOL> with Spinner ( label = spinner_label , timer = timer ) as spinner : <EOL> process = subprocess . Popen ( command_line ) <EOL> while True : <EOL> spinner . step ( ) <EOL> spinner . sleep ( ) <EOL> if process . poll ( ) is not None : <EOL> break <EOL> sys . exit ( process . returncode ) <EOL> def print_formatted_length ( value ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT:.>' in value : <EOL> print ( format_length ( float ( value ) ) ) <EOL> else : <EOL> print ( format_length ( int ( value ) ) ) <EOL> def print_formatted_number ( value ) : <EOL> """<STR_LIT>""" <EOL> print ( format_number ( float ( value ) ) ) <EOL> def print_formatted_size ( value ) : <EOL> """<STR_LIT>""" <EOL> print ( format_size ( int ( value ) ) ) <EOL> def print_formatted_table ( delimiter ) : <EOL> """<STR_LIT>""" <EOL> data = [ ] <EOL> for line in sys . stdin : <EOL> line = line . rstrip ( ) <EOL> data . append ( line . split ( delimiter ) ) <EOL> print ( format_table ( data ) ) <EOL> def print_formatted_timespan ( value ) : <EOL> """<STR_LIT>""" <EOL> print ( format_timespan ( float ( value ) ) ) <EOL> def print_parsed_length ( value ) : <EOL> """<STR_LIT>""" <EOL> print ( parse_length ( value ) ) <EOL> def print_parsed_size ( value ) : <EOL> """<STR_LIT>""" <EOL> print ( parse_size ( value ) ) </s>
