From 744116079a09fe61bf11ee5245f3d7eed2afb631 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Fri, 25 Oct 2013 21:33:31 -0700 Subject: [PATCH] upgrade wakatime package --- packages/wakatime/wakatime/stats.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/wakatime/wakatime/stats.py b/packages/wakatime/wakatime/stats.py index ac29996..9aaed1e 100644 --- a/packages/wakatime/wakatime/stats.py +++ b/packages/wakatime/wakatime/stats.py @@ -23,7 +23,17 @@ from pygments.lexers import guess_lexer_for_filename log = logging.getLogger(__name__) +# force file name extensions to be recognized as a certain language +EXTENSIONS = { + 'md': 'Markdown', +} + + def guess_language(file_name): + if file_name: + language = guess_language_from_extension(file_name.rsplit('.', 1)[-1]) + if language: + return language lexer = None try: with open(file_name) as f: @@ -36,6 +46,15 @@ def guess_language(file_name): return None +def guess_language_from_extension(extension): + if extension: + if extension in EXTENSIONS: + return EXTENSIONS[extension] + if extension.lower() in EXTENSIONS: + return mapping[EXTENSIONS.lower()] + return None + + def number_lines_in_file(file_name): lines = 0 try: