upgraded wakatime package

This commit is contained in:
Alan Hamlett 2013-09-22 15:04:24 -07:00
parent af0dce46aa
commit c3e08623c1
2 changed files with 11 additions and 13 deletions

View file

@ -65,10 +65,6 @@ def parseArguments(argv):
type=float, type=float,
help='optional floating-point unix epoch timestamp; '+ help='optional floating-point unix epoch timestamp; '+
'uses current time by default') 'uses current time by default')
parser.add_argument('--endtime', dest='endtime',
help='optional end timestamp turning this action into '+
'a duration; if a non-duration action occurs within a '+
'duration, the duration is ignored')
parser.add_argument('--write', dest='isWrite', parser.add_argument('--write', dest='isWrite',
action='store_true', action='store_true',
help='note action was triggered from writing to a file') help='note action was triggered from writing to a file')
@ -124,7 +120,7 @@ def get_user_agent(plugin):
def send_action(project=None, branch=None, stats={}, key=None, targetFile=None, def send_action(project=None, branch=None, stats={}, key=None, targetFile=None,
timestamp=None, endtime=None, isWrite=None, plugin=None, **kwargs): timestamp=None, isWrite=None, plugin=None, **kwargs):
url = 'https://www.wakati.me/api/v1/actions' url = 'https://www.wakati.me/api/v1/actions'
log.debug('Sending action to api at %s' % url) log.debug('Sending action to api at %s' % url)
data = { data = {
@ -135,8 +131,6 @@ def send_action(project=None, branch=None, stats={}, key=None, targetFile=None,
data['lines'] = stats['lines'] data['lines'] = stats['lines']
if stats.get('language'): if stats.get('language'):
data['language'] = stats['language'] data['language'] = stats['language']
if endtime:
data['endtime'] = endtime
if isWrite: if isWrite:
data['is_write'] = isWrite data['is_write'] = isWrite
if project: if project:

View file

@ -30,9 +30,8 @@ class CustomEncoder(json.JSONEncoder):
class JsonFormatter(logging.Formatter): class JsonFormatter(logging.Formatter):
def setup(self, timestamp, endtime, isWrite, targetFile, version, plugin): def setup(self, timestamp, isWrite, targetFile, version, plugin):
self.timestamp = timestamp self.timestamp = timestamp
self.endtime = endtime
self.isWrite = isWrite self.isWrite = isWrite
self.targetFile = targetFile self.targetFile = targetFile
self.version = version self.version = version
@ -44,14 +43,11 @@ class JsonFormatter(logging.Formatter):
('version', self.version), ('version', self.version),
('plugin', self.plugin), ('plugin', self.plugin),
('time', self.timestamp), ('time', self.timestamp),
('endtime', self.endtime),
('isWrite', self.isWrite), ('isWrite', self.isWrite),
('file', self.targetFile), ('file', self.targetFile),
('level', record.levelname), ('level', record.levelname),
('message', record.msg), ('message', record.msg),
]) ])
if not self.endtime:
del data['endtime']
if not self.plugin: if not self.plugin:
del data['plugin'] del data['plugin']
if not self.isWrite: if not self.isWrite:
@ -73,6 +69,15 @@ def setup_logging(args, version):
logger = logging.getLogger() logger = logging.getLogger()
set_log_level(logger, args) set_log_level(logger, args)
if len(logger.handlers) > 0: if len(logger.handlers) > 0:
formatter = JsonFormatter(datefmt='%a %b %d %H:%M:%S %Z %Y')
formatter.setup(
timestamp=args.timestamp,
isWrite=args.isWrite,
targetFile=args.targetFile,
version=version,
plugin=args.plugin,
)
logger.handlers[0].setFormatter(formatter)
return logger return logger
logfile = args.logfile logfile = args.logfile
if not logfile: if not logfile:
@ -81,7 +86,6 @@ def setup_logging(args, version):
formatter = JsonFormatter(datefmt='%a %b %d %H:%M:%S %Z %Y') formatter = JsonFormatter(datefmt='%a %b %d %H:%M:%S %Z %Y')
formatter.setup( formatter.setup(
timestamp=args.timestamp, timestamp=args.timestamp,
endtime=args.endtime,
isWrite=args.isWrite, isWrite=args.isWrite,
targetFile=args.targetFile, targetFile=args.targetFile,
version=version, version=version,