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,
help='optional floating-point unix epoch timestamp; '+
'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',
action='store_true',
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,
timestamp=None, endtime=None, isWrite=None, plugin=None, **kwargs):
timestamp=None, isWrite=None, plugin=None, **kwargs):
url = 'https://www.wakati.me/api/v1/actions'
log.debug('Sending action to api at %s' % url)
data = {
@ -135,8 +131,6 @@ def send_action(project=None, branch=None, stats={}, key=None, targetFile=None,
data['lines'] = stats['lines']
if stats.get('language'):
data['language'] = stats['language']
if endtime:
data['endtime'] = endtime
if isWrite:
data['is_write'] = isWrite
if project:

View File

@ -30,9 +30,8 @@ class CustomEncoder(json.JSONEncoder):
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.endtime = endtime
self.isWrite = isWrite
self.targetFile = targetFile
self.version = version
@ -44,14 +43,11 @@ class JsonFormatter(logging.Formatter):
('version', self.version),
('plugin', self.plugin),
('time', self.timestamp),
('endtime', self.endtime),
('isWrite', self.isWrite),
('file', self.targetFile),
('level', record.levelname),
('message', record.msg),
])
if not self.endtime:
del data['endtime']
if not self.plugin:
del data['plugin']
if not self.isWrite:
@ -73,6 +69,15 @@ def setup_logging(args, version):
logger = logging.getLogger()
set_log_level(logger, args)
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
logfile = args.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.setup(
timestamp=args.timestamp,
endtime=args.endtime,
isWrite=args.isWrite,
targetFile=args.targetFile,
version=version,