#NEWLINE# def normalize_network_threshold( threshold ) : #NEWLINE# #INDENT# unit = 'Bytes' #NEWLINE# if ( threshold is None ) : #NEWLINE# #INDENT# return [ ] #NEWLINE# #UNINDENT# if isinstance ( threshold , int ) : #NEWLINE# #INDENT# return [ str ( threshold ) , unit ] #NEWLINE# #UNINDENT# amount = 1024 #NEWLINE# shortcuts = { #NEWLINE# #INDENT# 'B' : 'Bytes' , #NEWLINE# 'KB' : 'Kilobytes' , #NEWLINE# 'MB' : 'Megabytes' , #NEWLINE# 'GB' : 'Gigabytes' , #NEWLINE# 'TB' : 'Terabytes' , #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# amount = int ( threshold ) #NEWLINE# return [ threshold , unit ] #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# if ( ' ' in threshold ) : #NEWLINE# #INDENT# ( amount , unit ) = threshold . split ( ) #NEWLINE# if ( unit in threshold ) : #NEWLINE# #INDENT# unit = shortcuts [ unit ] #NEWLINE# #UNINDENT# allowed_units = shortcuts . values ( ) #NEWLINE# if ( unit not in allowed_units ) : #NEWLINE# #INDENT# raise click . UsageError ( 'Network threshold unit must be one of {}' . format ( list ( allowed_units ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise click . UsageError ( 'Unknown network threshold "{}". Use something like "20 GB".' . format ( threshold ) ) #NEWLINE# #UNINDENT# #UNINDENT# return [ amount , unit ]