def parse_cmdline(argv):
 try:
  from collectors.etc import config
  defaults = config.get_defaults()
 except ImportError:
  sys.stderr.write('ImportError: Could not load defaults from configuration. Using hardcoded values')
  default_cdir = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'collectors')
  defaults = {'verbose': False, 'no_tcollector_stats': False, 'evictinterval': 6000, 'dedupinterval': 300, 'deduponlyzero': False, 'allowed_inactivity_time': 600, 'dryrun': False, 'maxtags': 8, 'max_bytes': ((64 * 1024) * 1024), 'http_password': False, 'reconnectinterval': 0, 'http_username': False, 'port': 4242, 'pidfile': '/var/run/tcollector.pid', 'http': False, 'tags': [], 'remove_inactive_collectors': False, 'host': 'localhost', 'backup_count': 1, 'logfile': '/var/log/tcollector.log', 'cdir': default_cdir, 'ssl': False, 'stdin': False, 'daemonize': False, 'hosts': False}
 except:
  sys.stderr.write(('Unexpected error: %s' % sys.exc_info()[0]))
  raise
 parser = OptionParser(description='Manages collectors which gather data and report back.')
 parser.add_option('-c', '--collector-dir', dest='cdir', metavar='DIR', default=defaults['cdir'], help='Directory where the collectors are located.')
 parser.add_option('-d', '--dry-run', dest='dryrun', action='store_true', default=defaults['dryrun'], help="Don't actually send anything to the TSD, just print the datapoints.")
 parser.add_option('-D', '--daemonize', dest='daemonize', action='store_true', default=defaults['daemonize'], help='Run as a background daemon.')
 parser.add_option('-H', '--host', dest='host', metavar='HOST', default=defaults['host'], help='Hostname to use to connect to the TSD.')
 parser.add_option('-L', '--hosts-list', dest='hosts', metavar='HOSTS', default=defaults['hosts'], help="List of host:port to connect to tsd's (comma separated).")
 parser.add_option('--no-tcollector-stats', dest='no_tcollector_stats', action='store_true', default=defaults['no_tcollector_stats'], help='Prevent tcollector from reporting its own stats to TSD')
 parser.add_option('-s', '--stdin', dest='stdin', action='store_true', default=defaults['stdin'], help='Run once, read and dedup data points from stdin.')
 parser.add_option('-p', '--port', dest='port', type='int', default=defaults['port'], metavar='PORT', help='Port to connect to the TSD instance on. default=%default')
 parser.add_option('-v', dest='verbose', action='store_true', default=defaults['verbose'], help='Verbose mode (log debug messages).')
 parser.add_option('-t', '--tag', dest='tags', action='append', default=defaults['tags'], metavar='TAG', help='Tags to append to all timeseries we send, e.g.: -t TAG=VALUE -t TAG2=VALUE')
 parser.add_option('-P', '--pidfile', dest='pidfile', default=defaults['pidfile'], metavar='FILE', help='Write our pidfile')
 parser.add_option('--dedup-interval', dest='dedupinterval', type='int', default=defaults['dedupinterval'], metavar='DEDUPINTERVAL', help='Number of seconds in which successive duplicate datapoints are suppressed before sending to the TSD. Use zero to disable. default=%default')
 parser.add_option('--dedup-only-zero', dest='deduponlyzero', action='store_true', default=defaults['deduponlyzero'], help='Only dedup 0 values.')
 parser.add_option('--evict-interval', dest='evictinterval', type='int', default=defaults['evictinterval'], metavar='EVICTINTERVAL', help='Number of seconds after which to remove cached values of old data points to save memory. default=%default')
 parser.add_option('--allowed-inactivity-time', dest='allowed_inactivity_time', type='int', default=ALLOWED_INACTIVITY_TIME, metavar='ALLOWEDINACTIVITYTIME', help='How long to wait for datapoints before assuming a collector is dead and restart it. default=%default')
 parser.add_option('--remove-inactive-collectors', dest='remove_inactive_collectors', action='store_true', default=defaults['remove_inactive_collectors'], help='Remove collectors not sending data in the max allowed inactivity interval')
 parser.add_option('--max-bytes', dest='max_bytes', type='int', default=defaults['max_bytes'], help='Maximum bytes per a logfile.')
 parser.add_option('--backup-count', dest='backup_count', type='int', default=defaults['backup_count'], help='Maximum number of logfiles to backup.')
 parser.add_option('--logfile', dest='logfile', type='str', default=DEFAULT_LOG, help='Filename where logs are written to.')
 parser.add_option('--reconnect-interval', dest='reconnectinterval', type='int', default=defaults['reconnectinterval'], metavar='RECONNECTINTERVAL', help='Number of seconds after which the connection tothe TSD hostname reconnects itself. This is usefulwhen the hostname is a multiple A record (RRDNS).')
 parser.add_option('--max-tags', dest='maxtags', type=int, default=defaults['maxtags'], help='The maximum number of tags to send to our TSD Instances')
 parser.add_option('--http', dest='http', action='store_true', default=defaults['http'], help='Send the data via the http interface')
 parser.add_option('--http-username', dest='http_username', default=defaults['http_username'], help='Username to use for HTTP Basic Auth when sending the data via HTTP')
 parser.add_option('--http-password', dest='http_password', default=defaults['http_password'], help='Password to use for HTTP Basic Auth when sending the data via HTTP')
 parser.add_option('--ssl', dest='ssl', action='store_true', default=defaults['ssl'], help='Enable SSL - used in conjunction with http')
 (options, args) = parser.parse_args(args=argv[1:])
 if (options.dedupinterval < 0):
  parser.error('--dedup-interval must be at least 0 seconds')
 if (options.evictinterval <= options.dedupinterval):
  parser.error('--evict-interval must be strictly greater than --dedup-interval')
 if (options.reconnectinterval < 0):
  parser.error('--reconnect-interval must be at least 0 seconds')
 if ((options.daemonize or options.max_bytes) and (not options.backup_count)):
  options.backup_count = 1
 return (options, args)

def parse_cmdline ( argv ) : try : from collectors . etc import config defaults = config . get_defaults ( ) except ImportError : sys . stderr . write ( 'ImportError: Could not load defaults from configuration. Using hardcoded values' ) default_cdir = os . path . join ( os . path . dirname ( os . path . realpath ( sys . argv [ 0 ] ) ) , 'collectors' ) defaults = { 'verbose' : False , 'no_tcollector_stats' : False , 'evictinterval' : 6000 , 'dedupinterval' : 300 , 'deduponlyzero' : False , 'allowed_inactivity_time' : 600 , 'dryrun' : False , 'maxtags' : 8 , 'max_bytes' : ( ( 64 * 1024 ) * 1024 ) , 'http_password' : False , 'reconnectinterval' : 0 , 'http_username' : False , 'port' : 4242 , 'pidfile' : '/var/run/tcollector.pid' , 'http' : False , 'tags' : [ ] , 'remove_inactive_collectors' : False , 'host' : 'localhost' , 'backup_count' : 1 , 'logfile' : '/var/log/tcollector.log' , 'cdir' : default_cdir , 'ssl' : False , 'stdin' : False , 'daemonize' : False , 'hosts' : False } except : sys . stderr . write ( ( 'Unexpected error: %s' % sys . exc_info ( ) [ 0 ] ) ) raise parser = OptionParser ( description = 'Manages collectors which gather data and report back.' ) parser . add_option ( '-c' , '--collector-dir' , dest = 'cdir' , metavar = 'DIR' , default = defaults [ 'cdir' ] , help = 'Directory where the collectors are located.' ) parser . add_option ( '-d' , '--dry-run' , dest = 'dryrun' , action = 'store_true' , default = defaults [ 'dryrun' ] , help = "Don't actually send anything to the TSD, just print the datapoints." ) parser . add_option ( '-D' , '--daemonize' , dest = 'daemonize' , action = 'store_true' , default = defaults [ 'daemonize' ] , help = 'Run as a background daemon.' ) parser . add_option ( '-H' , '--host' , dest = 'host' , metavar = 'HOST' , default = defaults [ 'host' ] , help = 'Hostname to use to connect to the TSD.' ) parser . add_option ( '-L' , '--hosts-list' , dest = 'hosts' , metavar = 'HOSTS' , default = defaults [ 'hosts' ] , help = "List of host:port to connect to tsd's (comma separated)." ) parser . add_option ( '--no-tcollector-stats' , dest = 'no_tcollector_stats' , action = 'store_true' , default = defaults [ 'no_tcollector_stats' ] , help = 'Prevent tcollector from reporting its own stats to TSD' ) parser . add_option ( '-s' , '--stdin' , dest = 'stdin' , action = 'store_true' , default = defaults [ 'stdin' ] , help = 'Run once, read and dedup data points from stdin.' ) parser . add_option ( '-p' , '--port' , dest = 'port' , type = 'int' , default = defaults [ 'port' ] , metavar = 'PORT' , help = 'Port to connect to the TSD instance on. default=%default' ) parser . add_option ( '-v' , dest = 'verbose' , action = 'store_true' , default = defaults [ 'verbose' ] , help = 'Verbose mode (log debug messages).' ) parser . add_option ( '-t' , '--tag' , dest = 'tags' , action = 'append' , default = defaults [ 'tags' ] , metavar = 'TAG' , help = 'Tags to append to all timeseries we send, e.g.: -t TAG=VALUE -t TAG2=VALUE' ) parser . add_option ( '-P' , '--pidfile' , dest = 'pidfile' , default = defaults [ 'pidfile' ] , metavar = 'FILE' , help = 'Write our pidfile' ) parser . add_option ( '--dedup-interval' , dest = 'dedupinterval' , type = 'int' , default = defaults [ 'dedupinterval' ] , metavar = 'DEDUPINTERVAL' , help = 'Number of seconds in which successive duplicate datapoints are suppressed before sending to the TSD. Use zero to disable. default=%default' ) parser . add_option ( '--dedup-only-zero' , dest = 'deduponlyzero' , action = 'store_true' , default = defaults [ 'deduponlyzero' ] , help = 'Only dedup 0 values.' ) parser . add_option ( '--evict-interval' , dest = 'evictinterval' , type = 'int' , default = defaults [ 'evictinterval' ] , metavar = 'EVICTINTERVAL' , help = 'Number of seconds after which to remove cached values of old data points to save memory. default=%default' ) parser . add_option ( '--allowed-inactivity-time' , dest = 'allowed_inactivity_time' , type = 'int' , default = ALLOWED_INACTIVITY_TIME , metavar = 'ALLOWEDINACTIVITYTIME' , help = 'How long to wait for datapoints before assuming a collector is dead and restart it. default=%default' ) parser . add_option ( '--remove-inactive-collectors' , dest = 'remove_inactive_collectors' , action = 'store_true' , default = defaults [ 'remove_inactive_collectors' ] , help = 'Remove collectors not sending data in the max allowed inactivity interval' ) parser . add_option ( '--max-bytes' , dest = 'max_bytes' , type = 'int' , default = defaults [ 'max_bytes' ] , help = 'Maximum bytes per a logfile.' ) parser . add_option ( '--backup-count' , dest = 'backup_count' , type = 'int' , default = defaults [ 'backup_count' ] , help = 'Maximum number of logfiles to backup.' ) parser . add_option ( '--logfile' , dest = 'logfile' , type = 'str' , default = DEFAULT_LOG , help = 'Filename where logs are written to.' ) parser . add_option ( '--reconnect-interval' , dest = 'reconnectinterval' , type = 'int' , default = defaults [ 'reconnectinterval' ] , metavar = 'RECONNECTINTERVAL' , help = 'Number of seconds after which the connection tothe TSD hostname reconnects itself. This is usefulwhen the hostname is a multiple A record (RRDNS).' ) parser . add_option ( '--max-tags' , dest = 'maxtags' , type = int , default = defaults [ 'maxtags' ] , help = 'The maximum number of tags to send to our TSD Instances' ) parser . add_option ( '--http' , dest = 'http' , action = 'store_true' , default = defaults [ 'http' ] , help = 'Send the data via the http interface' ) parser . add_option ( '--http-username' , dest = 'http_username' , default = defaults [ 'http_username' ] , help = 'Username to use for HTTP Basic Auth when sending the data via HTTP' ) parser . add_option ( '--http-password' , dest = 'http_password' , default = defaults [ 'http_password' ] , help = 'Password to use for HTTP Basic Auth when sending the data via HTTP' ) parser . add_option ( '--ssl' , dest = 'ssl' , action = 'store_true' , default = defaults [ 'ssl' ] , help = 'Enable SSL - used in conjunction with http' ) ( options , args ) = parser . parse_args ( args = argv [ 1 : ] ) if ( options . dedupinterval < 0 ) : parser . error ( '--dedup-interval must be at least 0 seconds' ) if ( options . evictinterval <= options . dedupinterval ) : parser . error ( '--evict-interval must be strictly greater than --dedup-interval' ) if ( options . reconnectinterval < 0 ) : parser . error ( '--reconnect-interval must be at least 0 seconds' ) if ( ( options . daemonize or options . max_bytes ) and ( not options . backup_count ) ) : options . backup_count = 1 return ( options , args )
parses the command-line .