<s> """<STR_LIT>""" <EOL> import sys <EOL> import imp <EOL> from os . path import dirname , join , abspath , exists <EOL> from optparse import OptionParser <EOL> BIN_DIR = dirname ( abspath ( __file__ ) ) <EOL> ROOT_DIR = dirname ( BIN_DIR ) <EOL> CONF_DIR = join ( ROOT_DIR , '<STR_LIT>' ) <EOL> default_relayrules = join ( CONF_DIR , '<STR_LIT>' ) <EOL> LIB_DIR = join ( ROOT_DIR , '<STR_LIT>' ) <EOL> sys . path . insert ( <NUM_LIT:0> , LIB_DIR ) <EOL> try : <EOL> from twisted . internet import epollreactor <EOL> epollreactor . install ( ) <EOL> except ImportError : <EOL> pass <EOL> from twisted . internet import stdio , reactor , defer <EOL> from twisted . protocols . basic import LineReceiver <EOL> from carbon . routers import ConsistentHashingRouter , RelayRulesRouter <EOL> from carbon . client import CarbonClientManager <EOL> from carbon import log , events <EOL> option_parser = OptionParser ( usage = "<STR_LIT>" ) <EOL> option_parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = "<STR_LIT>" ) <EOL> option_parser . add_option ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> option_parser . add_option ( '<STR_LIT>' , type = '<STR_LIT:int>' , default = <NUM_LIT:1> , help = '<STR_LIT>' ) <EOL> option_parser . add_option ( '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> option_parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = "<STR_LIT>" ) <EOL> option_parser . add_option ( '<STR_LIT>' , default = default_relayrules , <EOL> help = '<STR_LIT>' ) <EOL> options , args = option_parser . parse_args ( ) <EOL> if not args : <EOL> print '<STR_LIT>' <EOL> option_parser . print_usage ( ) <EOL> raise SystemExit ( <NUM_LIT:1> ) <EOL> if options . routing not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> raise SystemExit ( <NUM_LIT:1> ) <EOL> destinations = [ ] <EOL> for arg in args : <EOL> parts = arg . split ( '<STR_LIT::>' , <NUM_LIT:2> ) <EOL> host = parts [ <NUM_LIT:0> ] <EOL> port = int ( parts [ <NUM_LIT:1> ] ) <EOL> if len ( parts ) > <NUM_LIT:2> : <EOL> instance = parts [ <NUM_LIT:2> ] <EOL> else : <EOL> instance = None <EOL> destinations . append ( ( host , port , instance ) ) <EOL> if options . debug : <EOL> log . logToStdout ( ) <EOL> log . setDebugEnabled ( True ) <EOL> defer . setDebugging ( True ) <EOL> if options . routing == '<STR_LIT>' : <EOL> router = ConsistentHashingRouter ( options . replication , diverse_replicas = options . diverse_replicas ) <EOL> elif options . routing == '<STR_LIT>' : <EOL> if exists ( options . relayrules ) : <EOL> router = RelayRulesRouter ( options . relayrules ) <EOL> else : <EOL> print "<STR_LIT>" % options . relayrules <EOL> raise SystemExit ( <NUM_LIT:1> ) <EOL> client_manager = CarbonClientManager ( router ) <EOL> reactor . callWhenRunning ( client_manager . startService ) <EOL> if options . keyfunc : <EOL> router . setKeyFunctionFromModule ( options . keyfunc ) <EOL> firstConnectAttempts = [ client_manager . startClient ( dest ) for dest in destinations ] <EOL> firstConnectsAttempted = defer . DeferredList ( firstConnectAttempts ) <EOL> class StdinMetricsReader ( LineReceiver ) : <EOL> delimiter = '<STR_LIT:\n>' <EOL> def lineReceived ( self , line ) : <EOL> try : <EOL> ( metric , value , timestamp ) = line . split ( ) <EOL> datapoint = ( float ( timestamp ) , float ( value ) ) <EOL> assert datapoint [ <NUM_LIT:1> ] == datapoint [ <NUM_LIT:1> ] <EOL> client_manager . sendDatapoint ( metric , datapoint ) <EOL> except ValueError : <EOL> log . err ( None , '<STR_LIT>' % line ) <EOL> def connectionLost ( self , reason ) : <EOL> log . msg ( '<STR_LIT>' ) <EOL> def startShutdown ( results ) : <EOL> log . msg ( "<STR_LIT>" % str ( results ) ) <EOL> allStopped = client_manager . stopAllClients ( ) <EOL> allStopped . addCallback ( shutdown ) <EOL> firstConnectsAttempted . addCallback ( startShutdown ) <EOL> stdio . StandardIO ( StdinMetricsReader ( ) ) <EOL> exitCode = <NUM_LIT:0> <EOL> def shutdown ( results ) : <EOL> global exitCode <EOL> for success , result in results : <EOL> if not success : <EOL> exitCode = <NUM_LIT:1> <EOL> break <EOL> if reactor . running : <EOL> reactor . stop ( ) <EOL> reactor . run ( ) <EOL> raise SystemExit ( exitCode ) </s>
