From fad721530a4d8087f2187568aadf8a7a189f7848 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Mon, 20 Feb 2017 12:40:24 -0800 Subject: [PATCH] use alternate language if case-insensitive matches a language in the json files --- tests/test_languages.py | 4 +- wakatime/languages/default.json | 157 ++++++++++++++++---------------- wakatime/main.py | 2 +- wakatime/stats.py | 11 +-- 4 files changed, 85 insertions(+), 89 deletions(-) diff --git a/tests/test_languages.py b/tests/test_languages.py index 76b68c0..530a5c9 100644 --- a/tests/test_languages.py +++ b/tests/test_languages.py @@ -127,16 +127,16 @@ class LanguagesTestCase(utils.TestCase): with utils.mock.patch('wakatime.stats.smart_guess_lexer') as mock_guess_lexer: mock_guess_lexer.return_value = None + language = u('Java') now = u(int(time.time())) config = 'tests/samples/configs/good_config.cfg' entity = 'tests/samples/codefiles/python.py' - args = ['--file', entity, '--config', config, '--time', now, '--alternate-language', 'Java'] + args = ['--file', entity, '--config', config, '--time', now, '--alternate-language', language.upper()] retval = execute(args) self.assertEquals(retval, 102) - language = u('Java') self.assertEqual(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0].get('language'), language) def test_vim_alternate_language_is_used_when_not_guessed(self): diff --git a/wakatime/languages/default.json b/wakatime/languages/default.json index c57d4f8..8875041 100644 --- a/wakatime/languages/default.json +++ b/wakatime/languages/default.json @@ -1,80 +1,81 @@ { - "ActionScript": "ActionScript", - "ApacheConf": "ApacheConf", - "AppleScript": "AppleScript", - "ASP": "ASP", - "Assembly": "Assembly", - "Awk": "Awk", - "Bash": "Bash", - "Basic": "Basic", - "BrightScript": "BrightScript", - "C": "C", - "C#": "C#", - "C++": "C++", - "Clojure": "Clojure", - "Cocoa": "Cocoa", - "CoffeeScript": "CoffeeScript", - "ColdFusion": "ColdFusion", - "Common Lisp": "Common Lisp", - "CSHTML": "CSHTML", - "CSS": "CSS", - "Dart": "Dart", - "Delphi": "Delphi", - "Elixir": "Elixir", - "Elm": "Elm", - "Emacs Lisp": "Emacs Lisp", - "Erlang": "Erlang", - "F#": "F#", - "Fortran": "Fortran", - "Go": "Go", - "Gous": "Gosu", - "Groovy": "Groovy", - "Haml": "Haml", - "HaXe": "HaXe", - "Haskell": "Haskell", - "HTML": "HTML", - "INI": "INI", - "Jade": "Jade", - "Java": "Java", - "JavaScript": "JavaScript", - "JSON": "JSON", - "JSX": "JSX", - "Kotlin": "Kotlin", - "LESS": "LESS", - "Lua": "Lua", - "Markdown": "Markdown", - "Matlab": "Matlab", - "Mustache": "Mustache", - "OCaml": "OCaml", - "Objective-C": "Objective-C", - "Objective-C++": "Objective-C++", - "Objective-J": "Objective-J", - "Perl": "Perl", - "PHP": "PHP", - "PowerShell": "PowerShell", - "Prolog": "Prolog", - "Puppet": "Puppet", - "Python": "Python", - "R": "R", - "reStructuredText": "reStructuredText", - "Ruby": "Ruby", - "Rust": "Rust", - "Sass": "Sass", - "Scala": "Scala", - "Scheme": "Scheme", - "SCSS": "SCSS", - "Shell": "Shell", - "Slim": "Slim", - "Smalltalk": "Smalltalk", - "SQL": "SQL", - "Swift": "Swift", - "Text": "Text", - "Turing": "Turing", - "Twig": "Twig", - "TypeScript": "TypeScript", - "VB.net": "VB.net", - "VimL": "VimL", - "XAML": "XAML", - "XML": "XML", - "YAML": "YAML" + "actionscript": "ActionScript", + "apacheconf": "ApacheConf", + "applescript": "AppleScript", + "asp": "ASP", + "assembly": "Assembly", + "awk": "Awk", + "bash": "Bash", + "basic": "Basic", + "brightscript": "BrightScript", + "c": "C", + "c#": "C#", + "c++": "C++", + "clojure": "Clojure", + "cocoa": "Cocoa", + "coffeescript": "CoffeeScript", + "coldfusion": "ColdFusion", + "common lisp": "Common Lisp", + "cshtml": "CSHTML", + "css": "CSS", + "dart": "Dart", + "delphi": "Delphi", + "elixir": "Elixir", + "elm": "Elm", + "emacs lisp": "Emacs Lisp", + "erlang": "Erlang", + "f#": "F#", + "fortran": "Fortran", + "go": "Go", + "gous": "Gosu", + "groovy": "Groovy", + "haml": "Haml", + "haskell": "Haskell", + "haxe": "HaXe", + "html": "HTML", + "ini": "INI", + "jade": "Jade", + "java": "Java", + "javascript": "JavaScript", + "json": "JSON", + "jsx": "JSX", + "kotlin": "Kotlin", + "less": "LESS", + "lua": "Lua", + "markdown": "Markdown", + "matlab": "Matlab", + "mustache": "Mustache", + "objective-c": "Objective-C", + "objective-c++": "Objective-C++", + "objective-j": "Objective-J", + "ocaml": "OCaml", + "perl": "Perl", + "php": "PHP", + "powershell": "PowerShell", + "prolog": "Prolog", + "puppet": "Puppet", + "python": "Python", + "r": "R", + "restructuredtext": "reStructuredText", + "ruby": "Ruby", + "rust": "Rust", + "sass": "Sass", + "scala": "Scala", + "scheme": "Scheme", + "scss": "SCSS", + "shell": "Shell", + "slim": "Slim", + "smalltalk": "Smalltalk", + "sql": "SQL", + "swift": "Swift", + "text": "Text", + "turing": "Turing", + "twig": "Twig", + "typescript": "TypeScript", + "typoscript": "TypoScript", + "vb.net": "VB.net", + "viml": "VimL", + "xaml": "XAML", + "xml": "XML", + "yaml": "YAML" } diff --git a/wakatime/main.py b/wakatime/main.py index 0f7a035..bd80387 100644 --- a/wakatime/main.py +++ b/wakatime/main.py @@ -3,7 +3,7 @@ wakatime.main ~~~~~~~~~~~~~ - wakatime module entry point. + Module entry point. :copyright: (c) 2013 Alan Hamlett. :license: BSD, see LICENSE for more details. diff --git a/wakatime/stats.py b/wakatime/stats.py index 4448f2d..252261c 100644 --- a/wakatime/stats.py +++ b/wakatime/stats.py @@ -197,10 +197,7 @@ def standardize_language(language, plugin): # standardize language against default languages standardized = get_language_from_json(language, 'default') - if standardized is not None: - return standardized - - return None + return standardized def get_language_from_json(language, key): @@ -214,10 +211,8 @@ def get_language_from_json(language, key): try: with open(file_name, 'r', encoding='utf-8') as fh: languages = json.loads(fh.read()) - if language in languages.values(): - return language - if languages.get(language): - return languages[language] + if languages.get(language.lower()): + return languages[language.lower()] except: pass