From f2a92b80fb8b2f2b91984903a2ec759dd5fb6535 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Fri, 25 Jul 2014 02:45:35 -0700 Subject: [PATCH] v2.0.4 --- HISTORY.rst | 14 ++++ plugin/packages/wakatime/HISTORY.rst | 25 +++++++ plugin/packages/wakatime/wakatime/__init__.py | 73 ++++++++++++++----- plugin/packages/wakatime/wakatime/log.py | 2 +- plugin/packages/wakatime/wakatime/project.py | 2 +- .../wakatime/wakatime/projects/base.py | 2 +- .../wakatime/wakatime/projects/git.py | 2 +- .../wakatime/wakatime/projects/mercurial.py | 2 +- .../wakatime/wakatime/projects/projectmap.py | 2 +- .../wakatime/wakatime/projects/subversion.py | 2 +- .../wakatime/wakatime/projects/wakatime.py | 2 +- plugin/packages/wakatime/wakatime/queue.py | 2 +- plugin/packages/wakatime/wakatime/stats.py | 9 ++- plugin/wakatime.vim | 2 +- 14 files changed, 110 insertions(+), 31 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index aca7895..f7a6247 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,20 @@ History ------- +2.0.4 (2014-07-25) +++++++++++++++++++ + +- upgrade external wakatime package to v2.0.5 +- use unique logger namespace to prevent collisions in shared plugin environments +- option in .wakatime.cfg to obfuscate file names + + +2.0.3 (2014-06-09) +++++++++++++++++++ + +- upgrade external wakatime package to v2.0.2 + + 2.0.2 (2014-05-26) ++++++++++++++++++ diff --git a/plugin/packages/wakatime/HISTORY.rst b/plugin/packages/wakatime/HISTORY.rst index a3966b6..b2d6a1f 100644 --- a/plugin/packages/wakatime/HISTORY.rst +++ b/plugin/packages/wakatime/HISTORY.rst @@ -3,6 +3,31 @@ History ------- +2.0.5 (2014-07-25) +++++++++++++++++++ + +- option in .wakatime.cfg to obfuscate file names + + +2.0.4 (2014-07-25) +++++++++++++++++++ + +- use unique logger namespace to prevent collisions in shared plugin environments + + +2.0.3 (2014-06-18) +++++++++++++++++++ + +- use project from command line arg when no revision control project is found + + +2.0.2 (2014-06-09) +++++++++++++++++++ + +- include python3.2 compatible versions of simplejson, pytz, and tzlocal +- disable offline logging when Python was not compiled with sqlite3 module + + 2.0.1 (2014-05-26) ++++++++++++++++++ diff --git a/plugin/packages/wakatime/wakatime/__init__.py b/plugin/packages/wakatime/wakatime/__init__.py index b010f14..5916e95 100644 --- a/plugin/packages/wakatime/wakatime/__init__.py +++ b/plugin/packages/wakatime/wakatime/__init__.py @@ -13,7 +13,7 @@ from __future__ import print_function __title__ = 'wakatime' -__version__ = '2.0.2' +__version__ = '2.0.5' __author__ = 'Alan Hamlett' __license__ = 'BSD' __copyright__ = 'Copyright 2014 Alan Hamlett' @@ -52,7 +52,12 @@ except: from .packages import tzlocal3 -log = logging.getLogger(__name__) +log = logging.getLogger('WakaTime') + +try: + unicode +except NameError: + unicode = str class FileAction(argparse.Action): @@ -161,6 +166,9 @@ def parseArguments(argv): parser.add_argument('--disableoffline', dest='offline', action='store_false', help='disables offline time logging instead of queuing logged time') + parser.add_argument('--hidefilenames', dest='hidefilenames', + action='store_true', + help='obfuscate file names; will not send file names to api') parser.add_argument('--ignore', dest='ignore', action='append', help='filename patterns to ignore; POSIX regex syntax; can be used more than once') parser.add_argument('--logfile', dest='logfile', @@ -203,6 +211,8 @@ def parseArguments(argv): pass if args.offline and configs.has_option('settings', 'offline'): args.offline = configs.getboolean('settings', 'offline') + if not args.hidefilenames and configs.has_option('settings', 'hidefilenames'): + args.hidefilenames = configs.getboolean('settings', 'hidefilenames') if not args.verbose and configs.has_option('settings', 'verbose'): args.verbose = configs.getboolean('settings', 'verbose') if not args.verbose and configs.has_option('settings', 'debug'): @@ -221,7 +231,10 @@ def should_ignore(fileName, patterns): if compiled.search(fileName): return pattern except re.error as ex: - log.warning('Regex error (%s) for ignore pattern: %s' % (str(ex), pattern)) + log.warning(unicode('Regex error ({msg}) for ignore pattern: {pattern}').format( + msg=str(ex), + pattern=pattern, + )) except TypeError: pass return False @@ -230,21 +243,34 @@ def should_ignore(fileName, patterns): def get_user_agent(plugin): ver = sys.version_info python_version = '%d.%d.%d.%s.%d' % (ver[0], ver[1], ver[2], ver[3], ver[4]) - user_agent = 'wakatime/%s (%s) Python%s' % (__version__, - platform.platform(), python_version) + user_agent = unicode('wakatime/{ver} ({platform}) Python{py_ver}').format( + ver=__version__, + platform=platform.platform(), + py_ver=python_version, + ) if plugin: - user_agent = user_agent+' '+plugin + user_agent = unicode('{user_agent} {plugin}').format( + user_agent=user_agent, + plugin=plugin, + ) return user_agent def send_action(project=None, branch=None, stats=None, key=None, targetFile=None, - timestamp=None, isWrite=None, plugin=None, offline=None, **kwargs): + timestamp=None, isWrite=None, plugin=None, offline=None, + hidefilenames=None, **kwargs): url = 'https://wakatime.com/api/v1/actions' - log.debug('Sending action to api at %s' % url) + log.debug('Sending heartbeat to api at %s' % url) data = { 'time': timestamp, 'file': targetFile, } + if hidefilenames and targetFile is not None: + data['file'] = data['file'].rsplit('/', 1)[-1].rsplit('\\', 1)[-1] + if len(data['file'].strip('.').split('.', 1)) > 1: + data['file'] = unicode('HIDDEN.{ext}').format(ext=data['file'].strip('.').rsplit('.', 1)[-1]) + else: + data['file'] = unicode('HIDDEN') if stats.get('lines'): data['lines'] = stats['lines'] if stats.get('language'): @@ -258,16 +284,16 @@ def send_action(project=None, branch=None, stats=None, key=None, targetFile=None log.debug(data) # setup api request - request = Request(url=url, data=str.encode(json.dumps(data))) + request = Request(url=url, data=json.dumps(data)) request.add_header('User-Agent', get_user_agent(plugin)) request.add_header('Content-Type', 'application/json') - auth = 'Basic %s' % bytes.decode(base64.b64encode(str.encode(key))) + auth = unicode('Basic {key}').format(key=bytes.decode(base64.b64encode(str.encode(key)))) request.add_header('Authorization', auth) # add Olson timezone to request tz = tzlocal.get_localzone() if tz: - request.add_header('TimeZone', str(tz.zone)) + request.add_header('TimeZone', unicode(tz.zone)) # log time to api response = None @@ -276,7 +302,7 @@ def send_action(project=None, branch=None, stats=None, key=None, targetFile=None except HTTPError as exc: exception_data = { 'response_code': exc.getcode(), - sys.exc_info()[0].__name__: str(sys.exc_info()[1]), + sys.exc_info()[0].__name__: unicode(sys.exc_info()[1]), } if log.isEnabledFor(logging.DEBUG): exception_data['traceback'] = traceback.format_exc() @@ -289,7 +315,7 @@ def send_action(project=None, branch=None, stats=None, key=None, targetFile=None log.error(exception_data) except: exception_data = { - sys.exc_info()[0].__name__: str(sys.exc_info()[1]), + sys.exc_info()[0].__name__: unicode(sys.exc_info()[1]), } if log.isEnabledFor(logging.DEBUG): exception_data['traceback'] = traceback.format_exc() @@ -339,7 +365,9 @@ def main(argv=None): ignore = should_ignore(args.targetFile, args.ignore) if ignore is not False: - log.debug('File ignored because matches pattern: %s' % ignore) + log.debug(unicode('File ignored because matches pattern: {pattern}').format( + pattern=ignore, + )) return 0 if os.path.isfile(args.targetFile): @@ -348,10 +376,10 @@ def main(argv=None): project = find_project(args.targetFile, configs=configs) branch = None - project_name = None + project_name = args.project_name if project: branch = project.branch() - project_name = args.project_name or project.name() + project_name = project.name() if send_action( project=project_name, @@ -364,9 +392,16 @@ def main(argv=None): action = queue.pop() if action is None: break - if not send_action(project=action['project'], targetFile=action['file'], timestamp=action['time'], - branch=action['branch'], stats={'language': action['language'], 'lines': action['lines']}, - key=args.key, isWrite=action['is_write'], plugin=action['plugin'], offline=args.offline): + sent = send_action(project=action['project'], + targetFile=action['file'], + timestamp=action['time'], + branch=action['branch'], + stats={'language': action['language'], 'lines': action['lines']}, + key=args.key, isWrite=action['is_write'], + plugin=action['plugin'], + offline=args.offline, + hidefilenames=args.hidefilenames) + if not sent: break return 0 # success diff --git a/plugin/packages/wakatime/wakatime/log.py b/plugin/packages/wakatime/wakatime/log.py index 6d7acc2..88a21a7 100644 --- a/plugin/packages/wakatime/wakatime/log.py +++ b/plugin/packages/wakatime/wakatime/log.py @@ -73,7 +73,7 @@ def set_log_level(logger, args): def setup_logging(args, version): - logger = logging.getLogger() + logger = logging.getLogger('WakaTime') set_log_level(logger, args) if len(logger.handlers) > 0: formatter = JsonFormatter(datefmt='%Y/%m/%d %H:%M:%S %z') diff --git a/plugin/packages/wakatime/wakatime/project.py b/plugin/packages/wakatime/wakatime/project.py index 88827be..56a8657 100644 --- a/plugin/packages/wakatime/wakatime/project.py +++ b/plugin/packages/wakatime/wakatime/project.py @@ -19,7 +19,7 @@ from .projects.subversion import Subversion from .projects.wakatime import WakaTime -log = logging.getLogger(__name__) +log = logging.getLogger('WakaTime') # List of plugin classes to find a project for the current file path. diff --git a/plugin/packages/wakatime/wakatime/projects/base.py b/plugin/packages/wakatime/wakatime/projects/base.py index aeafdf7..d1af823 100644 --- a/plugin/packages/wakatime/wakatime/projects/base.py +++ b/plugin/packages/wakatime/wakatime/projects/base.py @@ -13,7 +13,7 @@ import logging import os -log = logging.getLogger(__name__) +log = logging.getLogger('WakaTime') class BaseProject(object): diff --git a/plugin/packages/wakatime/wakatime/projects/git.py b/plugin/packages/wakatime/wakatime/projects/git.py index c8539a6..79c925a 100644 --- a/plugin/packages/wakatime/wakatime/projects/git.py +++ b/plugin/packages/wakatime/wakatime/projects/git.py @@ -15,7 +15,7 @@ import os from .base import BaseProject -log = logging.getLogger(__name__) +log = logging.getLogger('WakaTime') # str is unicode in Python3 diff --git a/plugin/packages/wakatime/wakatime/projects/mercurial.py b/plugin/packages/wakatime/wakatime/projects/mercurial.py index f91ab71..afaac95 100644 --- a/plugin/packages/wakatime/wakatime/projects/mercurial.py +++ b/plugin/packages/wakatime/wakatime/projects/mercurial.py @@ -15,7 +15,7 @@ import os from .base import BaseProject -log = logging.getLogger(__name__) +log = logging.getLogger('WakaTime') # str is unicode in Python3 diff --git a/plugin/packages/wakatime/wakatime/projects/projectmap.py b/plugin/packages/wakatime/wakatime/projects/projectmap.py index ea5ceff..9a4a73e 100644 --- a/plugin/packages/wakatime/wakatime/projects/projectmap.py +++ b/plugin/packages/wakatime/wakatime/projects/projectmap.py @@ -26,7 +26,7 @@ import os from .base import BaseProject -log = logging.getLogger(__name__) +log = logging.getLogger('WakaTime') # str is unicode in Python3 diff --git a/plugin/packages/wakatime/wakatime/projects/subversion.py b/plugin/packages/wakatime/wakatime/projects/subversion.py index 9a4c205..5a5551e 100644 --- a/plugin/packages/wakatime/wakatime/projects/subversion.py +++ b/plugin/packages/wakatime/wakatime/projects/subversion.py @@ -21,7 +21,7 @@ except ImportError: from ..packages.ordereddict import OrderedDict -log = logging.getLogger(__name__) +log = logging.getLogger('WakaTime') # str is unicode in Python3 diff --git a/plugin/packages/wakatime/wakatime/projects/wakatime.py b/plugin/packages/wakatime/wakatime/projects/wakatime.py index 6eea2a7..14ebe4f 100644 --- a/plugin/packages/wakatime/wakatime/projects/wakatime.py +++ b/plugin/packages/wakatime/wakatime/projects/wakatime.py @@ -17,7 +17,7 @@ import os from .base import BaseProject -log = logging.getLogger(__name__) +log = logging.getLogger('WakaTime') # str is unicode in Python3 diff --git a/plugin/packages/wakatime/wakatime/queue.py b/plugin/packages/wakatime/wakatime/queue.py index c253540..81ee2fc 100644 --- a/plugin/packages/wakatime/wakatime/queue.py +++ b/plugin/packages/wakatime/wakatime/queue.py @@ -22,7 +22,7 @@ except ImportError: HAS_SQL = False -log = logging.getLogger(__name__) +log = logging.getLogger('WakaTime') class Queue(object): diff --git a/plugin/packages/wakatime/wakatime/stats.py b/plugin/packages/wakatime/wakatime/stats.py index 4c0e168..07d0f78 100644 --- a/plugin/packages/wakatime/wakatime/stats.py +++ b/plugin/packages/wakatime/wakatime/stats.py @@ -20,7 +20,12 @@ else: from pygments.lexers import guess_lexer_for_filename -log = logging.getLogger(__name__) +log = logging.getLogger('WakaTime') + +try: + unicode +except NameError: + unicode = str # force file name extensions to be recognized as a certain language @@ -54,7 +59,7 @@ def guess_language(file_name): except: pass if lexer: - return translate_language(str(lexer.name)) + return translate_language(unicode(lexer.name)) else: return None diff --git a/plugin/wakatime.vim b/plugin/wakatime.vim index b9292c2..ac1c2e5 100644 --- a/plugin/wakatime.vim +++ b/plugin/wakatime.vim @@ -6,7 +6,7 @@ " Website: https://wakatime.com/ " ============================================================================ -let s:VERSION = '2.0.3' +let s:VERSION = '2.0.4' " Init {{{