#NEWLINE# def parseArguments( ) : #NEWLINE# #INDENT# 'Parse command line arguments and configs from ~/.wakatime.cfg.\n    Command line arguments take precedence over config file settings.\n    Returns instances of ArgumentParser and SafeConfigParser.\n    ' #NEWLINE# parser = argparse . ArgumentParser ( description = 'Common interface for the WakaTime api.' ) #NEWLINE# parser . add_argument ( '--entity' , dest = 'entity' , metavar = 'FILE' , action = FileAction , help = ( 'absolute path to file for the heartbeat; can also be a ' + 'url, domain, or app when --entity-type is not file' ) ) #NEWLINE# parser . add_argument ( '--file' , dest = 'file' , action = FileAction , help = argparse . SUPPRESS ) #NEWLINE# parser . add_argument ( '--key' , dest = 'key' , help = ( 'your wakatime api key; uses api_key from ' + '~/.wakatime.cfg by default' ) ) #NEWLINE# parser . add_argument ( '--write' , dest = 'is_write' , action = 'store_true' , help = ( 'when set, tells api this heartbeat was triggered from ' + 'writing to a file' ) ) #NEWLINE# parser . add_argument ( '--plugin' , dest = 'plugin' , help = ( 'optional text editor plugin name and version ' + 'for User-Agent header' ) ) #NEWLINE# parser . add_argument ( '--time' , dest = 'timestamp' , metavar = 'time' , type = float , help = ( 'optional floating-point unix epoch timestamp; ' + 'uses current time by default' ) ) #NEWLINE# parser . add_argument ( '--lineno' , dest = 'lineno' , help = 'optional line number; current line being edited' ) #NEWLINE# parser . add_argument ( '--cursorpos' , dest = 'cursorpos' , help = 'optional cursor position in the current file' ) #NEWLINE# parser . add_argument ( '--entity-type' , dest = 'entity_type' , help = ( 'entity type for this heartbeat. can be one of "file", ' + '"domain", or "app"; defaults to file.' ) ) #NEWLINE# parser . add_argument ( '--proxy' , dest = 'proxy' , help = ( 'optional https proxy url; for example: ' + 'https://user:pass@localhost:8080' ) ) #NEWLINE# parser . add_argument ( '--project' , dest = 'project' , help = 'optional project name' ) #NEWLINE# parser . add_argument ( '--alternate-project' , dest = 'alternate_project' , help = ( 'optional alternate project name; auto-discovered project ' + 'takes priority' ) ) #NEWLINE# parser . add_argument ( '--alternate-language' , dest = 'alternate_language' , help = ( 'optional alternate language name; auto-detected language' + 'takes priority' ) ) #NEWLINE# parser . add_argument ( '--hostname' , dest = 'hostname' , help = ( 'hostname of ' + 'current machine.' ) ) #NEWLINE# parser . add_argument ( '--disableoffline' , dest = 'offline' , action = 'store_false' , help = 'disables offline time logging instead of queuing logged time' ) #NEWLINE# parser . add_argument ( '--hidefilenames' , dest = 'hidefilenames' , action = 'store_true' , help = 'obfuscate file names; will not send file names to api' ) #NEWLINE# parser . add_argument ( '--exclude' , dest = 'exclude' , action = 'append' , help = ( 'filename patterns to exclude from logging; POSIX regex ' + 'syntax; can be used more than once' ) ) #NEWLINE# parser . add_argument ( '--include' , dest = 'include' , action = 'append' , help = ( ( 'filename patterns to log; when used in combination with ' + '--exclude, files matching include will still be logged; ' ) + 'POSIX regex syntax; can be used more than once' ) ) #NEWLINE# parser . add_argument ( '--ignore' , dest = 'ignore' , action = 'append' , help = argparse . SUPPRESS ) #NEWLINE# parser . add_argument ( '--extra-heartbeats' , dest = 'extra_heartbeats' , action = 'store_true' , help = 'reads extra heartbeats from STDIN as a JSON array until EOF' ) #NEWLINE# parser . add_argument ( '--logfile' , dest = 'logfile' , help = 'defaults to ~/.wakatime.log' ) #NEWLINE# parser . add_argument ( '--apiurl' , dest = 'api_url' , help = 'heartbeats api url; for debugging with a local server' ) #NEWLINE# parser . add_argument ( '--timeout' , dest = 'timeout' , type = int , help = ( 'number of seconds to wait when sending heartbeats to api; ' + 'defaults to 60 seconds' ) ) #NEWLINE# parser . add_argument ( '--config' , dest = 'config' , help = 'defaults to ~/.wakatime.cfg' ) #NEWLINE# parser . add_argument ( '--verbose' , dest = 'verbose' , action = 'store_true' , help = 'turns on debug messages in log file' ) #NEWLINE# parser . add_argument ( '--version' , action = 'version' , version = __version__ ) #NEWLINE# args = parser . parse_args ( ) #NEWLINE# if ( not args . timestamp ) : #NEWLINE# #INDENT# args . timestamp = time . time ( ) #NEWLINE# #UNINDENT# configs = parseConfigFile ( args . config ) #NEWLINE# if ( configs is None ) : #NEWLINE# #INDENT# return ( args , configs ) #NEWLINE# #UNINDENT# if ( not args . key ) : #NEWLINE# #INDENT# default_key = None #NEWLINE# if configs . has_option ( 'settings' , 'api_key' ) : #NEWLINE# #INDENT# default_key = configs . get ( 'settings' , 'api_key' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if configs . has_option ( 'settings' , 'apikey' ) : #NEWLINE# #INDENT# default_key = configs . get ( 'settings' , 'apikey' ) #NEWLINE# #UNINDENT# #UNINDENT# if default_key : #NEWLINE# #INDENT# args . key = default_key #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# parser . error ( 'Missing api key' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not args . entity ) : #NEWLINE# #INDENT# if args . file : #NEWLINE# #INDENT# args . entity = args . file #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# parser . error ( 'argument --entity is required' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not args . exclude ) : #NEWLINE# #INDENT# args . exclude = [ ] #NEWLINE# #UNINDENT# if configs . has_option ( 'settings' , 'ignore' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# for pattern in configs . get ( 'settings' , 'ignore' ) . split ( '\n' ) : #NEWLINE# #INDENT# if ( pattern . strip ( ) != '' ) : #NEWLINE# #INDENT# args . exclude . append ( pattern ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if configs . has_option ( 'settings' , 'exclude' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# for pattern in configs . get ( 'settings' , 'exclude' ) . split ( '\n' ) : #NEWLINE# #INDENT# if ( pattern . strip ( ) != '' ) : #NEWLINE# #INDENT# args . exclude . append ( pattern ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( not args . include ) : #NEWLINE# #INDENT# args . include = [ ] #NEWLINE# #UNINDENT# if configs . has_option ( 'settings' , 'include' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# for pattern in configs . get ( 'settings' , 'include' ) . split ( '\n' ) : #NEWLINE# #INDENT# if ( pattern . strip ( ) != '' ) : #NEWLINE# #INDENT# args . include . append ( pattern ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( args . offline and configs . has_option ( 'settings' , 'offline' ) ) : #NEWLINE# #INDENT# args . offline = configs . getboolean ( 'settings' , 'offline' ) #NEWLINE# #UNINDENT# if ( ( not args . hidefilenames ) and configs . has_option ( 'settings' , 'hidefilenames' ) ) : #NEWLINE# #INDENT# args . hidefilenames = configs . getboolean ( 'settings' , 'hidefilenames' ) #NEWLINE# #UNINDENT# if ( ( not args . proxy ) and configs . has_option ( 'settings' , 'proxy' ) ) : #NEWLINE# #INDENT# args . proxy = configs . get ( 'settings' , 'proxy' ) #NEWLINE# #UNINDENT# if ( ( not args . verbose ) and configs . has_option ( 'settings' , 'verbose' ) ) : #NEWLINE# #INDENT# args . verbose = configs . getboolean ( 'settings' , 'verbose' ) #NEWLINE# #UNINDENT# if ( ( not args . verbose ) and configs . has_option ( 'settings' , 'debug' ) ) : #NEWLINE# #INDENT# args . verbose = configs . getboolean ( 'settings' , 'debug' ) #NEWLINE# #UNINDENT# if ( ( not args . logfile ) and configs . has_option ( 'settings' , 'logfile' ) ) : #NEWLINE# #INDENT# args . logfile = configs . get ( 'settings' , 'logfile' ) #NEWLINE# #UNINDENT# if ( ( not args . api_url ) and configs . has_option ( 'settings' , 'api_url' ) ) : #NEWLINE# #INDENT# args . api_url = configs . get ( 'settings' , 'api_url' ) #NEWLINE# #UNINDENT# if ( ( not args . timeout ) and configs . has_option ( 'settings' , 'timeout' ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# args . timeout = int ( configs . get ( 'settings' , 'timeout' ) ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# print ( traceback . format_exc ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# return ( parser , configs )